@@ -8,13 +8,14 @@ export default function download(
|
||||
strFileName: string,
|
||||
strMimeType?: string
|
||||
) {
|
||||
const self = window,
|
||||
// this script is only for browsers anyway...
|
||||
u = "application/octet-stream",
|
||||
// this default mime also triggers iframe downloads
|
||||
m = strMimeType || u,
|
||||
x = data,
|
||||
D = document,
|
||||
const self = window;
|
||||
// this script is only for browsers anyway...
|
||||
const u = "application/octet-stream";
|
||||
|
||||
// this default mime also triggers iframe downloads
|
||||
let m = strMimeType || u,
|
||||
x = data;
|
||||
const D = document,
|
||||
a = D.createElement("a"),
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'a' implicitly has an 'any' type.
|
||||
z = function (a) {
|
||||
@@ -24,21 +25,15 @@ export default function download(
|
||||
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
|
||||
BB = self.MSBlobBuilder || self.WebKitBlobBuilder || self.BlobBuilder,
|
||||
fn = strFileName || "download",
|
||||
// @ts-expect-error ts-migrate(1155) FIXME: 'const' declarations must be initialized.
|
||||
blob,
|
||||
// @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;
|
||||
fn = strFileName || "download";
|
||||
|
||||
let blob, b, fr;
|
||||
|
||||
if (String(this) === "true") {
|
||||
//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.
|
||||
// reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
||||
// @ts-expect-error this is weird code
|
||||
x = [x, m];
|
||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'm' because it is a constant.
|
||||
m = x[0];
|
||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'x' because it is a constant.
|
||||
x = x[1];
|
||||
}
|
||||
|
||||
@@ -50,7 +45,6 @@ export default function download(
|
||||
|
||||
//end if dataURL passed?
|
||||
try {
|
||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'blob' because it is a constant.
|
||||
blob =
|
||||
x instanceof B
|
||||
? x
|
||||
@@ -59,16 +53,13 @@ export default function download(
|
||||
});
|
||||
} catch (y) {
|
||||
if (BB) {
|
||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'b' because it is a constant.
|
||||
b = new BB();
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'u' implicitly has an 'any' type.
|
||||
function d2b(u) {
|
||||
function d2b(u: string) {
|
||||
if (typeof u !== "string") {
|
||||
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.
|
||||
bin = dec(p.pop()),
|
||||
mx = bin.length,
|
||||
i = 0,
|
||||
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);
|
||||
|
||||
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") {
|
||||
throw Error("Attempted to pass non-string url to saver");
|
||||
}
|
||||
@@ -141,19 +131,15 @@ export default function download(
|
||||
typeof m === "string"
|
||||
) {
|
||||
try {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
||||
return saver("data:" + m + ";base64," + self.btoa(blob));
|
||||
} catch (y) {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
||||
return saver("data:" + m + "," + encodeURIComponent(blob));
|
||||
}
|
||||
}
|
||||
|
||||
// Blob but not URL:
|
||||
// @ts-expect-error ts-migrate(2588) FIXME: Cannot assign to 'fr' because it is a constant.
|
||||
fr = new FileReader();
|
||||
|
||||
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'e' implicitly has an 'any' type.
|
||||
fr.onload = function (e) {
|
||||
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
|
||||
saver(this.result);
|
||||
|
||||
@@ -64,7 +64,7 @@ export default async function collectionImporter({
|
||||
for (const item of items) {
|
||||
if (item.type === "collection") {
|
||||
// check if collection with name exists
|
||||
const [collection, isCreated] = await Collection.findOrCreate({
|
||||
const response = await Collection.findOrCreate({
|
||||
where: {
|
||||
teamId: user.teamId,
|
||||
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
|
||||
// there is also a "Name (Imported)" but this is a case not worth dealing
|
||||
// with right now
|
||||
if (!isCreated) {
|
||||
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({
|
||||
teamId: user.teamId,
|
||||
createdById: user.id,
|
||||
@@ -107,6 +109,7 @@ export default async function collectionImporter({
|
||||
const collectionDir = item.dir.split("/")[0];
|
||||
const collection = collections[collectionDir];
|
||||
invariant(collection, `Collection must exist for document ${item.dir}`);
|
||||
|
||||
// we have a document
|
||||
const content = await item.item.async("string");
|
||||
const name = path.basename(item.name);
|
||||
@@ -171,7 +174,7 @@ export default async function collectionImporter({
|
||||
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
|
||||
for (const attachmentPath of keys(attachments)) {
|
||||
const attachment = attachments[attachmentPath];
|
||||
|
||||
Reference in New Issue
Block a user