Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene url form fix #6136

Merged
merged 4 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/react-components/room/RoomSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ SceneInfo.propTypes = {
showAttributions: PropTypes.bool,
canChangeScene: PropTypes.bool,
onChangeScene: PropTypes.func,
scene: {
attributions: {
content: PropTypes.string,
scene: PropTypes.shape({
attributions: PropTypes.shape({
content: PropTypes.array,
creator: PropTypes.string
},
}),
url: PropTypes.string,
screenshot_url: PropTypes.string,
name: PropTypes.string
}
})
};

export function RoomSidebar({ room, accountId, onClose, canEdit, onEdit, onChangeScene }) {
Expand Down
6 changes: 2 additions & 4 deletions src/react-components/room/SceneUrlModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ export function SceneUrlModal({ enableSpoke, editorName, onValidateUrl, onSubmit
)}
</p>
<TextInputField
name="url"
label={<FormattedMessage id="scene-url-modal.url-input" defaultMessage="Scene URL" />}
placeholder="https://example.com/scene.glb"
type="url"
required
ref={register({ validate: onValidateUrl })}
{...register("url", { validate: onValidateUrl, required: true })}
error={errors?.url?.message}
/>
<Button type="submit" preset="accept" disabled={isSubmitting}>
Expand Down Expand Up @@ -95,5 +93,5 @@ SceneUrlModal.propTypes = {
editorName: PropTypes.string,
onSubmit: PropTypes.func,
onClose: PropTypes.func,
onValidateUrl: PropTypes.isRequired
onValidateUrl: PropTypes.func.isRequired
};
8 changes: 7 additions & 1 deletion src/react-components/room/SceneUrlModalContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export function SceneUrlModalContainer({ hubChannel, onClose }) {
const onValidateUrl = useCallback(
async url => {
const valid = await isValidSceneUrl(url.trim());
return valid || intl.formatMessage("scene-url-modal.invalid-scene-url");
return (
valid ||
intl.formatMessage({
id: "scene-url-modal.invalid-scene-url",
defaultMessage: "This URL does not point to a scene or valid GLB."
})
);
},
[intl]
);
Expand Down
28 changes: 15 additions & 13 deletions src/utils/scene-url-utils.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { isLocalHubsSceneUrl, proxiedUrlFor } from "../utils/media-url-utils";

export async function isValidGLB(url) {
return fetch(url).then(async r => {
const reader = r.body.getReader();
let header = "";
function readChunk({ done, value }) {
header += String.fromCharCode.apply(null, value.slice(0, 4));
if (!done && header.length < 4) {
return reader.read().then(readChunk);
} else {
reader.cancel();
return fetch(url)
.then(async r => {
const reader = r.body.getReader();
let header = "";
function readChunk({ done, value }) {
header += String.fromCharCode.apply(null, value.slice(0, 4));
if (!done && header.length < 4) {
return reader.read().then(readChunk);
} else {
reader.cancel();
}
}
}
await reader.read().then(readChunk);
return header.startsWith("glTF");
});
await reader.read().then(readChunk);
return header.startsWith("glTF");
})
.catch(e => console.error(e));
}

export async function isValidSceneUrl(url) {
Expand Down
Loading