generated from lobehub/chat-plugin-realtime-weather
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: 移除默认的 api key 配置,添加服务端校验逻辑
- Loading branch information
Showing
6 changed files
with
41 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface Settings { | ||
SERPAPI_API_KEY?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import { | ||
PluginErrorType, | ||
createErrorResponse, | ||
getPluginSettingsStringFromRequest, | ||
} from '@lobehub/chat-plugin-sdk'; | ||
|
||
import { Settings } from './_types'; | ||
import runner from './_utils'; | ||
|
||
export const config = { | ||
runtime: 'edge', | ||
}; | ||
|
||
export default async (req: Request) => { | ||
if (req.method !== 'POST') return new Response('Method Not Allowed', { status: 405 }); | ||
if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed); | ||
|
||
const settings = getPluginSettingsStringFromRequest<Settings>(req); | ||
|
||
if (!settings) | ||
return createErrorResponse(PluginErrorType.PluginSettingsInvalid, { | ||
message: 'Plugin settings not found.', | ||
}); | ||
|
||
const args = await req.json(); | ||
try { | ||
const args = await req.json(); | ||
|
||
const result = await runner(args); | ||
const result = await runner(args, settings); | ||
|
||
return new Response(JSON.stringify(result)); | ||
return new Response(JSON.stringify(result)); | ||
} catch (error) { | ||
return createErrorResponse(PluginErrorType.PluginServerError, error as object); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters