@knime/hub-features 1.0.8 → 1.0.10
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/CHANGELOG.md +18 -0
- package/package.json +4 -4
- package/src/useFileUpload/useFileUpload.ts +49 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @knime/hub-features
|
|
2
2
|
|
|
3
|
+
## 1.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 15a4479: - fix mimetype detection for KNIME formats (.knwf, .knar)
|
|
8
|
+
- enforce a max queue size when processing uploads
|
|
9
|
+
- Updated dependencies [15a4479]
|
|
10
|
+
- Updated dependencies [15a4479]
|
|
11
|
+
- @knime/utils@1.1.2
|
|
12
|
+
- @knime/components@1.8.2
|
|
13
|
+
|
|
14
|
+
## 1.0.9
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [3b80728]
|
|
19
|
+
- @knime/components@1.8.1
|
|
20
|
+
|
|
3
21
|
## 1.0.8
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knime/hub-features",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Vue components & composables for shared hub features",
|
|
5
5
|
"homepage": "https://knime.github.io/webapps-common/",
|
|
6
6
|
"license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"@vueuse/shared": "^10.10.0",
|
|
27
27
|
"consola": "3.2.3",
|
|
28
28
|
"typescript": "^5.4.5",
|
|
29
|
-
"@knime/components": "1.8.
|
|
30
|
-
"@knime/
|
|
31
|
-
"@knime/
|
|
29
|
+
"@knime/components": "1.8.2",
|
|
30
|
+
"@knime/styles": "1.1.1",
|
|
31
|
+
"@knime/utils": "1.1.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"vue": "3.x"
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
2
|
|
|
3
3
|
import { useUploadManager } from "@knime/components";
|
|
4
|
-
import { promise } from "@knime/utils";
|
|
4
|
+
import { getFileMimeType, promise } from "@knime/utils";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_MAX_UPLOAD_QUEUE_SIZE = 10;
|
|
5
7
|
|
|
6
8
|
const DEFAULT_API_BASE_URL = "/_/api";
|
|
7
9
|
|
|
8
10
|
type UseFileUploadOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Max number of concurrent uploads allowed in the upload queue.
|
|
13
|
+
* When an upload is started with a number of files that exceed the pending
|
|
14
|
+
* uploads then only files up-to the max queue size will be processed and the rest
|
|
15
|
+
* will be ignored. This will also call the `onUploadQueueSizeExceeded` callback
|
|
16
|
+
*/
|
|
17
|
+
maxUploadQueueSize?: number;
|
|
9
18
|
apiBaseUrl?: string;
|
|
10
19
|
onFileUploadComplete?: (
|
|
11
20
|
uploadId: string,
|
|
12
21
|
filePartIds: Record<number, string>,
|
|
13
22
|
) => void;
|
|
14
23
|
onFileUploadFailed?: (uploadId: string, error: Error) => void;
|
|
24
|
+
onUploadQueueSizeExceeded?: (maxQueueSize: number) => void;
|
|
15
25
|
};
|
|
16
26
|
|
|
17
27
|
/**
|
|
@@ -100,7 +110,7 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
100
110
|
Object.fromEntries(
|
|
101
111
|
Object.entries(fileDictionary).map(([name, file]) => [
|
|
102
112
|
name,
|
|
103
|
-
{ itemContentType: file
|
|
113
|
+
{ itemContentType: getFileMimeType(file) },
|
|
104
114
|
]),
|
|
105
115
|
);
|
|
106
116
|
|
|
@@ -163,7 +173,6 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
163
173
|
};
|
|
164
174
|
|
|
165
175
|
const useUploadManagerResult = useUploadManager({
|
|
166
|
-
prepareUpload,
|
|
167
176
|
resolveFilePartUploadURL,
|
|
168
177
|
|
|
169
178
|
onFileUploadComplete: ({ uploadId, filePartIds }) => {
|
|
@@ -174,12 +183,7 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
174
183
|
})
|
|
175
184
|
.catch((error) => {
|
|
176
185
|
consola.error("Error attempting to complete upload", { error });
|
|
177
|
-
useUploadManagerResult.setFailed(
|
|
178
|
-
uploadId,
|
|
179
|
-
error instanceof Error
|
|
180
|
-
? error
|
|
181
|
-
: new Error("Error attempting to complete upload"),
|
|
182
|
-
);
|
|
186
|
+
useUploadManagerResult.setFailed(uploadId, error as Error);
|
|
183
187
|
});
|
|
184
188
|
},
|
|
185
189
|
|
|
@@ -188,9 +192,44 @@ export const useFileUpload = (options: UseFileUploadOptions = {}) => {
|
|
|
188
192
|
},
|
|
189
193
|
});
|
|
190
194
|
|
|
195
|
+
const getEnqueueableFiles = (files: File[]): File[] => {
|
|
196
|
+
const { totalPendingUploads } = useUploadManagerResult;
|
|
197
|
+
|
|
198
|
+
const { maxUploadQueueSize = DEFAULT_MAX_UPLOAD_QUEUE_SIZE } = options;
|
|
199
|
+
|
|
200
|
+
if (files.length + totalPendingUploads.value > maxUploadQueueSize) {
|
|
201
|
+
options.onUploadQueueSizeExceeded?.(maxUploadQueueSize);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// only keep as many files as the queue allows
|
|
205
|
+
return files.slice(0, maxUploadQueueSize - totalPendingUploads.value);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const isPreparingUpload = ref(false);
|
|
209
|
+
|
|
191
210
|
return {
|
|
192
211
|
...useUploadManagerResult,
|
|
193
212
|
|
|
213
|
+
isPreparingUpload: computed(() => isPreparingUpload.value),
|
|
214
|
+
|
|
215
|
+
start: async (parentId: string, files: File[]) => {
|
|
216
|
+
try {
|
|
217
|
+
isPreparingUpload.value = true;
|
|
218
|
+
|
|
219
|
+
// TODO: HUB-9102: improve error handling here. see ticket for details
|
|
220
|
+
const uploadPayload = await promise.retryPromise(() =>
|
|
221
|
+
prepareUpload(parentId, getEnqueueableFiles(files)),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
isPreparingUpload.value = false;
|
|
225
|
+
|
|
226
|
+
useUploadManagerResult.start(parentId, uploadPayload);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
// TODO: HUB-8152 process max file size error
|
|
229
|
+
consola.error(error);
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
|
|
194
233
|
cancel: (uploadId: string) => {
|
|
195
234
|
useUploadManagerResult.cancel(uploadId);
|
|
196
235
|
cancelUpload(uploadId).catch((error) => {
|