Skip to content

Commit e552213

Browse files
committed
YIPPEEEEE
1 parent ebcaba3 commit e552213

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/lib/project-fetcher-hoc.jsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import bindAll from 'lodash.bindall';
55
import { connect } from 'react-redux';
66
import Project from './project.protobuf.js';
77
import Pbf from './pbf.js';
8+
import JSZip from 'jszip';
89

910
import { setProjectUnchanged } from '../reducers/project-changed';
1011
import {
@@ -268,15 +269,28 @@ const ProjectFetcherHOC = function (WrappedComponent) {
268269
storage.setProjectToken(projectId);
269270
assetPromise = storage.load(storage.AssetType.Project, projectId, storage.DataFormat.JSON);
270271
} else {
271-
projectUrl = `http://localhost:8080/api/v1/projects/getproject?requestType=protobuf&safe=true&projectId=${projectId}`
272+
projectUrl = `http://localhost:8080/api/v1/projects/getprojectwrapper?safe=true&projectId=${projectId}`
272273
// TODO: convert the protobuf to a pmp. Get the pbf file from the server to do this.
273274
assetPromise = progressMonitor.fetchWithProgress(projectUrl)
274-
.then(r => {
275+
.then(async r => {
275276
this.props.vm.runtime.renderer.setPrivateSkinAccess(false);
276277
if (!r.ok) {
277278
throw new Error(`Request returned status ${r.status}`);
278279
}
279-
return r.arrayBuffer();
280+
const project = await r.json();
281+
282+
const pbf = new Pbf(new Uint8Array(project.project.data));
283+
const json = protobufToJson(pbf);
284+
285+
// now get the assets
286+
let zip = new JSZip();
287+
zip.file("project.json", JSON.stringify(json));
288+
289+
for (const asset of project.assets) {
290+
zip.file(asset.name, asset.data);
291+
}
292+
293+
return zip.generateAsync({ type: "arraybuffer" });
280294
})
281295
.then(buffer => ({ data: buffer }))
282296
.catch(error => {
@@ -300,13 +314,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
300314
})
301315
.then(projectAsset => {
302316
if (projectAsset) {
303-
// convert the protobuf to json then to array buffer
304-
const pbf = new Pbf(projectAsset.data);
305-
const json = protobufToJson(pbf);
306-
307-
const projectData = new TextEncoder().encode(JSON.stringify(json));
308-
309-
this.props.onFetchedProjectData(projectData, loadingState);
317+
this.props.onFetchedProjectData(projectAsset.data, loadingState);
310318
} else {
311319
// pm: Failed to grab data, use the "fetch" API as a backup
312320
// we shouldnt be interrupted by the fetch replacement in tw-progress-monitor

0 commit comments

Comments
 (0)