@@ -5,6 +5,7 @@ import bindAll from 'lodash.bindall';
5
5
import { connect } from 'react-redux' ;
6
6
import Project from './project.protobuf.js' ;
7
7
import Pbf from './pbf.js' ;
8
+ import JSZip from 'jszip' ;
8
9
9
10
import { setProjectUnchanged } from '../reducers/project-changed' ;
10
11
import {
@@ -268,15 +269,28 @@ const ProjectFetcherHOC = function (WrappedComponent) {
268
269
storage . setProjectToken ( projectId ) ;
269
270
assetPromise = storage . load ( storage . AssetType . Project , projectId , storage . DataFormat . JSON ) ;
270
271
} 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 } `
272
273
// TODO: convert the protobuf to a pmp. Get the pbf file from the server to do this.
273
274
assetPromise = progressMonitor . fetchWithProgress ( projectUrl )
274
- . then ( r => {
275
+ . then ( async r => {
275
276
this . props . vm . runtime . renderer . setPrivateSkinAccess ( false ) ;
276
277
if ( ! r . ok ) {
277
278
throw new Error ( `Request returned status ${ r . status } ` ) ;
278
279
}
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" } ) ;
280
294
} )
281
295
. then ( buffer => ( { data : buffer } ) )
282
296
. catch ( error => {
@@ -300,13 +314,7 @@ const ProjectFetcherHOC = function (WrappedComponent) {
300
314
} )
301
315
. then ( projectAsset => {
302
316
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 ) ;
310
318
} else {
311
319
// pm: Failed to grab data, use the "fetch" API as a backup
312
320
// we shouldnt be interrupted by the fetch replacement in tw-progress-monitor
0 commit comments