This commit is contained in:
archer
2023-07-11 15:57:01 +08:00
parent cd77d81135
commit eb768d9c04
47 changed files with 1949 additions and 1280 deletions

View File

@@ -3,33 +3,36 @@ import { jsonRes } from '@/service/response';
import { connectToDatabase, ShareChat } from '@/service/mongo';
import { authApp, authUser } from '@/service/utils/auth';
import type { ShareChatEditType } from '@/types/app';
import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);
/* create a shareChat */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { modelId, name, maxContext, password } = req.body as ShareChatEditType & {
modelId: string;
const { appId, name, maxContext } = req.body as ShareChatEditType & {
appId: string;
};
await connectToDatabase();
const { userId } = await authUser({ req, authToken: true });
await authApp({
appId: modelId,
appId,
userId,
authOwner: false
});
const { _id } = await ShareChat.create({
const shareId = nanoid();
await ShareChat.create({
shareId,
userId,
modelId,
appId,
name,
password,
maxContext
});
jsonRes(res, {
data: _id
data: shareId
});
} catch (err) {
jsonRes(res, {