mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-01-04 08:53:49 +01:00
also store app version in data object
This commit is contained in:
parent
02a7f64d5f
commit
9996728f9c
3
index.js
3
index.js
@ -56,8 +56,7 @@ window.addEventListener('keydown', (event) => {
|
|||||||
// add model to store
|
// add model to store
|
||||||
import modelData from './models/circle_error.d3sketch';
|
import modelData from './models/circle_error.d3sketch';
|
||||||
import JSONToSketchData from './src/shape/JSONToSketchData.js';
|
import JSONToSketchData from './src/shape/JSONToSketchData.js';
|
||||||
const { data, appVersion } = JSON.parse(modelData);
|
JSONToSketchData(JSON.parse(modelData)).then(sketch => {
|
||||||
JSONToSketchData({ data }, appVersion).then(sketch => {
|
|
||||||
store.dispatch(actions.openSketch(sketch));
|
store.dispatch(actions.openSketch(sketch));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -99,8 +99,8 @@ class App extends React.Component {
|
|||||||
case 'D3SKETCH':
|
case 'D3SKETCH':
|
||||||
case 'JSON':
|
case 'JSON':
|
||||||
const url = URL.createObjectURL(file);
|
const url = URL.createObjectURL(file);
|
||||||
const { data, appVersion } = await fetch(url).then(result => result.json());
|
const data = await fetch(url).then(result => result.json());
|
||||||
const sketchData = await JSONToSketchData(data, appVersion);
|
const sketchData = await JSONToSketchData(data);
|
||||||
openSketch(sketchData);
|
openSketch(sketchData);
|
||||||
break;
|
break;
|
||||||
case 'JPG':
|
case 'JPG':
|
||||||
|
@ -48,7 +48,7 @@ class DoodlePreview extends React.Component {
|
|||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
let { docData, sketchData } = this.props;
|
let { docData, sketchData } = this.props;
|
||||||
|
|
||||||
if (docData) sketchData = await JSONToSketchData(docData.data, docData.appVersion);
|
if (docData) sketchData = await JSONToSketchData(docData);
|
||||||
|
|
||||||
const { canvas } = this.refs;
|
const { canvas } = this.refs;
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ function revive(appVersion, key, value) {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function JSONToSketchData(data, appVersion) {
|
export default async function JSONToSketchData({ data, appVersion }) {
|
||||||
let sketchData;
|
let sketchData;
|
||||||
if (semver.gt(appVersion, '0.17.4')) {
|
if (semver.gt(appVersion, '0.17.4')) {
|
||||||
sketchData = reviveObject(data, (key, value) => revive(appVersion, key, value));
|
sketchData = reviveObject(data, (key, value) => revive(appVersion, key, value));
|
||||||
} else {
|
} else {
|
||||||
sketchData = JSON.parse(data.data, (key, value) => revive(appVersion, key, value));
|
sketchData = JSON.parse(data, (key, value) => revive(appVersion, key, value));
|
||||||
}
|
}
|
||||||
sketchData = await recursivePromiseApply(sketchData);
|
sketchData = await recursivePromiseApply(sketchData);
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
|
|||||||
author: doc.author,
|
author: doc.author,
|
||||||
id: doc._id,
|
id: doc._id,
|
||||||
createdOn: doc.createdOn,
|
createdOn: doc.createdOn,
|
||||||
updatedOn: doc.updatedOn,
|
updatedOn: doc.updatedOn
|
||||||
appVersion: doc.appVersion
|
|
||||||
};
|
};
|
||||||
if (doc.class) response.class = doc.class;
|
if (doc.class) response.class = doc.class;
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
|
|||||||
}
|
}
|
||||||
const data = await blobToJSON(doc._attachments.sketch.data);
|
const data = await blobToJSON(doc._attachments.sketch.data);
|
||||||
|
|
||||||
response.data = await JSONToSketchData(data, appVersion);
|
response.data = await JSONToSketchData(data);
|
||||||
} else {
|
} else {
|
||||||
const data = { data: doc.data, appVersion };
|
const data = { data: doc.data, appVersion };
|
||||||
response.data = await JSONToSketchData(data);
|
response.data = await JSONToSketchData(data);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { vectorArrayToBase64, imageToBase64 } from '../utils/binaryUtils.js';
|
import { vectorArrayToBase64, imageToBase64 } from '../utils/binaryUtils.js';
|
||||||
|
import { VERSION } from '../constants/general.js';
|
||||||
|
|
||||||
function createShapeData(shape) {
|
function createShapeData(shape) {
|
||||||
shape = { ...shape };
|
shape = { ...shape };
|
||||||
@ -59,5 +60,5 @@ export default function sketchDataToJSON({ objectsById, spaces }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return { data, appVersion: VERSION };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user