Skip to content

Commit

Permalink
🔥 chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Aug 18, 2023
1 parent 20ebfa4 commit b54b96f
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions api/v1/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,17 @@ export default async (req: Request) => {

if (!item) return;

// 兼容 V0 版本的代码
if ((manifest.version as number) === 0) {
// 先通过插件资产 endpoint 路径查询
const res = await fetch((item as any).runtime.endpoint, { body: args, method: 'post' });
const data = await res.text();
console.log(`[${name}]`, args, `result:`, data.slice(0, 3600));
return new Response(data);
}
if (!item.manifest) return;

// 新版 V1 的代码
else if (manifest.version === 1) {
// 先通过插件资产 endpoint 路径查询
// 获取插件的 manifest
const pluginRes = await fetch(item.manifest);
const chatPlugin = (await pluginRes.json()) as LobeChatPlugin;

if (!item.manifest) return;
const response = await fetch(chatPlugin.server.url, { body: args, method: 'post' });

// 获取插件的 manifest
const pluginRes = await fetch(item.manifest);
const chatPlugin = (await pluginRes.json()) as LobeChatPlugin;
const data = await response.text();

const response = await fetch(chatPlugin.server.url, { body: args, method: 'post' });
console.log(`[${name}]`, args, `result:`, data.slice(0, 3600));

const data = await response.text();

console.log(`[${name}]`, args, `result:`, data.slice(0, 3600));

return new Response(data);
}

return;
return new Response(data);
};

0 comments on commit b54b96f

Please sign in to comment.