u
This commit is contained in:
@@ -1944,6 +1944,85 @@ export const modelconversation = {
|
||||
},
|
||||
};
|
||||
|
||||
export const vfs = {
|
||||
/**
|
||||
* GET /api/vfs
|
||||
* List files in the virtual filesystem for the selected company.
|
||||
* → 200 { files: [{ name, size, mime, updated_at, created_at, isText, isImage, isPdf }] }
|
||||
*/
|
||||
list() {
|
||||
return http('/api/vfs');
|
||||
},
|
||||
|
||||
/**
|
||||
* GET /api/vfs/*path
|
||||
* Fetch raw content of a file (e.g. text for the editor).
|
||||
* @param {string} path
|
||||
*/
|
||||
async getText(path) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
const res = await fetch(`/api/vfs/${clean}?raw=1`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`Datei konnte nicht geladen werden (${res.status} ${res.statusText})`);
|
||||
}
|
||||
return res.text();
|
||||
},
|
||||
|
||||
/**
|
||||
* PUT /api/vfs/*path
|
||||
* Create or update a file.
|
||||
* @param {string} path
|
||||
* @param {string} content
|
||||
* @param {string} [mime]
|
||||
*/
|
||||
save(path, content, mime) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
return http(`/api/vfs/${clean}`, {
|
||||
method: 'PUT',
|
||||
body: { content, mime },
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* DELETE /api/vfs/*path
|
||||
* Delete a file.
|
||||
* @param {string} path
|
||||
*/
|
||||
delete(path) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
return http(`/api/vfs/${clean}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/vfs/upload
|
||||
* Upload multiple files or a single file to VFS.
|
||||
* @param {File[]|FileList|File} files
|
||||
* @param {string} [targetDir]
|
||||
*/
|
||||
async upload(files, targetDir = '') {
|
||||
const formData = new FormData();
|
||||
if (targetDir) formData.append('targetDir', targetDir);
|
||||
const list = Array.isArray(files) ? files : files instanceof FileList ? Array.from(files) : [files];
|
||||
for (const f of list) {
|
||||
formData.append('files', f);
|
||||
}
|
||||
const res = await fetch('/api/vfs/upload', {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: formData,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({}));
|
||||
throw new Error(err.error || `Upload fehlgeschlagen (${res.status})`);
|
||||
}
|
||||
return res.json();
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
auth,
|
||||
article,
|
||||
@@ -1968,8 +2047,10 @@ export default {
|
||||
supplier,
|
||||
thumb,
|
||||
unit,
|
||||
vfs,
|
||||
warehouse,
|
||||
stock,
|
||||
globalHistory,
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user