From 82561a2b90c3bd479f4e4bb3e415ff8aef596526 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Mon, 18 May 2026 23:06:50 +0200 Subject: [PATCH] fix(ui): add RecentItem type + ad protection while building items --- static/js/app/ui.js | 12 ++++++++++-- static/js/core/types.js | 20 +++++++++++++++++++- static/js/features/library/recent.js | 19 ++++++++++++------- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/static/js/app/ui.js b/static/js/app/ui.js index 3e472373..23feb81c 100644 --- a/static/js/app/ui.js +++ b/static/js/app/ui.js @@ -744,7 +744,11 @@ const ui = { const frag = document.createDocumentFragment(); for (const folder of folders) { - frag.appendChild(this._createFolderItem(folder)); + try { + frag.appendChild(this._createFolderItem(folder)); + } catch (e) { + console.warn(`Error building folder item `, folder, `reason: `, e); + } } target.appendChild(frag); }, @@ -759,7 +763,11 @@ const ui = { const frag = document.createDocumentFragment(); for (const file of files) { - frag.appendChild(this._createFileItem(file)); + try { + frag.appendChild(this._createFileItem(file)); + } catch (e) { + console.warn(`Error building file item `, file, `reason: `, e); + } } target.appendChild(frag); }, diff --git a/static/js/core/types.js b/static/js/core/types.js index c02fb4c8..a1670b80 100644 --- a/static/js/core/types.js +++ b/static/js/core/types.js @@ -14,7 +14,7 @@ //FIXME: rename into FolderItem /** * @typedef {Object} FolderItem - * @property {string} category + * @property {string} category (folder) * @property {number} created_at - timestamp * @property {string} icon_class * @property {string} icon_special_class @@ -105,6 +105,24 @@ * @property {String} size_formatted */ +/** + * @typedef {Object} RecentItem + * @property {string} id + * @property {string} user_id + * @property {string} item_id /// ID of the favorited item (file or folder) + * @property {ItemTypeEnum} item_type + * @property {number} accessed_at + * @property {string|null} item_name: null if folder + * @property {number|null} item_size null if folder + * @property {string|null} item_mime_type if file + * @property {string|null} parent_id + * @property {String} item_path Full human-readable path (e.g. "Documents/Work" for a folder, "Documents/Work/report.pdf" for a file) + * @property {String} icon_class + * @property {String} icon_special_class + * @property {String} category + * @property {String} size_formatted + */ + /** * @typedef {Object} TrashItem * @property {string} id diff --git a/static/js/features/library/recent.js b/static/js/features/library/recent.js index ccd207be..f6e21494 100644 --- a/static/js/features/library/recent.js +++ b/static/js/features/library/recent.js @@ -12,7 +12,7 @@ import { i18n } from '../../core/i18n.js'; import { multiSelect } from '../files/multiSelect.js'; import * as pathTooltip from '../pathTooltip.js'; -/** @import {FileItem, FolderItem, ItemTypeEnum} from '../../core/types.js' */ +/** @import {FileItem, FolderItem, ItemTypeEnum, RecentItem} from '../../core/types.js' */ const recent = { /** Maximum items to request from the server */ @@ -95,7 +95,7 @@ const recent = { throw new Error(`Server returned ${response.status}`); } - const recentItems = await response.json(); + const recentItems = /** @type {RecentItem[]} */ (await response.json()); ui.resetFilesList(); // ensure also list visible & error hidden const filesList = document.getElementById('files-list'); @@ -141,13 +141,18 @@ const recent = { modified_at: item.accessed_at, path: item.item_path || '', category: 'folder', - created_at: item.created_at, - icon_class: '', - icon_special_class: '', + created_at: item.accessed_at, //Wrong information + icon_class: item.icon_class, + icon_special_class: item.icon_special_class, owner_id: '', is_root: false }); } else { + if (item.item_mime_type === undefined || item.item_mime_type === null) { + // FIXME: this case should not be possible, is it an information badly cleaned up on server ? + console.warn('Broken information for RecentItem: ', item); + //continue; + } files.push({ id: item.item_id, name: item.item_name || item.item_id, @@ -161,8 +166,8 @@ const recent = { modified_at: item.accessed_at, path: item.item_path || '', owner_id: '', - created_at: item.created_at, - sort_date: item.created_at + created_at: item.accessed_at, //wrong information + sort_date: item.accessed_at }); } }