quasar-ui-danx 0.3.40 → 0.3.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.3.40",
3
+ "version": "0.3.42",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -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 { FileUpload } from "../../../../helpers";
27
+ import { downloadFile, fDateTime, FileUpload, sleep } from "../../../../helpers";
28
28
 
29
29
  defineExpose({ upload });
30
30
  const emit = defineEmits([
@@ -44,7 +44,12 @@ const props = defineProps({
44
44
  default: "Waiting for location..."
45
45
  },
46
46
  cameraOnly: Boolean,
47
- geolocation: Boolean
47
+ geolocation: Boolean,
48
+ autoDownloadCapture: Boolean,
49
+ downloadName: {
50
+ type: String,
51
+ default: "Upload"
52
+ }
48
53
  });
49
54
 
50
55
  const fileUpload = ref(null);
@@ -61,6 +66,10 @@ function upload() {
61
66
  */
62
67
  async function onAttachFiles({ target: { files } }) {
63
68
  console.log("files attached", files);
69
+ if (props.autoDownloadCapture) {
70
+ await saveFilesLocally(files);
71
+ }
72
+ console.log("uploading files");
64
73
  emit("uploading", files);
65
74
  let fileUpload = new FileUpload(files)
66
75
  .onProgress(({ file, progress }) => {
@@ -83,4 +92,22 @@ async function onAttachFiles({ target: { files } }) {
83
92
 
84
93
  fileUpload.upload();
85
94
  }
95
+
96
+
97
+ async function saveFilesLocally(files) {
98
+ // Make sure the blob URL is set before saving
99
+ await sleep(10);
100
+
101
+ for (let file of files) {
102
+ let fileName = props.downloadName + "-" + fDateTime(null, { format: " M-d-yy h:mm a" });
103
+ if (file.name) {
104
+ fileName += "__" + file.name;
105
+ } else {
106
+ fileName += "." + (file.mime || file.type).split("/").pop() || "jpg";
107
+ }
108
+ console.log("downloading ", fileName);
109
+ await downloadFile(file.blobUrl, fileName);
110
+ console.log("downloaded");
111
+ }
112
+ }
86
113
  </script>
@@ -1,5 +1,6 @@
1
1
  import { uid } from "quasar";
2
2
  import { danxOptions } from "../config";
3
+ import { sleep } from "../helpers";
3
4
  import { resolveFileLocation } from "./files";
4
5
  import { FlashMessages } from "./FlashMessages";
5
6
 
@@ -277,7 +278,16 @@ export class FileUpload {
277
278
  console.log("calling presigned URL", presignedUrl);
278
279
 
279
280
  // Fetch presigned upload URL
280
- const fileResource = await fetch(presignedUrl).then(r => r.json());
281
+ let fileResource;
282
+
283
+ try {
284
+ fileResource = await fetch(presignedUrl).then(r => r.json());
285
+ } catch (error) {
286
+ console.log("First upload attempt failed. waiting and trying again:", error);
287
+ await sleep(3000);
288
+ console.log("upload attempt 2...");
289
+ fileResource = await fetch(presignedUrl).then(r => r.json());
290
+ }
281
291
 
282
292
  console.log("loaded presignedUrl: fileResource", fileResource);
283
293