@canonmsg/backend-contracts 1.4.0 → 1.5.0
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/dist/cjs/media.js +15 -4
- package/dist/media.js +15 -4
- package/package.json +1 -1
package/dist/cjs/media.js
CHANGED
|
@@ -59,6 +59,13 @@ function getStoredFileExtension(input) {
|
|
|
59
59
|
}
|
|
60
60
|
return 'bin';
|
|
61
61
|
}
|
|
62
|
+
// Numeric attachment metadata flows straight into every client's duration and
|
|
63
|
+
// size formatting; NaN/Infinity/negatives are dropped rather than stored.
|
|
64
|
+
function normalizeAttachmentNumber(value) {
|
|
65
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
66
|
+
? value
|
|
67
|
+
: undefined;
|
|
68
|
+
}
|
|
62
69
|
function normalizeStoredAttachments(value) {
|
|
63
70
|
if (!Array.isArray(value))
|
|
64
71
|
return null;
|
|
@@ -76,15 +83,19 @@ function normalizeStoredAttachments(value) {
|
|
|
76
83
|
if (typeof candidate.url !== 'string' || candidate.url.length === 0) {
|
|
77
84
|
return null;
|
|
78
85
|
}
|
|
86
|
+
const sizeBytes = normalizeAttachmentNumber(candidate.sizeBytes);
|
|
87
|
+
const width = normalizeAttachmentNumber(candidate.width);
|
|
88
|
+
const height = normalizeAttachmentNumber(candidate.height);
|
|
89
|
+
const durationMs = normalizeAttachmentNumber(candidate.durationMs);
|
|
79
90
|
attachments.push({
|
|
80
91
|
kind: candidate.kind,
|
|
81
92
|
url: candidate.url,
|
|
82
93
|
...(typeof candidate.mimeType === 'string' && candidate.mimeType ? { mimeType: candidate.mimeType } : {}),
|
|
83
94
|
...(typeof candidate.fileName === 'string' && candidate.fileName ? { fileName: candidate.fileName } : {}),
|
|
84
|
-
...(
|
|
85
|
-
...(
|
|
86
|
-
...(
|
|
87
|
-
...(
|
|
95
|
+
...(sizeBytes !== undefined ? { sizeBytes } : {}),
|
|
96
|
+
...(width !== undefined ? { width } : {}),
|
|
97
|
+
...(height !== undefined ? { height } : {}),
|
|
98
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
88
99
|
});
|
|
89
100
|
}
|
|
90
101
|
return attachments.length > 0 ? attachments : [];
|
package/dist/media.js
CHANGED
|
@@ -51,6 +51,13 @@ export function getStoredFileExtension(input) {
|
|
|
51
51
|
}
|
|
52
52
|
return 'bin';
|
|
53
53
|
}
|
|
54
|
+
// Numeric attachment metadata flows straight into every client's duration and
|
|
55
|
+
// size formatting; NaN/Infinity/negatives are dropped rather than stored.
|
|
56
|
+
function normalizeAttachmentNumber(value) {
|
|
57
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
58
|
+
? value
|
|
59
|
+
: undefined;
|
|
60
|
+
}
|
|
54
61
|
export function normalizeStoredAttachments(value) {
|
|
55
62
|
if (!Array.isArray(value))
|
|
56
63
|
return null;
|
|
@@ -68,15 +75,19 @@ export function normalizeStoredAttachments(value) {
|
|
|
68
75
|
if (typeof candidate.url !== 'string' || candidate.url.length === 0) {
|
|
69
76
|
return null;
|
|
70
77
|
}
|
|
78
|
+
const sizeBytes = normalizeAttachmentNumber(candidate.sizeBytes);
|
|
79
|
+
const width = normalizeAttachmentNumber(candidate.width);
|
|
80
|
+
const height = normalizeAttachmentNumber(candidate.height);
|
|
81
|
+
const durationMs = normalizeAttachmentNumber(candidate.durationMs);
|
|
71
82
|
attachments.push({
|
|
72
83
|
kind: candidate.kind,
|
|
73
84
|
url: candidate.url,
|
|
74
85
|
...(typeof candidate.mimeType === 'string' && candidate.mimeType ? { mimeType: candidate.mimeType } : {}),
|
|
75
86
|
...(typeof candidate.fileName === 'string' && candidate.fileName ? { fileName: candidate.fileName } : {}),
|
|
76
|
-
...(
|
|
77
|
-
...(
|
|
78
|
-
...(
|
|
79
|
-
...(
|
|
87
|
+
...(sizeBytes !== undefined ? { sizeBytes } : {}),
|
|
88
|
+
...(width !== undefined ? { width } : {}),
|
|
89
|
+
...(height !== undefined ? { height } : {}),
|
|
90
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
80
91
|
});
|
|
81
92
|
}
|
|
82
93
|
return attachments.length > 0 ? attachments : [];
|