feat(usage): add test script API with refactored execution logic
- Add private helper method `execute_and_format_usage_result` to eliminate code duplication - Refactor `query_usage` to use helper method instead of duplicating result processing - Add new `test_usage_script` method to test temporary script without saving - Add backend command `test_usage_script` accepting script content as parameter - Register new command in lib.rs invoke_handler - Add frontend `usageApi.testScript` method to call the new backend API - Update `UsageScriptModal.handleTest` to test current editor content instead of saved script - Improve DX: users can now test script changes before saving
This commit is contained in:
@@ -144,7 +144,15 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
||||
const handleTest = async () => {
|
||||
setTesting(true);
|
||||
try {
|
||||
const result = await usageApi.query(provider.id, appId);
|
||||
// 使用当前编辑器中的脚本内容进行测试
|
||||
const result = await usageApi.testScript(
|
||||
provider.id,
|
||||
appId,
|
||||
script.code,
|
||||
script.timeout,
|
||||
script.accessToken,
|
||||
script.userId
|
||||
);
|
||||
if (result.success && result.data && result.data.length > 0) {
|
||||
// 显示所有套餐数据
|
||||
const summary = result.data
|
||||
|
||||
Reference in New Issue
Block a user