Files
FastGPT/projects/app/src/pages/api/support/outLink/create.ts
Finley Ge a478621730 refactor openapikey and outlink apis (#2134)
* refactor: OpenAPIKey refactor

* refactor: outlink api refactor

fix: list return wrong data

* chore: remove deprecated type definition

* chore: remove throw Error. instead of Promise.reject

* fix: auth openapikey's owner

* fix: manager could read all keys
2024-07-24 11:11:36 +08:00

46 lines
1.3 KiB
TypeScript

import { MongoOutLink } from '@fastgpt/service/support/outLink/schema';
import { authApp } from '@fastgpt/service/support/permission/app/auth';
import type { OutLinkEditType } from '@fastgpt/global/support/outLink/type.d';
import { customAlphabet } from 'nanoid';
import { PublishChannelEnum } from '@fastgpt/global/support/outLink/constant';
import { ManagePermissionVal } from '@fastgpt/global/support/permission/constant';
import type { ApiRequestProps } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry';
/* create a shareChat */
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);
export type OutLinkCreateQuery = {};
export type OutLinkCreateBody = OutLinkEditType &
OutLinkEditType & {
appId: string;
type: PublishChannelEnum;
};
export type OutLinkCreateResponse = string;
async function handler(
req: ApiRequestProps<OutLinkCreateBody, OutLinkCreateQuery>
): Promise<OutLinkCreateResponse> {
const { appId, ...props } = req.body;
const { teamId, tmbId } = await authApp({
req,
authToken: true,
appId,
per: ManagePermissionVal
});
const shareId = nanoid();
await MongoOutLink.create({
shareId,
teamId,
tmbId,
appId,
...props
});
return shareId;
}
export default NextAPI(handler);