Skip to content

Commit

Permalink
Merge pull request #6136 from mozilla/scene-url-form-fix
Browse files Browse the repository at this point in the history
Scene url form fix
  • Loading branch information
keianhzo authored Jun 21, 2023
2 parents b5a6869 + af29349 commit 77780e4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
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

0 comments on commit 77780e4

Please sign in to comment.