feat(trash): move trash API to normalized version (with cursor, orderBy) + normalize Trash section to existing components

normalize also component to format badges (expiry, role, etc)
This commit is contained in:
Edouard Vanbelle
2026-05-30 00:15:07 +02:00
parent 6dab878919
commit ea83891a61
34 changed files with 2043 additions and 418 deletions
+59
View File
@@ -0,0 +1,59 @@
// @ts-check
/**
* OxiCloud – Trash resources model.
*
* Thin fetch wrapper for `GET /api/trash/resources` (cursor-paginated).
* The legacy `GET /api/trash` endpoint is deprecated server-side and is no
* longer called from the UI.
*/
/** @import {FileItem, FolderItem, ResourceTypeEnum} from '../core/types.js' */
/**
* @typedef {Object} TrashResourceItem
* @property {ResourceTypeEnum} resource_type - 'file' | 'folder'
* @property {string} trashed_at - ISO-8601: when the item was sent to trash
* @property {string} deletion_date - ISO-8601: when retention will purge it
* @property {FileItem|FolderItem} resource - Full resource details (resource.path = original location)
*/
/**
* @typedef {Object} TrashResourcesResponse
* @property {TrashResourceItem[]} items
* @property {string|undefined} [next_cursor]
*/
/**
* Fetch one page of the current user's trashed resources.
*
* @param {{
* cursor?: string,
* orderBy?: string,
* limit?: number,
* reverse?: boolean,
* resourceTypes?: ResourceTypeEnum[],
* }} [opts]
* @returns {Promise<TrashResourcesResponse>}
*/
async function fetchTrashPage({ cursor, orderBy = 'deletion_date', limit = 50, reverse = false, resourceTypes } = {}) {
const params = new URLSearchParams({ order_by: orderBy, limit: String(limit) });
if (cursor) params.set('cursor', cursor);
if (reverse) params.set('reverse', 'true');
if (resourceTypes?.length) params.set('resource_types', resourceTypes.join(','));
const res = await fetch(`/api/trash/resources?${params}`, {
credentials: 'same-origin',
cache: 'no-store'
});
if (!res.ok) {
const err = /** @type {any} */ (new Error(`GET /api/trash/resources failed: ${res.status}`));
err.status = res.status;
throw err;
}
return /** @type {Promise<TrashResourcesResponse>} */ (res.json());
}
export { fetchTrashPage };