This commit is contained in:
seb
2026-10-16 13:59:02 +02:00
parent e083d66a75
commit bed19f8b10
7 changed files with 313 additions and 6 deletions

View File

@@ -2,7 +2,14 @@ import fs from 'fs';
import path from 'path';
import multer from 'multer';
import { emit } from '../sse.js';
import { prepareVfs, resolveVfsRoot, isReadOnlyDatabasePath, getMimeType } from '../../tools/vfs.js';
import {
prepareVfs,
resolveVfsRoot,
isReadOnlyDatabasePath,
getMimeType,
restoreDefaultSkills,
restoreDefaultApplets,
} from '../../tools/vfs.js';
import sharp from 'sharp';
import {
parseDraftPath,
@@ -1464,4 +1471,162 @@ export function register(app, basePath = '') {
});
// #endregion
/**
* @openapi
* /vfs/skills/restore:
* post:
* tags: [Vfs]
* summary: Restore system default skills
* description: |
* Restores all shipped system default SKILL files into the active virtual filesystem (VFS)
* for the authenticated user's selected company, overwriting existing system skills with their upstream definitions.
* security:
* - cookieAuth: []
* x-signals: [vfs]
* x-markdown: vfs/skills-restore.md
* responses:
* 200:
* description: System skills restored successfully
* content:
* application/json:
* schema:
* type: object
* required: [success, restored, count]
* properties:
* success:
* type: boolean
* restored:
* type: array
* items:
* type: string
* count:
* type: integer
* 400:
* description: No company selected
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 401:
* description: Unauthorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 403:
* description: Not authorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Restore failed
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /vfs/skills/restore
app.post(`${basePath}/vfs/skills/restore`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
return res.status(400).json({ error: selected.error });
}
try {
const restored = await restoreDefaultSkills({ googleAuthId: req.user.id });
emit('vfs', { companyId: selected.companyId });
return res.json({
success: true,
restored,
count: restored.length,
});
} catch (error) {
const status = vfsFileErrorStatus(error);
if (status === 500) console.error('Restore default skills failed:', error);
return res.status(status).json({ error: error.message });
}
});
// #endregion
/**
* @openapi
* /vfs/applets/restore:
* post:
* tags: [Vfs]
* summary: Restore system default applets
* description: |
* Restores all shipped system default example applets (.applet.js) into the active virtual
* filesystem (VFS) for the authenticated user's selected company, overwriting existing system applets with their upstream definitions.
* security:
* - cookieAuth: []
* x-signals: [vfs]
* x-markdown: vfs/applets-restore.md
* responses:
* 200:
* description: System applets restored successfully
* content:
* application/json:
* schema:
* type: object
* required: [success, restored, count]
* properties:
* success:
* type: boolean
* restored:
* type: array
* items:
* type: string
* count:
* type: integer
* 400:
* description: No company selected
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 401:
* description: Unauthorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 403:
* description: Not authorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Restore failed
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /vfs/applets/restore
app.post(`${basePath}/vfs/applets/restore`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
return res.status(400).json({ error: selected.error });
}
try {
const restored = await restoreDefaultApplets({ googleAuthId: req.user.id });
emit('vfs', { companyId: selected.companyId });
return res.json({
success: true,
restored,
count: restored.length,
});
} catch (error) {
const status = vfsFileErrorStatus(error);
if (status === 500) console.error('Restore default applets failed:', error);
return res.status(status).json({ error: error.message });
}
});
// #endregion
}

View File

@@ -10,7 +10,7 @@ import { parseVfsRef, vfsFileErrorStatus } from './vfs.js';
// VFS paths that are owned by their own literal route in `vfs.js`. They are registered as
// separate Express handlers, so this wildcard must defer to them instead of treating e.g.
// `/vfs/upload` as an applet path. Deferring keeps the two files order-independent.
const RESERVED_VFS_SEGMENTS = new Set(['upload', 'mkdir', 'rename']);
const RESERVED_VFS_SEGMENTS = new Set(['upload', 'mkdir', 'rename', 'drafts', 'skills', 'applets']);
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;