Skip to content

Commit

Permalink
do not allow object to be passed to managed-street, only json string
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr committed Dec 20, 2024
1 parent 79f5432 commit 015a1fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
20 changes: 5 additions & 15 deletions src/components/managed-street.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ userLayersEl = document.getElementById('street-container');
newStreetEl = document.createElement('a-entity');
newStreetEl.setAttribute('managed-street', {
sourceType: 'json-blob',
sourceValue: window.STREET.SAMPLE_STREET,
sourceValue: JSON.stringify(window.STREET.SAMPLE_STREET),
synchronize: true
});
userLayersEl.append(newStreetEl);
Expand Down Expand Up @@ -153,7 +153,7 @@ AFRAME.registerComponent('managed-street', {
},
sourceType: {
type: 'string',
oneOf: ['streetmix-url', 'streetplan-url', 'json-blob', 'json-hash']
oneOf: ['streetmix-url', 'streetplan-url', 'json-blob']
},
sourceValue: {
type: 'string'
Expand Down Expand Up @@ -234,19 +234,9 @@ AFRAME.registerComponent('managed-street', {
if (typeof data.sourceValue === 'string') {
const streetObjectFromBlob = JSON.parse(data.sourceValue);
this.parseStreetObject(streetObjectFromBlob);
}

// if data.sourceValue is an object, then parse and rewrite it as a json string for saving
if (typeof data.sourceValue === 'object') {
const streetObjectFromBlob = data.sourceValue;

this.parseStreetObject(streetObjectFromBlob);

const stringifiedStreetObject = JSON.stringify(streetObjectFromBlob);
this.el.setAttribute(
'managed-street',
'sourceValue',
stringifiedStreetObject
} else {
console.log(
'[managed-street]: ERROR parsing json-blob, sourceValue must be a string'
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/json-utils_1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,18 @@ AFRAME.registerComponent('set-loader-from-hash', {
const fragment = window.location.hash;
const prefix = '#managed-street-json:';

let streetObjectFromHash = {};
let jsonStr = {};
try {
const encodedJsonStr = fragment.substring(prefix.length);
const jsonStr = decodeURIComponent(encodedJsonStr);
streetObjectFromHash = JSON.parse(jsonStr);
jsonStr = decodeURIComponent(encodedJsonStr);
} catch (err) {
console.error('Error parsing fragment:', err);
}
const definition = {
components: {
'managed-street': {
sourceType: 'json-blob',
sourceValue: streetObjectFromHash,
sourceValue: jsonStr,
synchronize: true
}
}
Expand Down

0 comments on commit 015a1fd

Please sign in to comment.