// The media library's API (backend: local_backend/routers/media.py, plan steps 5.1 / 5.2). import client from '../../api/client' export const listMedia = ({ kind, q, collection, folder, limit = 500 } = {}) => client.get('/api/media', { params: { kind: kind || undefined, q: q || undefined, collection: collection || undefined, folder: folder || undefined, limit } }).then(r => r.data) export const getMedia = id => client.get(`/api/media/${id}`).then(r => r.data) /** Upload one file → the library item (`existing: true` when the same file was already there). */ export function uploadMedia(file, { name, folderId, onProgress } = {}) { const fd = new FormData() fd.append('file', file) if (name) fd.append('name', name) if (folderId) fd.append('folder_id', String(folderId)) return client.post('/api/media', fd, { onUploadProgress: e => { if (onProgress && e.total) onProgress(Math.round((e.loaded / e.total) * 100)) }, }).then(r => r.data) } export const renameMedia = (id, name) => client.patch(`/api/media/${id}`, { name }).then(r => r.data) export const deleteMedia = id => client.delete(`/api/media/${id}`) // folders (6R.16): only a grouping in the database; the files stay where they are export const listFolders = () => client.get('/api/media/folders').then(r => r.data) export const createFolder = name => client.post('/api/media/folders', { name }).then(r => r.data) export const renameFolder = (id, name) => client.patch(`/api/media/folders/${id}`, { name }).then(r => r.data) export const deleteFolder = id => client.delete(`/api/media/folders/${id}`) export const moveMedia = (ids, folderId) => client.post('/api/media/move', { ids, folder_id: folderId ?? null }).then(r => r.data) export const setFolder = (id, folderId) => client.patch(`/api/media/${id}`, { folder_id: folderId ?? null }).then(r => r.data)