mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-11 04:03:16 +08:00
feat: support per-bot workspace switching
This commit is contained in:
parent
adcace3512
commit
44dd50216a
64 changed files with 3878 additions and 712 deletions
25
plugin-src/host/channels/shared/workspace-rpc.mjs
Normal file
25
plugin-src/host/channels/shared/workspace-rpc.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { isAbsolute } from 'node:path';
|
||||
|
||||
export const SET_WORKSPACE_ENDPOINT = 'bot.workspace.set';
|
||||
|
||||
export function validWorkspacePayload(payload) {
|
||||
return payload !== null
|
||||
&& typeof payload === 'object'
|
||||
&& !Array.isArray(payload)
|
||||
&& Object.keys(payload).every((key) => ['botId', 'workspace'].includes(key))
|
||||
&& typeof payload.botId === 'string'
|
||||
&& /^[A-Za-z0-9_-]{1,128}$/.test(payload.botId)
|
||||
&& typeof payload.workspace === 'string'
|
||||
&& payload.workspace.length <= 4_096
|
||||
&& isAbsolute(payload.workspace.trim());
|
||||
}
|
||||
|
||||
export function publicWorkspaceError(error) {
|
||||
if (![
|
||||
'workspace-not-absolute',
|
||||
'workspace-not-found',
|
||||
'workspace-not-directory',
|
||||
'workspace-bot-not-found',
|
||||
].includes(error?.code)) return null;
|
||||
return { code: error.code, message: error.message };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue