u
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user