fix: prevent crashes while formatting unexpected value types

refactor/sveltekit
Tomáš Mládek 2023-12-28 21:11:27 +01:00
parent e2dcb07ec9
commit 5c47e087e6
1 changed files with 18 additions and 15 deletions

View File

@ -216,22 +216,25 @@
};
function formatValue(value: string | number, attribute: string): string {
switch (attribute) {
case "FILE_SIZE":
return filesize(parseInt(String(value), 10), { base: 2 });
case ATTR_ADDED:
case "LAST_VISITED":
return formatRelative(
fromUnixTime(parseInt(String(value), 10)),
new Date(),
);
case "NUM_VISITED":
return `${value} times`;
case "MEDIA_DURATION":
return formatDuration(parseInt(String(value), 10));
default:
return String(value);
try {
switch (attribute) {
case "FILE_SIZE":
return filesize(parseInt(String(value), 10), { base: 2 });
case ATTR_ADDED:
case "LAST_VISITED":
return formatRelative(
fromUnixTime(parseInt(String(value), 10)),
new Date(),
);
case "NUM_VISITED":
return `${value} times`;
case "MEDIA_DURATION":
return formatDuration(parseInt(String(value), 10));
}
} catch {
// noop.
}
return String(value);
}
// Unused attributes