chore: initial commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type {Socket} from 'socket.io-client';
|
||||
import {get_workflow_catalog} from '../../../bot/workflow/catalog.ts';
|
||||
import {console_print} from '../../../utils/console_print.ts';
|
||||
|
||||
export async function update_workflow_catalog(
|
||||
socket: Socket,
|
||||
node_id: number,
|
||||
is_current: () => boolean = () => socket.connected,
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (!socket.connected || !is_current()) return;
|
||||
const workflow_catalog = get_workflow_catalog();
|
||||
if (!socket.connected || !is_current()) return;
|
||||
const response = await socket.timeout(5000).emitWithAck('update_workflow_catalog', {
|
||||
id: node_id,
|
||||
workflow_catalog,
|
||||
});
|
||||
if (!socket.connected || !is_current()) return;
|
||||
if (!response || (response.status !== 'success' && response.status !== 'error')) {
|
||||
throw new Error('Invalid workflow catalog acknowledgement');
|
||||
}
|
||||
if (response.status === 'error') throw new Error('Workflow catalog report was rejected');
|
||||
console_print.log(console_print.success('工作流目录更新成功'));
|
||||
} catch {
|
||||
if (!socket.connected || !is_current()) return;
|
||||
throw new Error('Workflow catalog report failed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user