quasar-ui-danx 0.3.42 → 0.3.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/danx.es.js +129 -101
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +4 -4
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/Form/Fields/FileUploadButton.vue +7 -9
- package/src/helpers/FileUpload.ts +11 -19
- package/src/helpers/download.ts +51 -0
package/package.json
CHANGED
@@ -24,7 +24,7 @@
|
|
24
24
|
import { PlusIcon } from "@heroicons/vue/outline";
|
25
25
|
import { QBtn } from "quasar";
|
26
26
|
import { ref } from "vue";
|
27
|
-
import {
|
27
|
+
import { downloadBlobOrUrl, fDateTime, FileUpload, sleep } from "../../../../helpers";
|
28
28
|
|
29
29
|
defineExpose({ upload });
|
30
30
|
const emit = defineEmits([
|
@@ -65,11 +65,9 @@ function upload() {
|
|
65
65
|
* @returns {Promise<void>}
|
66
66
|
*/
|
67
67
|
async function onAttachFiles({ target: { files } }) {
|
68
|
-
console.log("files attached", files);
|
69
68
|
if (props.autoDownloadCapture) {
|
70
69
|
await saveFilesLocally(files);
|
71
70
|
}
|
72
|
-
console.log("uploading files");
|
73
71
|
emit("uploading", files);
|
74
72
|
let fileUpload = new FileUpload(files)
|
75
73
|
.onProgress(({ file, progress }) => {
|
@@ -83,9 +81,6 @@ async function onAttachFiles({ target: { files } }) {
|
|
83
81
|
emit("complete", fileUpload.files);
|
84
82
|
});
|
85
83
|
|
86
|
-
console.log("created fileUpload", fileUpload);
|
87
|
-
|
88
|
-
debugger;
|
89
84
|
if (props.geolocation) {
|
90
85
|
await fileUpload.resolveLocation(props.locationWaitMessage);
|
91
86
|
}
|
@@ -105,9 +100,12 @@ async function saveFilesLocally(files) {
|
|
105
100
|
} else {
|
106
101
|
fileName += "." + (file.mime || file.type).split("/").pop() || "jpg";
|
107
102
|
}
|
108
|
-
|
109
|
-
|
110
|
-
|
103
|
+
|
104
|
+
try {
|
105
|
+
await downloadBlobOrUrl(file, fileName);
|
106
|
+
} catch (e) {
|
107
|
+
console.error("Failed to download file", e);
|
108
|
+
}
|
111
109
|
}
|
112
110
|
}
|
113
111
|
</script>
|
@@ -269,29 +269,25 @@ export class FileUpload {
|
|
269
269
|
* Start uploading all files
|
270
270
|
*/
|
271
271
|
async upload() {
|
272
|
-
console.log && console.log("FileUploader@upload():", this.fileUploads, this.options);
|
273
272
|
for (const fileUpload of this.fileUploads) {
|
274
273
|
try {
|
275
274
|
const mimeType = fileUpload.file.mimeType || fileUpload.file.type;
|
276
275
|
const presignedUrl = this.options.presignedUploadUrl(this.options.directory, fileUpload.file.name, mimeType);
|
277
276
|
|
278
|
-
console.log("calling presigned URL", presignedUrl);
|
279
|
-
|
280
277
|
// Fetch presigned upload URL
|
281
|
-
let fileResource;
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
278
|
+
let fileResource = null;
|
279
|
+
let count = 60;
|
280
|
+
|
281
|
+
while (!fileResource && count-- > 0) {
|
282
|
+
try {
|
283
|
+
fileResource = await fetch(presignedUrl).then(r => r.json());
|
284
|
+
} catch (error) {
|
285
|
+
console.warn(`Upload failed, trying ${count} more times....`, error);
|
286
|
+
await sleep(1000);
|
287
|
+
}
|
290
288
|
}
|
291
289
|
|
292
|
-
|
293
|
-
|
294
|
-
if (!fileResource.url) {
|
290
|
+
if (!fileResource?.url) {
|
295
291
|
FlashMessages.error("Could not fetch presigned upload URL for file " + fileUpload.file.name);
|
296
292
|
continue;
|
297
293
|
}
|
@@ -306,9 +302,7 @@ export class FileUpload {
|
|
306
302
|
|
307
303
|
// The XHR request is different based on weather we're sending to S3 or the platform server
|
308
304
|
if (isS3Upload) {
|
309
|
-
console.log("uploading S3", xhr);
|
310
305
|
xhr.open("PUT", fileResource.url);
|
311
|
-
console.log("setting content type to", mimeType);
|
312
306
|
xhr.setRequestHeader("Content-Type", mimeType);
|
313
307
|
fileUpload.body = fileUpload.file;
|
314
308
|
} else {
|
@@ -326,8 +320,6 @@ export class FileUpload {
|
|
326
320
|
// Set all the callbacks on the XHR requests
|
327
321
|
this.setXhrCallbacks();
|
328
322
|
|
329
|
-
console.log && console.log("FileUploader@upload():", "sending uploads");
|
330
|
-
|
331
323
|
// Send all the XHR file uploads
|
332
324
|
for (const fileUpload of this.fileUploads) {
|
333
325
|
fileUpload.xhr.send(fileUpload.body);
|
package/src/helpers/download.ts
CHANGED
@@ -7,6 +7,57 @@
|
|
7
7
|
// semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
|
8
8
|
// https://github.com/rndme/download
|
9
9
|
|
10
|
+
export async function downloadBlobOrUrl(blobOrUrl, filename = "download") {
|
11
|
+
// Create a Promise that resolves to a Blob URL
|
12
|
+
const blobUrlPromise = new Promise((resolve, reject) => {
|
13
|
+
if (blobOrUrl instanceof File) {
|
14
|
+
// Create an object URL from the File
|
15
|
+
const url = URL.createObjectURL(blobOrUrl);
|
16
|
+
resolve(url);
|
17
|
+
} else if (typeof blobOrUrl === "string") {
|
18
|
+
// It's a Blob URL
|
19
|
+
resolve(blobOrUrl);
|
20
|
+
} else if (blobOrUrl instanceof Blob) {
|
21
|
+
// Create an object URL from the Blob
|
22
|
+
const url = URL.createObjectURL(blobOrUrl);
|
23
|
+
resolve(url);
|
24
|
+
} else {
|
25
|
+
console.error("blobOrUrl was not a Blob or URL", blobOrUrl);
|
26
|
+
reject(new Error("The provided value must be a Blob or a Blob URL string."));
|
27
|
+
}
|
28
|
+
});
|
29
|
+
|
30
|
+
return await blobUrlPromise.then((blobUrl) => {
|
31
|
+
// Create a temporary anchor element
|
32
|
+
const anchor = document.createElement("a");
|
33
|
+
anchor.style.display = "none";
|
34
|
+
anchor.href = blobUrl as string;
|
35
|
+
anchor.download = filename;
|
36
|
+
anchor.target = "_blank";
|
37
|
+
|
38
|
+
// Append the anchor to the body
|
39
|
+
document.body.appendChild(anchor);
|
40
|
+
|
41
|
+
// Programmatically trigger a click event on the anchor
|
42
|
+
const clickEvent = new MouseEvent("click", {
|
43
|
+
view: window,
|
44
|
+
bubbles: true,
|
45
|
+
cancelable: true
|
46
|
+
});
|
47
|
+
anchor.dispatchEvent(clickEvent);
|
48
|
+
|
49
|
+
// Remove the anchor from the document
|
50
|
+
document.body.removeChild(anchor);
|
51
|
+
|
52
|
+
// Revoke the object URL if we created one
|
53
|
+
if (blobOrUrl instanceof Blob) {
|
54
|
+
setTimeout(() => URL.revokeObjectURL(blobUrl), 100);
|
55
|
+
}
|
56
|
+
}).catch((error) => {
|
57
|
+
console.error("An error occurred while downloading the file:", error);
|
58
|
+
});
|
59
|
+
}
|
60
|
+
|
10
61
|
/* eslint-disable */
|
11
62
|
export function download(data, strFileName, strMimeType) {
|
12
63
|
var self = window;
|