u
This commit is contained in:
@@ -6,15 +6,18 @@ export const vfs = {
|
||||
* List files in the virtual filesystem for the selected company.
|
||||
* → 200 { files: [{ name, size, mime, updated_at, created_at, isText, isImage, isPdf }] }
|
||||
*/
|
||||
// #region GET /api/vfs — list
|
||||
list() {
|
||||
return http('/api/vfs');
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* GET /api/vfs/*path
|
||||
* Fetch raw content of a file (e.g. text for the editor).
|
||||
* @param {string} path
|
||||
*/
|
||||
// #region GET /api/vfs/*path — getText
|
||||
async getText(path) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
const res = await fetch(`/api/vfs/${clean}?raw=1`, {
|
||||
@@ -25,6 +28,7 @@ export const vfs = {
|
||||
}
|
||||
return res.text();
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PUT /api/vfs/*path
|
||||
@@ -33,6 +37,7 @@ export const vfs = {
|
||||
* @param {string} content
|
||||
* @param {string} [mime]
|
||||
*/
|
||||
// #region PUT /api/vfs/*path — save
|
||||
save(path, content, mime) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
return http(`/api/vfs/${clean}`, {
|
||||
@@ -40,18 +45,21 @@ export const vfs = {
|
||||
body: { content, mime },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* DELETE /api/vfs/*path
|
||||
* Delete a file.
|
||||
* @param {string} path
|
||||
*/
|
||||
// #region DELETE /api/vfs/*path — delete
|
||||
delete(path) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
return http(`/api/vfs/${clean}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/vfs/upload
|
||||
@@ -59,6 +67,7 @@ export const vfs = {
|
||||
* @param {File[]|FileList|File} files
|
||||
* @param {string} [targetDir]
|
||||
*/
|
||||
// #region POST /api/vfs/upload — upload
|
||||
async upload(files, targetDir = '') {
|
||||
const formData = new FormData();
|
||||
if (targetDir) formData.append('targetDir', targetDir);
|
||||
@@ -78,12 +87,14 @@ export const vfs = {
|
||||
}
|
||||
return res.json();
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/vfs/mkdir
|
||||
* Create a directory in VFS.
|
||||
* @param {string} path
|
||||
*/
|
||||
// #region POST /api/vfs/mkdir — mkdir
|
||||
mkdir(path) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
return http('/api/vfs/mkdir', {
|
||||
@@ -91,6 +102,7 @@ export const vfs = {
|
||||
body: { path: clean },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/vfs/rename
|
||||
@@ -98,6 +110,7 @@ export const vfs = {
|
||||
* @param {string} oldPath
|
||||
* @param {string} newPath
|
||||
*/
|
||||
// #region POST /api/vfs/rename — rename
|
||||
rename(oldPath, newPath) {
|
||||
const cleanOld = String(oldPath || '').replace(/^\/+/, '');
|
||||
const cleanNew = String(newPath || '').replace(/^\/+/, '');
|
||||
@@ -106,6 +119,7 @@ export const vfs = {
|
||||
body: { oldPath: cleanOld, newPath: cleanNew },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/vfs/*path — run a `.applet.js` file from VFS.
|
||||
@@ -116,6 +130,7 @@ export const vfs = {
|
||||
* `result` is a typed CSV string (`;`-separated, header row first), `columns` are the
|
||||
* declared `{ name, type }` pairs, `rows` is the data-row count.
|
||||
*/
|
||||
// #region POST /api/vfs/*path — runApplet
|
||||
runApplet(path, options = {}) {
|
||||
const clean = String(path || '').replace(/^\/+/, '');
|
||||
const body = {};
|
||||
@@ -127,4 +142,5 @@ export const vfs = {
|
||||
body,
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user