fix: parse file list API response format correctly

API returns {"files": [{"name": "...", "data_type": "..."}]}, not a
plain array. Extract file names from the nested structure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 11:26:39 +01:00
parent 3b11a4e974
commit a37dd82ae3
+4 -4
View File
@@ -40,17 +40,17 @@ app.registerExtension({
);
if (!resp.ok) return;
const data = await resp.json();
if (!Array.isArray(data)) return;
const fileList = (data.files || []).map(f => f.name || f);
console.log(`[ProjectSource] refreshFiles: got ${fileList.length} files:`, fileList);
const fileW = node.widgets?.find(w => w.name === "file_name");
if (fileW) {
const currentValue = fileW.value;
fileW.options.values = data.length > 0 ? data : [""];
fileW.options.values = fileList.length > 0 ? fileList : [""];
// Keep current selection if still valid
if (currentValue && data.includes(currentValue)) {
if (currentValue && fileList.includes(currentValue)) {
fileW.value = currentValue;
}
console.log(`[ProjectSource] refreshFiles: ${data.length} files loaded`);
}
} catch (e) {
console.error("[ProjectSource] Failed to refresh files:", e);