@@ -10,27 +10,31 @@ export function useProjectManager() {
1010 try {
1111 await useInfraStore ( ) . create_connection ( )
1212 const snapshot = appStore . exportStores ( )
13+ const schema = back_schemas . opengeodeweb_back . export_project
14+ const defaultName = "project.zip"
1315
14- const schema = back_schemas . opengeodeweb_back . project . export_project
15- const url = `${ geode . base_url } ${ schema . $id } `
16- const method = schema . methods [ 0 ]
17-
18- const response = await fetch ( url , {
19- method,
20- headers : { "Content-Type" : "application/json" } ,
21- body : JSON . stringify ( { snapshot } ) ,
22- } )
23- if ( ! response . ok ) {
24- throw new Error ( `Export failed: ${ response . statusText } ` )
25- }
26- const blob = await response . blob ( )
27- const filename = response . headers . get ( "new-file-name" )
28- const urlObject = URL . createObjectURL ( blob )
29- const a = document . createElement ( "a" )
30- a . href = urlObject
31- a . download = filename
32- a . click ( )
33- URL . revokeObjectURL ( urlObject )
16+ await api_fetch (
17+ { schema, params : { snapshot, filename : defaultName } } ,
18+ {
19+ response_function : async ( response ) => {
20+ const contentType =
21+ response . headers ?. get ?. ( "content-type" ) || "application/zip"
22+ const data = response . _data
23+ const blob =
24+ data instanceof Blob
25+ ? data
26+ : new Blob ( [ data ] , { type : contentType } )
27+ const downloadName =
28+ response . headers ?. get ?. ( "new-file-name" ) || defaultName
29+ const urlObject = URL . createObjectURL ( blob )
30+ const a = document . createElement ( "a" )
31+ a . href = urlObject
32+ a . download = downloadName
33+ a . click ( )
34+ URL . revokeObjectURL ( urlObject )
35+ } ,
36+ } ,
37+ )
3438 } finally {
3539 geode . stop_request ( )
3640 }
@@ -43,11 +47,11 @@ export function useProjectManager() {
4347 await useInfraStore ( ) . create_connection ( )
4448
4549 await viewer_call ( {
46- schema : viewer_schemas . opengeodeweb_viewer . utils . import_project ,
50+ schema : viewer_schemas . opengeodeweb_viewer . import_project ,
4751 params : { } ,
4852 } )
4953 await viewer_call ( {
50- schema : viewer_schemas . opengeodeweb_viewer . viewer . reset_visualization ,
54+ schema : viewer_schemas . opengeodeweb_viewer . reset_visualization ,
5155 params : { } ,
5256 } )
5357
0 commit comments