feat: 新增脚本录制功能
This commit is contained in:
37
electron/service/script-execution-service/index.ts
Normal file
37
electron/service/script-execution-service/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { executeScriptService } from '@electron/service/execute-script-service';
|
||||
import {
|
||||
getScriptPathById,
|
||||
updateLastRun,
|
||||
} from '@electron/service/script-store-service';
|
||||
import type { ScriptExecutionResult } from '@lib/script-types';
|
||||
|
||||
const executor = new executeScriptService();
|
||||
|
||||
export async function runScriptById(
|
||||
id: string,
|
||||
channel?: string,
|
||||
): Promise<ScriptExecutionResult> {
|
||||
const scriptPath = getScriptPathById(id);
|
||||
if (!scriptPath) {
|
||||
return {
|
||||
success: false,
|
||||
exitCode: null,
|
||||
stdoutTail: '',
|
||||
stderrTail: '',
|
||||
error: 'Script not found',
|
||||
};
|
||||
}
|
||||
|
||||
const result = await executor.executeScript(scriptPath, {
|
||||
SCRIPT_ID: id,
|
||||
CHANNEL: channel || '',
|
||||
});
|
||||
|
||||
updateLastRun(id, {
|
||||
time: new Date().toISOString(),
|
||||
success: result.success,
|
||||
error: result.error,
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user