mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-29 17:55:24 +00:00

* fix plus request (#4476) * perf: package plus request * perf: plus request fix * fix: doc --------- Co-authored-by: heheer <heheer@sealos.io>
38 lines
1014 B
TypeScript
38 lines
1014 B
TypeScript
import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
|
|
import { updateApiKeyUsedTime } from './tools';
|
|
import { MongoOpenApi } from './schema';
|
|
import type { OpenApiSchema } from '@fastgpt/global/support/openapi/type';
|
|
|
|
export type AuthOpenApiLimitProps = { openApi: OpenApiSchema };
|
|
|
|
export async function authOpenApiKey({ apikey }: { apikey: string }) {
|
|
if (!apikey) {
|
|
return Promise.reject(ERROR_ENUM.unAuthApiKey);
|
|
}
|
|
try {
|
|
const openApi = await MongoOpenApi.findOne({ apiKey: apikey.trim() }).lean();
|
|
if (!openApi) {
|
|
return Promise.reject(ERROR_ENUM.unAuthApiKey);
|
|
}
|
|
|
|
// auth limit
|
|
if (global.feConfigs?.isPlus) {
|
|
await global.authOpenApiHandler({
|
|
openApi
|
|
});
|
|
}
|
|
|
|
updateApiKeyUsedTime(openApi._id);
|
|
|
|
return {
|
|
apikey,
|
|
teamId: String(openApi.teamId),
|
|
tmbId: String(openApi.tmbId),
|
|
appId: openApi.appId || '',
|
|
sourceName: openApi.name
|
|
};
|
|
} catch (error) {
|
|
return Promise.reject(error);
|
|
}
|
|
}
|