Compare commits

...

5 Commits

Author SHA1 Message Date
Bentlybro
ac826df61b revert: remove screenshots from repo 2026-02-03 12:25:26 +00:00
Bentlybro
a9d12594c2 docs: add PR testing screenshots 2026-02-03 12:22:11 +00:00
Bentlybro
a967b0dc63 style: format 2026-02-03 11:57:07 +00:00
Bentlybro
e5420f8bd9 fix: add proper type guard for obj.type 2026-02-03 11:50:06 +00:00
Bentlybro
638e150a12 fix(frontend): Handle object values in FileInput component
Fixes #11800

The FileInput component crashed with 'TypeError: e.startsWith is not a function'
when the value was an object (from external API) instead of a string.

Changes:
- Updated getFileLabelFromValue() to handle object format: { name, type, size, data }
- Added type guards for string vs object values
- Graceful fallback for edge cases (null, undefined, empty object)

Test cases verified:
- Object with name: returns filename
- Object with type only: extracts and formats MIME type
- String data URI: parses correctly
- String file path: extracts extension
- Edge cases: returns 'File' fallback
2026-02-03 11:44:21 +00:00

View File

@@ -104,7 +104,31 @@ export function FileInput(props: Props) {
return false; return false;
} }
const getFileLabelFromValue = (val: string) => { const getFileLabelFromValue = (val: unknown): string => {
// Handle object format from external API: { name, type, size, data }
if (val && typeof val === "object") {
const obj = val as Record<string, unknown>;
if (typeof obj.name === "string") {
return getFileLabel(
obj.name,
typeof obj.type === "string" ? obj.type : "",
);
}
if (typeof obj.type === "string") {
const mimeParts = obj.type.split("/");
if (mimeParts.length > 1) {
return `${mimeParts[1].toUpperCase()} file`;
}
return `${obj.type} file`;
}
return "File";
}
// Handle string values (data URIs or file paths)
if (typeof val !== "string") {
return "File";
}
if (val.startsWith("data:")) { if (val.startsWith("data:")) {
const matches = val.match(/^data:([^;]+);/); const matches = val.match(/^data:([^;]+);/);
if (matches?.[1]) { if (matches?.[1]) {