@yomotech/view-toolkit 0.0.13 → 0.0.14
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();
|