mirror of
https://github.com/langgenius/webapp-conversation.git
synced 2025-12-08 17:32:27 +08:00
25 lines
714 B
TypeScript
25 lines
714 B
TypeScript
import type { NextRequest } from 'next/server'
|
|
import { ChatClient } from 'dify-client'
|
|
import { v4 } from 'uuid'
|
|
import { API_KEY, API_URL, APP_ID, APP_INFO } from '@/config'
|
|
|
|
const userPrefix = `user_${APP_ID}:`
|
|
|
|
export const getInfo = (request: NextRequest) => {
|
|
const sessionId = request.cookies.get('session_id')?.value || v4()
|
|
const user = userPrefix + sessionId
|
|
return {
|
|
sessionId,
|
|
user,
|
|
}
|
|
}
|
|
|
|
export const setSession = (sessionId: string) => {
|
|
if (APP_INFO.disable_session_same_site)
|
|
{ return { 'Set-Cookie': `session_id=${sessionId}; SameSite=None; Secure` } }
|
|
|
|
return { 'Set-Cookie': `session_id=${sessionId}` }
|
|
}
|
|
|
|
export const client = new ChatClient(API_KEY, API_URL || undefined)
|