feat: init
This commit is contained in:
parent
8acd8f6fbd
commit
97d3a6277d
77 changed files with 5299 additions and 0 deletions
20
app/api/utils/common.ts
Normal file
20
app/api/utils/common.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import { type NextRequest } from 'next/server'
|
||||
import { APP_ID, API_KEY } from '@/config'
|
||||
import { ChatClient } from '../sdk'
|
||||
const userPrefix = `user_${APP_ID}:`;
|
||||
const uuid = require('uuid')
|
||||
|
||||
export const getInfo = (request: NextRequest) => {
|
||||
const sessionId = request.cookies.get('session_id')?.value || uuid.v4();
|
||||
const user = userPrefix + sessionId;
|
||||
return {
|
||||
sessionId,
|
||||
user
|
||||
}
|
||||
}
|
||||
|
||||
export const setSession = (sessionId: string) => {
|
||||
return { 'Set-Cookie': `session_id=${sessionId}` }
|
||||
}
|
||||
|
||||
export const client = new ChatClient(API_KEY)
|
||||
Loading…
Add table
Add a link
Reference in a new issue