@@ -8,13 +8,14 @@ export default function download(
|
|||||||
strFileName: string,
|
strFileName: string,
|
||||||
strMimeType?: string
|
strMimeType?: string
|
||||||
) {
|
) {
|
||||||
const self = window,
|
const self = window;
|
||||||
// this script is only for browsers anyway...
|
// this script is only for browsers anyway...
|
||||||
u = "application/octet-stream",
|
const u = "application/octet-stream";
|
||||||
// this default mime also triggers iframe downloads
|
|
||||||
m = strMimeType || u,
|
// this default mime also triggers iframe downloads
|
||||||
x = data,
|
let m = strMimeType || u,
|
||||||
D = document,
|
x = data;
|
||||||
|
const D = document,
|
||||||
a = D.createElement("a"),
|
a = D.createElement("a"),
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'a' implicitly has an 'any' type.
|
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'a' implicitly has an 'any' type.
|
||||||
z = function (a) {
|
z = function (a) {
|
||||||
@@ -24,21 +25,15 @@ export default function download(
|
|||||||
B = self.Blob || self.MozBlob || self.WebKitBlob || z,
|
B = self.Blob || self.MozBlob || self.WebKitBlob || z,
|
||||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'WebKitBlobBuilder' does not exist on typ... Remove this comment to see the full error message
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'WebKitBlobBuilder' does not exist on typ... Remove this comment to see the full error message
|
||||||
BB = self.MSBlobBuilder || self.WebKitBlobBuilder || self.BlobBuilder,
|
BB = self.MSBlobBuilder || self.WebKitBlobBuilder || self.BlobBuilder,
|
||||||
fn = strFileName || "download",
|
fn = strFileName || "download";
|
||||||
// @ts-expect-error ts-migrate(1155) FIXME: 'const' declarations must be initialized.
|
|
||||||
blob,
|
let blob, b, fr;
|
||||||
// @ts-expect-error ts-migrate(1155) FIXME: 'const' declarations must be initialized.
|
|
||||||
b,
|
|
||||||
// @ts-expect-error ts-migrate(1155) FIXME: 'const' declarations must be initialized.
|
|
||||||
fr;
|
|
||||||
|
|
||||||
if (String(this) === "true") {
|
if (String(this) === "true") {
|
||||||
//reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
// reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'x' because it is a constant.
|
// @ts-expect-error this is weird code
|
||||||
x = [x, m];
|
x = [x, m];
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'm' because it is a constant.
|
|
||||||
m = x[0];
|
m = x[0];
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'x' because it is a constant.
|
|
||||||
x = x[1];
|
x = x[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +45,6 @@ export default function download(
|
|||||||
|
|
||||||
//end if dataURL passed?
|
//end if dataURL passed?
|
||||||
try {
|
try {
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'blob' because it is a constant.
|
|
||||||
blob =
|
blob =
|
||||||
x instanceof B
|
x instanceof B
|
||||||
? x
|
? x
|
||||||
@@ -59,16 +53,13 @@ export default function download(
|
|||||||
});
|
});
|
||||||
} catch (y) {
|
} catch (y) {
|
||||||
if (BB) {
|
if (BB) {
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'b' because it is a constant.
|
|
||||||
b = new BB();
|
b = new BB();
|
||||||
b.append([x]);
|
b.append([x]);
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'blob' because it is a constant.
|
|
||||||
blob = b.getBlob(m); // the blob
|
blob = b.getBlob(m); // the blob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'u' implicitly has an 'any' type.
|
function d2b(u: string) {
|
||||||
function d2b(u) {
|
|
||||||
if (typeof u !== "string") {
|
if (typeof u !== "string") {
|
||||||
throw Error("Attempted to pass non-string to d2b");
|
throw Error("Attempted to pass non-string to d2b");
|
||||||
}
|
}
|
||||||
@@ -79,10 +70,9 @@ export default function download(
|
|||||||
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
|
||||||
bin = dec(p.pop()),
|
bin = dec(p.pop()),
|
||||||
mx = bin.length,
|
mx = bin.length,
|
||||||
i = 0,
|
|
||||||
uia = new Uint8Array(mx);
|
uia = new Uint8Array(mx);
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'i' because it is a constant.
|
let i = 0;
|
||||||
for (i; i < mx; ++i) uia[i] = bin.charCodeAt(i);
|
for (i; i < mx; ++i) uia[i] = bin.charCodeAt(i);
|
||||||
|
|
||||||
return new B([uia], {
|
return new B([uia], {
|
||||||
@@ -90,7 +80,7 @@ export default function download(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saver(url: string, winMode: boolean) {
|
function saver(url: string, winMode = false) {
|
||||||
if (typeof url !== "string") {
|
if (typeof url !== "string") {
|
||||||
throw Error("Attempted to pass non-string url to saver");
|
throw Error("Attempted to pass non-string url to saver");
|
||||||
}
|
}
|
||||||
@@ -141,19 +131,15 @@ export default function download(
|
|||||||
typeof m === "string"
|
typeof m === "string"
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
||||||
return saver("data:" + m + ";base64," + self.btoa(blob));
|
return saver("data:" + m + ";base64," + self.btoa(blob));
|
||||||
} catch (y) {
|
} catch (y) {
|
||||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
|
||||||
return saver("data:" + m + "," + encodeURIComponent(blob));
|
return saver("data:" + m + "," + encodeURIComponent(blob));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blob but not URL:
|
// Blob but not URL:
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'fr' because it is a constant.
|
|
||||||
fr = new FileReader();
|
fr = new FileReader();
|
||||||
|
|
||||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'e' implicitly has an 'any' type.
|
|
||||||
fr.onload = function (e) {
|
fr.onload = function (e) {
|
||||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
||||||
saver(this.result);
|
saver(this.result);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export default async function collectionImporter({
|
|||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
if (item.type === "collection") {
|
if (item.type === "collection") {
|
||||||
// check if collection with name exists
|
// check if collection with name exists
|
||||||
const [collection, isCreated] = await Collection.findOrCreate({
|
const response = await Collection.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
@@ -75,12 +75,14 @@ export default async function collectionImporter({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let collection = response[0];
|
||||||
|
const isCreated = response[1];
|
||||||
|
|
||||||
// create new collection if name already exists, yes it's possible that
|
// create new collection if name already exists, yes it's possible that
|
||||||
// there is also a "Name (Imported)" but this is a case not worth dealing
|
// there is also a "Name (Imported)" but this is a case not worth dealing
|
||||||
// with right now
|
// with right now
|
||||||
if (!isCreated) {
|
if (!isCreated) {
|
||||||
const name = `${item.name} (Imported)`;
|
const name = `${item.name} (Imported)`;
|
||||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'collection' because it is a cons... Remove this comment to see the full error message
|
|
||||||
collection = await Collection.create({
|
collection = await Collection.create({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
createdById: user.id,
|
createdById: user.id,
|
||||||
@@ -107,6 +109,7 @@ export default async function collectionImporter({
|
|||||||
const collectionDir = item.dir.split("/")[0];
|
const collectionDir = item.dir.split("/")[0];
|
||||||
const collection = collections[collectionDir];
|
const collection = collections[collectionDir];
|
||||||
invariant(collection, `Collection must exist for document ${item.dir}`);
|
invariant(collection, `Collection must exist for document ${item.dir}`);
|
||||||
|
|
||||||
// we have a document
|
// we have a document
|
||||||
const content = await item.item.async("string");
|
const content = await item.item.async("string");
|
||||||
const name = path.basename(item.name);
|
const name = path.basename(item.name);
|
||||||
@@ -171,7 +174,7 @@ export default async function collectionImporter({
|
|||||||
Logger.info("commands", `Skipped importing ${item.path}`);
|
Logger.info("commands", `Skipped importing ${item.path}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All collections, documents, and attachments have been created – time to
|
// All collections, documents, and attachments have been created - time to
|
||||||
// update the documents to point to newly uploaded attachments where possible
|
// update the documents to point to newly uploaded attachments where possible
|
||||||
for (const attachmentPath of keys(attachments)) {
|
for (const attachmentPath of keys(attachments)) {
|
||||||
const attachment = attachments[attachmentPath];
|
const attachment = attachments[attachmentPath];
|
||||||
|
|||||||
Reference in New Issue
Block a user