aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index c5af45262..35f9a1032 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -822,7 +822,6 @@ export namespace Doc {
export async function Zip(doc: Doc, zipFilename = 'dashExport.zip') {
const { clone, map, linkMap } = await Doc.MakeClone(doc);
- clone.LINKS = new List<Doc>(Array.from(linkMap.values()));
const proms = [] as string[];
function replacer(key: any, value: any) {
if (key && ['branchOf', 'cloneOf', 'cursors'].includes(key)) return undefined;
@@ -856,8 +855,10 @@ export namespace Doc {
}
const docs: { [id: string]: any } = {};
+ const links: { [id: string]: any } = {};
Array.from(map.entries()).forEach(f => (docs[f[0]] = f[1]));
- const jsonDocs = JSON.stringify({ id: clone[Id], docs }, decycle(replacer));
+ Array.from(linkMap.entries()).forEach(l => (links[l[0]] = l[1]));
+ const jsonDocs = JSON.stringify({ id: clone[Id], docs, links }, decycle(replacer));
const zip = new JSZip();
var count = 0;
@@ -873,7 +874,7 @@ export namespace Doc {
const assetPathOnServer = proms[i].replace(window.location.origin + '/', '').replace(/\//g, '%%%');
zip.file(assetPathOnServer, data, { binary: true });
if (++count == proms.length) {
- zip.file('doc.json', jsonDocs);
+ zip.file('docs.json', jsonDocs);
zip.generateAsync({ type: 'blob' }).then(content => saveAs(content, zipFilename));
// const a = document.createElement("a");
// const url = Utils.prepend(`/downloadId/${this.props.Document[Id]}`);
@@ -1543,10 +1544,12 @@ export namespace Doc {
const response = await fetch(upload, { method: 'POST', body: formData });
const json = await response.json();
if (json !== 'error') {
- await DocServer.GetRefFields(json.docids as string[]);
+ const docs = await DocServer.GetRefFields(json.docids as string[]);
const doc = DocCast(await DocServer.GetRefField(json.id));
- (await DocListCastAsync(doc?.LINKS))?.forEach(link => LinkManager.Instance.addLink(link));
- doc.LINKS = undefined;
+ const links = await DocServer.GetRefFields(json.linkids as string[]);
+ Array.from(Object.keys(links))
+ .map(key => links[key])
+ .forEach(link => link instanceof Doc && LinkManager.Instance.addLink(link));
return doc;
}
}