@yomotech/view-toolkit 0.0.13 → 0.0.15
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.
|
@@ -2441,11 +2441,17 @@ class Couchdb {
|
|
|
2441
2441
|
return null;
|
|
2442
2442
|
}
|
|
2443
2443
|
// do not decode images as utf8 text
|
|
2444
|
-
if (
|
|
2444
|
+
if (doc.type === 'media' ||
|
|
2445
|
+
doc.type === 'base64file' ||
|
|
2446
|
+
this.isBinaryMediaFile(doc.name || doc.path || docId, doc.contentType)) {
|
|
2445
2447
|
return {
|
|
2446
|
-
type: 'base64file',
|
|
2447
|
-
mimeType: doc.
|
|
2448
|
+
type: doc.type || 'base64file',
|
|
2449
|
+
mimeType: this.getMimeType(doc.name || doc.path || docId, doc.contentType),
|
|
2448
2450
|
base64: doc.data,
|
|
2451
|
+
src: `data:${this.getMimeType(doc.name || doc.path || docId, doc.contentType)};base64,${doc.data}`,
|
|
2452
|
+
name: doc.name,
|
|
2453
|
+
path: doc.path,
|
|
2454
|
+
metadata: doc.metadata || {},
|
|
2449
2455
|
};
|
|
2450
2456
|
}
|
|
2451
2457
|
const decodedContent = this.fromBase64(doc.data);
|
|
@@ -2465,14 +2471,56 @@ class Couchdb {
|
|
|
2465
2471
|
return null;
|
|
2466
2472
|
}
|
|
2467
2473
|
}
|
|
2468
|
-
|
|
2474
|
+
isBinaryMediaFile(fileNameOrPath, contentType) {
|
|
2469
2475
|
const lower = (fileNameOrPath || '').toLowerCase();
|
|
2470
|
-
|
|
2476
|
+
const type = contentType || '';
|
|
2477
|
+
return (type.startsWith('image/') ||
|
|
2478
|
+
type.startsWith('video/') ||
|
|
2479
|
+
type.startsWith('audio/') ||
|
|
2480
|
+
type === 'application/pdf' ||
|
|
2481
|
+
lower.endsWith('.png') ||
|
|
2471
2482
|
lower.endsWith('.jpg') ||
|
|
2472
2483
|
lower.endsWith('.jpeg') ||
|
|
2473
2484
|
lower.endsWith('.ico') ||
|
|
2474
2485
|
lower.endsWith('.svg') ||
|
|
2475
|
-
(
|
|
2486
|
+
lower.endsWith('.webp') ||
|
|
2487
|
+
lower.endsWith('.gif') ||
|
|
2488
|
+
lower.endsWith('.mp4') ||
|
|
2489
|
+
lower.endsWith('.webm') ||
|
|
2490
|
+
lower.endsWith('.mp3') ||
|
|
2491
|
+
lower.endsWith('.wav') ||
|
|
2492
|
+
lower.endsWith('.m4a') ||
|
|
2493
|
+
lower.endsWith('.pdf'));
|
|
2494
|
+
}
|
|
2495
|
+
getMimeType(fileNameOrPath, contentType) {
|
|
2496
|
+
if (contentType)
|
|
2497
|
+
return contentType;
|
|
2498
|
+
const lower = (fileNameOrPath || '').toLowerCase();
|
|
2499
|
+
if (lower.endsWith('.png'))
|
|
2500
|
+
return 'image/png';
|
|
2501
|
+
if (lower.endsWith('.jpg') || lower.endsWith('.jpeg'))
|
|
2502
|
+
return 'image/jpeg';
|
|
2503
|
+
if (lower.endsWith('.ico'))
|
|
2504
|
+
return 'image/x-icon';
|
|
2505
|
+
if (lower.endsWith('.svg'))
|
|
2506
|
+
return 'image/svg+xml';
|
|
2507
|
+
if (lower.endsWith('.webp'))
|
|
2508
|
+
return 'image/webp';
|
|
2509
|
+
if (lower.endsWith('.gif'))
|
|
2510
|
+
return 'image/gif';
|
|
2511
|
+
if (lower.endsWith('.mp4'))
|
|
2512
|
+
return 'video/mp4';
|
|
2513
|
+
if (lower.endsWith('.webm'))
|
|
2514
|
+
return 'video/webm';
|
|
2515
|
+
if (lower.endsWith('.mp3'))
|
|
2516
|
+
return 'audio/mpeg';
|
|
2517
|
+
if (lower.endsWith('.wav'))
|
|
2518
|
+
return 'audio/wav';
|
|
2519
|
+
if (lower.endsWith('.m4a'))
|
|
2520
|
+
return 'audio/mp4';
|
|
2521
|
+
if (lower.endsWith('.pdf'))
|
|
2522
|
+
return 'application/pdf';
|
|
2523
|
+
return 'application/octet-stream';
|
|
2476
2524
|
}
|
|
2477
2525
|
getImageMimeType(fileNameOrPath) {
|
|
2478
2526
|
const lower = (fileNameOrPath || '').toLowerCase();
|
|
@@ -2934,7 +2982,9 @@ class SideMenuComponent {
|
|
|
2934
2982
|
subMenu?.submenu.forEach((childMenu) => {
|
|
2935
2983
|
tasks.push((async () => {
|
|
2936
2984
|
try {
|
|
2937
|
-
|
|
2985
|
+
let projectName = `${this.tenantName}_${this.projectSeleted}`;
|
|
2986
|
+
const image = await this.couchdbService.getFileContentFromCouchDb(projectName, childMenu.icon);
|
|
2987
|
+
childMenu.icon = this.getMediaSrc(image);
|
|
2938
2988
|
}
|
|
2939
2989
|
catch (err) {
|
|
2940
2990
|
console.error("Failed to fetch icon:", err);
|
|
@@ -3039,7 +3089,9 @@ class SideMenuComponent {
|
|
|
3039
3089
|
if (childMenu.options && childMenu.options.setImageUrl) {
|
|
3040
3090
|
tasks.push((async () => {
|
|
3041
3091
|
try {
|
|
3042
|
-
|
|
3092
|
+
let projectName = `${this.tenantName}_${this.projectSeleted}`;
|
|
3093
|
+
const image = await this.couchdbService.getFileContentFromCouchDb(projectName, childMenu.icon);
|
|
3094
|
+
childMenu.icon = this.getMediaSrc(image);
|
|
3043
3095
|
}
|
|
3044
3096
|
catch (err) {
|
|
3045
3097
|
console.error("Failed to fetch icon:", err);
|
|
@@ -3053,6 +3105,24 @@ class SideMenuComponent {
|
|
|
3053
3105
|
}
|
|
3054
3106
|
this.settingMenu = JSON.parse(JSON.stringify(this.settings));
|
|
3055
3107
|
}
|
|
3108
|
+
getMediaSrc(file) {
|
|
3109
|
+
if (!file)
|
|
3110
|
+
return '';
|
|
3111
|
+
// Best case: service already returns full data URL
|
|
3112
|
+
if (file.src) {
|
|
3113
|
+
return file.src;
|
|
3114
|
+
}
|
|
3115
|
+
// If service returns raw base64 + mimeType
|
|
3116
|
+
if (file.base64) {
|
|
3117
|
+
const mimeType = file.mimeType || 'image/png';
|
|
3118
|
+
return `data:${mimeType};base64,${file.base64}`;
|
|
3119
|
+
}
|
|
3120
|
+
// If service returns old dataUrl format
|
|
3121
|
+
if (file.dataUrl) {
|
|
3122
|
+
return file.dataUrl;
|
|
3123
|
+
}
|
|
3124
|
+
return '';
|
|
3125
|
+
}
|
|
3056
3126
|
isUrl(value) {
|
|
3057
3127
|
return /^https?:\/\//.test(value) || value.startsWith('blob:');
|
|
3058
3128
|
}
|