sf-crud 13.2.56 → 13.2.57
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/fesm2022/sf-crud.mjs
CHANGED
|
@@ -2202,6 +2202,7 @@ class ControlComponent {
|
|
|
2202
2202
|
isLoading = false;
|
|
2203
2203
|
dataFromService = [];
|
|
2204
2204
|
uploadedFiles = [];
|
|
2205
|
+
_loadFilesId = 0;
|
|
2205
2206
|
displayAdd = false;
|
|
2206
2207
|
tempValue;
|
|
2207
2208
|
clicked = false;
|
|
@@ -2370,24 +2371,70 @@ class ControlComponent {
|
|
|
2370
2371
|
this.value = this.tempValue;
|
|
2371
2372
|
this.sendValue();
|
|
2372
2373
|
}
|
|
2373
|
-
loadFiles() {
|
|
2374
|
+
async loadFiles() {
|
|
2375
|
+
const runId = ++this._loadFilesId;
|
|
2374
2376
|
this.isLoading = true;
|
|
2375
2377
|
this.uploadedFiles = [];
|
|
2376
2378
|
if (!this.value) {
|
|
2377
2379
|
this.isLoading = false;
|
|
2378
2380
|
this.cdr.detectChanges();
|
|
2381
|
+
return;
|
|
2379
2382
|
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2383
|
+
const mimeTypes = {
|
|
2384
|
+
pdf: 'application/pdf', jpg: 'image/jpeg', jpeg: 'image/jpeg',
|
|
2385
|
+
png: 'image/png', gif: 'image/gif', bmp: 'image/bmp'
|
|
2386
|
+
};
|
|
2387
|
+
const resolveUrl = async (url) => {
|
|
2388
|
+
try {
|
|
2389
|
+
const res = await fetch(url, { method: 'HEAD' });
|
|
2390
|
+
if (res.ok)
|
|
2391
|
+
return url;
|
|
2392
|
+
const lastSlash = url.lastIndexOf('/');
|
|
2393
|
+
const uploadedUrl = url.substring(0, lastSlash + 1) + 'UPLOADED_' + url.substring(lastSlash + 1);
|
|
2394
|
+
const res2 = await fetch(uploadedUrl, { method: 'HEAD' });
|
|
2395
|
+
if (!res2.ok)
|
|
2396
|
+
return null;
|
|
2397
|
+
const ext = url.substring(url.lastIndexOf('.') + 1).toLowerCase();
|
|
2398
|
+
const mimeType = mimeTypes[ext] ?? 'application/octet-stream';
|
|
2399
|
+
const content = await fetch(uploadedUrl);
|
|
2400
|
+
const buffer = await content.arrayBuffer();
|
|
2401
|
+
return URL.createObjectURL(new Blob([buffer], { type: mimeType }));
|
|
2402
|
+
}
|
|
2403
|
+
catch {
|
|
2404
|
+
return null;
|
|
2405
|
+
}
|
|
2406
|
+
};
|
|
2407
|
+
if (this.control.config.namePattern && this.control.type == "string") {
|
|
2408
|
+
const urls = this.control.config.separator ? this.value.split(",") : [this.value];
|
|
2409
|
+
const validUrls = [];
|
|
2410
|
+
for (const url of urls) {
|
|
2411
|
+
const resolved = await resolveUrl(url);
|
|
2412
|
+
if (runId !== this._loadFilesId)
|
|
2413
|
+
return;
|
|
2414
|
+
if (resolved !== null) {
|
|
2415
|
+
this.uploadedFiles.push({ url: resolved, name: this.getNameFile(this.control.config.namePattern, url) });
|
|
2416
|
+
validUrls.push(url);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
if (validUrls.length !== urls.length)
|
|
2420
|
+
this.value = validUrls.length > 0 ? validUrls.join(this.control.config?.separator || ',') : null;
|
|
2385
2421
|
}
|
|
2386
2422
|
else if (this.control.config.namePattern && this.control.type == "array") {
|
|
2387
|
-
|
|
2388
|
-
this.
|
|
2389
|
-
|
|
2423
|
+
const validUrls = [];
|
|
2424
|
+
for (const url of this.value) {
|
|
2425
|
+
const resolved = await resolveUrl(url);
|
|
2426
|
+
if (runId !== this._loadFilesId)
|
|
2427
|
+
return;
|
|
2428
|
+
if (resolved !== null) {
|
|
2429
|
+
this.uploadedFiles.push({ url: resolved, name: this.getNameFile(this.control.config.namePattern, url) });
|
|
2430
|
+
validUrls.push(url);
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
if (validUrls.length !== this.value.length)
|
|
2434
|
+
this.value = validUrls.length > 0 ? validUrls : null;
|
|
2390
2435
|
}
|
|
2436
|
+
this.isLoading = false;
|
|
2437
|
+
this.cdr.detectChanges();
|
|
2391
2438
|
}
|
|
2392
2439
|
onDeleteFile(index) {
|
|
2393
2440
|
if ((!this.control.config?.limit || this.control.config?.limit == 1) && this.control.type == "string")
|