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.ts69
1 files changed, 35 insertions, 34 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index b533bd10c..b8ac8fb5d 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -14,8 +14,8 @@ import { decycle } from '../decycler/decycler';
import { DashColor, incrementTitleCopy, intersectRect, Utils } from '../Utils';
import { DateField } from './DateField';
import { Copy, HandleUpdate, Id, OnUpdate, Parent, Self, SelfProxy, ToScriptString, ToString, Update } from './FieldSymbols';
-import { InkTool } from './InkField';
-import { List } from './List';
+import { InkField, InkTool } from './InkField';
+import { List, ListFieldName } from './List';
import { ObjectField } from './ObjectField';
import { PrefetchProxy, ProxyField } from './Proxy';
import { FieldId, RefField } from './RefField';
@@ -23,7 +23,7 @@ import { RichTextField } from './RichTextField';
import { listSpec } from './Schema';
import { ComputedField, ScriptField } from './ScriptField';
import { Cast, DocCast, FieldValue, NumCast, StrCast, ToConstructor } from './Types';
-import { AudioField, ImageField, MapField, PdfField, VideoField, WebField } from './URLField';
+import { AudioField, CsvField, ImageField, PdfField, VideoField, WebField } from './URLField';
import { deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, normalizeEmail, setter, SharingPermissions, updateFunction } from './util';
import JSZip = require('jszip');
import * as JSZipUtils from '../JSZipUtils';
@@ -828,35 +828,32 @@ export namespace Doc {
export async function Zip(doc: Doc, zipFilename = 'dashExport.zip') {
const { clone, map, linkMap } = await Doc.MakeClone(doc);
- const proms = [] as string[];
+ const proms = new Set<string>();
function replacer(key: any, value: any) {
if (key && ['branchOf', 'cloneOf', 'cursors'].includes(key)) return undefined;
- else if (value instanceof Doc) {
- if (key !== 'field' && Number.isNaN(Number(key))) {
- return { id: value[Id], __type: 'Doc', fields: value[FieldsSym]() };
- }
- return { fieldId: value[Id], __type: 'proxy' };
- } else if (value instanceof ImageField) {
+ if (value instanceof ImageField) {
const extension = value.url.href.replace(/.*\./, '');
- proms.push(value.url.href.replace('.' + extension, '_o.' + extension));
- return { url: value.url.href, __type: 'image' };
- } else if (value instanceof PdfField) {
- proms.push(value.url.href);
- return { url: value.url.href, __type: 'pdf' };
- } else if (value instanceof AudioField) {
- proms.push(value.url.href);
- return { url: value.url.href, __type: 'audio' };
- } else if (value instanceof VideoField) {
- proms.push(value.url.href);
- return { url: value.url.href, __type: 'video' };
- } else if (value instanceof ScriptField) return { script: value.script, __type: 'script' };
- else if (value instanceof RichTextField) return { Data: value.Data, Text: value.Text, __type: 'RichTextField' };
- else if (value instanceof WebField) return { url: value.url.href, __type: 'web' };
- else if (value instanceof MapField) return { url: value.url.href, __type: 'map' };
- else if (value instanceof DateField) return { date: value.toString(), __type: 'date' };
- else if (value instanceof ProxyField) return { fieldId: value.fieldId, __type: 'proxy' };
- else if (value instanceof Array && key !== 'fields') return { fields: value, __type: 'list' };
- else if (value instanceof ComputedField) return { script: value.script, __type: 'computed' };
+ proms.add(value.url.href.replace('.' + extension, '_o.' + extension));
+ return SerializationHelper.Serialize(value);
+ }
+ if (value instanceof PdfField || value instanceof AudioField || value instanceof VideoField) {
+ proms.add(value.url.href);
+ return SerializationHelper.Serialize(value);
+ }
+ if (
+ value instanceof Doc ||
+ value instanceof ScriptField ||
+ value instanceof RichTextField ||
+ value instanceof InkField ||
+ value instanceof CsvField ||
+ value instanceof WebField ||
+ value instanceof DateField ||
+ value instanceof ProxyField ||
+ value instanceof ComputedField
+ ) {
+ return SerializationHelper.Serialize(value);
+ }
+ if (value instanceof Array && key !== ListFieldName && key !== InkField.InkDataFieldName) return { fields: value, __type: 'list' };
return value;
}
@@ -868,18 +865,22 @@ export namespace Doc {
const zip = new JSZip();
var count = 0;
- proms
- .filter(url => url.startsWith(window.location.origin))
- .forEach((url, i) => {
+ const promArr = Array.from(proms).filter(url => url.startsWith(window.location.origin));
+ if (!promArr.length) {
+ zip.file('docs.json', jsonDocs);
+ zip.generateAsync({ type: 'blob' }).then(content => saveAs(content, zipFilename));
+ } else
+ promArr.forEach((url, i) => {
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(url, (err: any, data: any) => {
if (err) throw err; // or handle the error
// // Generate a directory within the Zip file structure
// const assets = zip.folder("assets");
// assets.file(filename, data, {binary: true});
- const assetPathOnServer = proms[i].replace(window.location.origin + '/', '').replace(/\//g, '%%%');
+ const assetPathOnServer = promArr[i].replace(window.location.origin + '/', '').replace(/\//g, '%%%');
zip.file(assetPathOnServer, data, { binary: true });
- if (++count == proms.length) {
+ console.log(' => ' + url);
+ if (++count === promArr.length) {
zip.file('docs.json', jsonDocs);
zip.generateAsync({ type: 'blob' }).then(content => saveAs(content, zipFilename));
// const a = document.createElement("a");