mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix: tighten type safety on file object fields
Use explicit typeof checks for path, name, and mime_type instead of relying on truthiness, which could produce unexpected output for non-string values.
This commit is contained in:
@@ -543,10 +543,19 @@ function getFileAccordionData(
|
||||
if (typeof f === "object" && f !== null) {
|
||||
const fileObj = f as Record<string, unknown>;
|
||||
// Workspace file format: path (size, mime_type)
|
||||
const filePath = fileObj.path || fileObj.name || "unknown";
|
||||
const filePath =
|
||||
typeof fileObj.path === "string"
|
||||
? fileObj.path
|
||||
: typeof fileObj.name === "string"
|
||||
? fileObj.name
|
||||
: "unknown";
|
||||
const mimeType =
|
||||
typeof fileObj.mime_type === "string"
|
||||
? fileObj.mime_type
|
||||
: "unknown";
|
||||
const size =
|
||||
typeof fileObj.size_bytes === "number"
|
||||
? ` (${(fileObj.size_bytes / 1024).toFixed(1)} KB, ${fileObj.mime_type || "unknown"})`
|
||||
? ` (${(fileObj.size_bytes / 1024).toFixed(1)} KB, ${mimeType})`
|
||||
: "";
|
||||
return `${filePath}${size}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user