refactor: remove obsolete project mode
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `projects`
|
||||||
|
DROP COLUMN `mode`;
|
||||||
@@ -353,7 +353,6 @@ model Project {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String
|
name String
|
||||||
description String? @db.Text
|
description String? @db.Text
|
||||||
mode String @default("novel-promotion")
|
|
||||||
userId String
|
userId String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|||||||
@@ -347,7 +347,6 @@ model Project {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String
|
name String
|
||||||
description String?
|
description String?
|
||||||
mode String @default("novel-promotion")
|
|
||||||
userId String
|
userId String
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|||||||
@@ -155,10 +155,7 @@ export default function WorkspacePage() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(formData)
|
||||||
...formData,
|
|
||||||
mode: 'novel-promotion' // 固定为 novel-promotion
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export const POST = apiHandler(async (
|
|||||||
const { projectId } = await context.params
|
const { projectId } = await context.params
|
||||||
const authResult = await requireProjectAuth(projectId)
|
const authResult = await requireProjectAuth(projectId)
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
const body = await request.json().catch(() => ({}))
|
const body = await request.json().catch(() => ({}))
|
||||||
const currentPrompt = typeof body?.currentPrompt === 'string' ? body.currentPrompt.trim() : ''
|
const currentPrompt = typeof body?.currentPrompt === 'string' ? body.currentPrompt.trim() : ''
|
||||||
@@ -19,10 +19,6 @@ export const POST = apiHandler(async (
|
|||||||
if (!currentPrompt || !modifyInstruction) {
|
if (!currentPrompt || !modifyInstruction) {
|
||||||
throw new ApiError('INVALID_PARAMS')
|
throw new ApiError('INVALID_PARAMS')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const panelId = typeof body?.panelId === 'string' ? body.panelId.trim() : ''
|
const panelId = typeof body?.panelId === 'string' ? body.panelId.trim() : ''
|
||||||
const episodeId = typeof body?.episodeId === 'string' ? body.episodeId.trim() : ''
|
const episodeId = typeof body?.episodeId === 'string' ? body.episodeId.trim() : ''
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,9 @@ export const POST = apiHandler(async (
|
|||||||
const { projectId } = await context.params
|
const { projectId } = await context.params
|
||||||
const authResult = await requireProjectAuth(projectId)
|
const authResult = await requireProjectAuth(projectId)
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
const body = await request.json().catch(() => ({}))
|
const body = await request.json().catch(() => ({}))
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
|
|||||||
@@ -16,11 +16,7 @@ export const POST = apiHandler(async (
|
|||||||
include: { characters: true, locations: true },
|
include: { characters: true, locations: true },
|
||||||
})
|
})
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -24,11 +24,7 @@ export const POST = apiHandler(async (
|
|||||||
include: { characters: true, locations: true },
|
include: { characters: true, locations: true },
|
||||||
})
|
})
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -14,11 +14,7 @@ export const POST = apiHandler(async (
|
|||||||
const { projectId } = await params
|
const { projectId } = await params
|
||||||
const authResult = await requireProjectAuthLight(projectId)
|
const authResult = await requireProjectAuthLight(projectId)
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await request.json().catch(() => ({}))
|
const body = await request.json().catch(() => ({}))
|
||||||
const content = typeof body?.content === 'string' ? body.content : ''
|
const content = typeof body?.content === 'string' ? body.content : ''
|
||||||
|
|||||||
@@ -276,10 +276,6 @@ export const PATCH = apiHandler(async (
|
|||||||
|
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentProjectConfig = await prisma.novelPromotionProject.findUnique({
|
const currentProjectConfig = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
select: {
|
select: {
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ export const POST = apiHandler(async (
|
|||||||
|
|
||||||
const authResult = await requireProjectAuth(projectId)
|
const authResult = await requireProjectAuth(projectId)
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ export const POST = apiHandler(async (
|
|||||||
include: { characters: true, locations: true },
|
include: { characters: true, locations: true },
|
||||||
})
|
})
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -26,11 +26,7 @@ export const POST = apiHandler(async (
|
|||||||
include: { characters: true, locations: true },
|
include: { characters: true, locations: true },
|
||||||
})
|
})
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ export const POST = apiHandler(async (
|
|||||||
|
|
||||||
const authResult = await requireProjectAuthLight(projectId)
|
const authResult = await requireProjectAuthLight(projectId)
|
||||||
if (isErrorResponse(authResult)) return authResult
|
if (isErrorResponse(authResult)) return authResult
|
||||||
const { session, project } = authResult
|
const { session } = authResult
|
||||||
|
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new ApiError('INVALID_PARAMS')
|
|
||||||
}
|
|
||||||
|
|
||||||
const asyncTaskResponse = await maybeSubmitLLMTask({
|
const asyncTaskResponse = await maybeSubmitLLMTask({
|
||||||
request,
|
request,
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ export const GET = apiHandler(async (
|
|||||||
data: { lastAccessedAt: new Date() }
|
data: { lastAccessedAt: new Date() }
|
||||||
}).catch(err => _ulogError('更新访问时间失败:', err))
|
}).catch(err => _ulogError('更新访问时间失败:', err))
|
||||||
|
|
||||||
// 这个API只返回基础项目信息
|
// 这个 API 只返回基础项目信息
|
||||||
// 模式特定的数据应该通过各自的API获取(如 /api/novel-promotion/[projectId])
|
// 项目附属业务数据通过各自的 API 获取(如 /api/novel-promotion/[projectId])
|
||||||
const projectWithSignedUrls = addSignedUrlsToProject(project)
|
const projectWithSignedUrls = addSignedUrlsToProject(project)
|
||||||
|
|
||||||
return NextResponse.json({ project: projectWithSignedUrls })
|
return NextResponse.json({ project: projectWithSignedUrls })
|
||||||
|
|||||||
@@ -188,12 +188,11 @@ export const POST = apiHandler(async (request: NextRequest) => {
|
|||||||
where: { userId: session.user.id }
|
where: { userId: session.user.id }
|
||||||
})
|
})
|
||||||
|
|
||||||
// 创建基础项目(mode 固定为 novel-promotion)
|
// 创建基础项目
|
||||||
const project = await prisma.project.create({
|
const project = await prisma.project.create({
|
||||||
data: {
|
data: {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
description: description?.trim() || null,
|
description: description?.trim() || null,
|
||||||
mode: 'novel-promotion',
|
|
||||||
userId: session.user.id
|
userId: session.user.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ export async function createHomeProjectLaunch({
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: projectName,
|
name: projectName,
|
||||||
description: storyText,
|
description: storyText,
|
||||||
mode: 'novel-promotion',
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
import { ProjectMode } from '@/types/project'
|
|
||||||
|
|
||||||
// 重新导出 ProjectMode 类型,方便其他文件使用
|
|
||||||
export type { ProjectMode }
|
|
||||||
|
|
||||||
export interface ModeConfig {
|
|
||||||
id: ProjectMode
|
|
||||||
name: string
|
|
||||||
description: string
|
|
||||||
icon: string
|
|
||||||
color: string
|
|
||||||
available: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PROJECT_MODE: ModeConfig = {
|
|
||||||
id: 'novel-promotion',
|
|
||||||
name: '小说推文',
|
|
||||||
description: '从小说生成推广短视频',
|
|
||||||
icon: 'N',
|
|
||||||
color: 'purple',
|
|
||||||
available: true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 为了兼容性保留
|
|
||||||
export const PROJECT_MODES: ModeConfig[] = [PROJECT_MODE]
|
|
||||||
|
|
||||||
export function getModeConfig(mode: ProjectMode): ModeConfig | undefined {
|
|
||||||
return mode === 'novel-promotion' ? PROJECT_MODE : undefined
|
|
||||||
}
|
|
||||||
@@ -30,15 +30,11 @@ export async function handleAnalyzeGlobalTask(job: Job<TaskJobData>) {
|
|||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelData = await prisma.novelPromotionProject.findUnique({
|
const novelData = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -49,15 +49,11 @@ export async function handleAnalyzeNovelTask(job: Job<TaskJobData>) {
|
|||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelData = await prisma.novelPromotionProject.findUnique({
|
const novelData = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -48,14 +48,11 @@ export async function handleClipsBuildTask(job: Job<TaskJobData>) {
|
|||||||
|
|
||||||
const project = await prisma.project.findUnique({
|
const project = await prisma.project.findUnique({
|
||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
select: { id: true, mode: true },
|
select: { id: true },
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelData = await prisma.novelPromotionProject.findUnique({
|
const novelData = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -67,15 +67,11 @@ export async function handleEpisodeSplitTask(job: Job<TaskJobData>) {
|
|||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelProject = await prisma.novelPromotionProject.findFirst({
|
const novelProject = await prisma.novelPromotionProject.findFirst({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -33,15 +33,11 @@ export async function handleScreenplayConvertTask(job: Job<TaskJobData>) {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelData = await prisma.novelPromotionProject.findUnique({
|
const novelData = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -82,15 +82,11 @@ export async function handleScriptToStoryboardTask(job: Job<TaskJobData>) {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register project name for per-project log file routing
|
// Register project name for per-project log file routing
|
||||||
onProjectNameAvailable(projectId, project.name)
|
onProjectNameAvailable(projectId, project.name)
|
||||||
|
|||||||
@@ -77,15 +77,11 @@ export async function handleStoryToScriptTask(job: Job<TaskJobData>) {
|
|||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register project name for per-project log file routing
|
// Register project name for per-project log file routing
|
||||||
onProjectNameAvailable(projectId, project.name)
|
onProjectNameAvailable(projectId, project.name)
|
||||||
|
|||||||
@@ -36,15 +36,11 @@ export async function handleVoiceAnalyzeTask(job: Job<TaskJobData>) {
|
|||||||
where: { id: projectId },
|
where: { id: projectId },
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
mode: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!project) {
|
if (!project) {
|
||||||
throw new Error('Project not found')
|
throw new Error('Project not found')
|
||||||
}
|
}
|
||||||
if (project.mode !== 'novel-promotion') {
|
|
||||||
throw new Error('Not a novel promotion project')
|
|
||||||
}
|
|
||||||
|
|
||||||
const novelPromotionData = await prisma.novelPromotionProject.findUnique({
|
const novelPromotionData = await prisma.novelPromotionProject.findUnique({
|
||||||
where: { projectId },
|
where: { projectId },
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import type { CapabilitySelections } from '@/lib/model-config-contract'
|
import type { CapabilitySelections } from '@/lib/model-config-contract'
|
||||||
|
|
||||||
// ============================================
|
|
||||||
// 项目模式类型
|
|
||||||
// ============================================
|
|
||||||
export type ProjectMode = 'novel-promotion'
|
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// 基础项目类型
|
// 基础项目类型
|
||||||
// ============================================
|
// ============================================
|
||||||
@@ -12,7 +7,6 @@ export interface BaseProject {
|
|||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
description: string | null
|
description: string | null
|
||||||
mode: ProjectMode
|
|
||||||
userId: string
|
userId: string
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export function installAuthMocks() {
|
|||||||
if (state.projectAuthMode === 'not_found') return notFoundResponse()
|
if (state.projectAuthMode === 'not_found') return notFoundResponse()
|
||||||
return {
|
return {
|
||||||
session: state.session,
|
session: state.session,
|
||||||
project: { id: projectId, userId: state.session.user.id, name: 'project', mode: 'novel-promotion' },
|
project: { id: projectId, userId: state.session.user.id, name: 'project' },
|
||||||
novelData: { id: 'novel-data-id' },
|
novelData: { id: 'novel-data-id' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ export async function createFixtureUser() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createFixtureProject(userId: string, mode: 'novel-promotion' | 'general' = 'novel-promotion') {
|
export async function createFixtureProject(userId: string) {
|
||||||
const id = suffix()
|
const id = suffix()
|
||||||
return await prisma.project.create({
|
return await prisma.project.create({
|
||||||
data: {
|
data: {
|
||||||
userId,
|
userId,
|
||||||
mode,
|
|
||||||
name: `project_${id}`,
|
name: `project_${id}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ vi.mock('@/lib/api-auth', () => {
|
|||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: 'novel-promotion' },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
requireProjectAuthLight: async (projectId: string) => {
|
requireProjectAuthLight: async (projectId: string) => {
|
||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: 'novel-promotion' },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { buildMockRequest } from '../../../helpers/request'
|
|||||||
|
|
||||||
type AuthState = {
|
type AuthState = {
|
||||||
authenticated: boolean
|
authenticated: boolean
|
||||||
projectMode: 'novel-promotion' | 'other'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubmitResult = {
|
type SubmitResult = {
|
||||||
@@ -28,7 +27,6 @@ type DirectRouteCase = {
|
|||||||
|
|
||||||
const authState = vi.hoisted<AuthState>(() => ({
|
const authState = vi.hoisted<AuthState>(() => ({
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
projectMode: 'novel-promotion',
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const submitTaskMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<SubmitResult>>())
|
const submitTaskMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<SubmitResult>>())
|
||||||
@@ -218,14 +216,14 @@ vi.mock('@/lib/api-auth', () => {
|
|||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: authState.projectMode },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
requireProjectAuthLight: async (projectId: string) => {
|
requireProjectAuthLight: async (projectId: string) => {
|
||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: authState.projectMode },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -534,7 +532,6 @@ describe('api contract - direct submit routes (behavior)', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
authState.authenticated = true
|
authState.authenticated = true
|
||||||
authState.projectMode = 'novel-promotion'
|
|
||||||
let seq = 0
|
let seq = 0
|
||||||
submitTaskMock.mockImplementation(async () => ({
|
submitTaskMock.mockImplementation(async () => ({
|
||||||
taskId: `task-${++seq}`,
|
taskId: `task-${++seq}`,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { buildMockRequest } from '../../../helpers/request'
|
|||||||
|
|
||||||
type AuthState = {
|
type AuthState = {
|
||||||
authenticated: boolean
|
authenticated: boolean
|
||||||
projectMode: 'novel-promotion' | 'other'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type LLMRouteCase = {
|
type LLMRouteCase = {
|
||||||
@@ -23,7 +22,6 @@ type RouteContext = {
|
|||||||
|
|
||||||
const authState = vi.hoisted<AuthState>(() => ({
|
const authState = vi.hoisted<AuthState>(() => ({
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
projectMode: 'novel-promotion',
|
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const maybeSubmitLLMTaskMock = vi.hoisted(() =>
|
const maybeSubmitLLMTaskMock = vi.hoisted(() =>
|
||||||
@@ -77,14 +75,14 @@ vi.mock('@/lib/api-auth', () => {
|
|||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: authState.projectMode },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
requireProjectAuthLight: async (projectId: string) => {
|
requireProjectAuthLight: async (projectId: string) => {
|
||||||
if (!authState.authenticated) return unauthorized()
|
if (!authState.authenticated) return unauthorized()
|
||||||
return {
|
return {
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: projectId, userId: 'user-1', mode: authState.projectMode },
|
project: { id: projectId, userId: 'user-1' },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -329,7 +327,6 @@ describe('api contract - llm observe routes (behavior)', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
authState.authenticated = true
|
authState.authenticated = true
|
||||||
authState.projectMode = 'novel-promotion'
|
|
||||||
maybeSubmitLLMTaskMock.mockResolvedValue(
|
maybeSubmitLLMTaskMock.mockResolvedValue(
|
||||||
NextResponse.json({
|
NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { buildMockRequest } from '../../../helpers/request'
|
|||||||
const authMock = vi.hoisted(() => ({
|
const authMock = vi.hoisted(() => ({
|
||||||
requireProjectAuthLight: vi.fn(async () => ({
|
requireProjectAuthLight: vi.fn(async () => ({
|
||||||
session: { user: { id: 'user-1', name: 'User 1' } },
|
session: { user: { id: 'user-1', name: 'User 1' } },
|
||||||
project: { id: 'project-1', userId: 'user-1', mode: 'novel-promotion', name: 'Project 1' },
|
project: { id: 'project-1', userId: 'user-1', name: 'Project 1' },
|
||||||
})),
|
})),
|
||||||
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type StoryboardRecord = {
|
|||||||
const authMock = vi.hoisted(() => ({
|
const authMock = vi.hoisted(() => ({
|
||||||
requireProjectAuthLight: vi.fn(async () => ({
|
requireProjectAuthLight: vi.fn(async () => ({
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: 'project-1', userId: 'user-1', mode: 'novel-promotion' },
|
project: { id: 'project-1', userId: 'user-1' },
|
||||||
})),
|
})),
|
||||||
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ const prismaMock = vi.hoisted(() => ({
|
|||||||
id: 'project-1',
|
id: 'project-1',
|
||||||
name: 'Test Project',
|
name: 'Test Project',
|
||||||
description: null,
|
description: null,
|
||||||
mode: 'novel-promotion',
|
|
||||||
userId: 'user-1',
|
userId: 'user-1',
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
@@ -60,6 +59,13 @@ describe('api specific - project create default audio model', () => {
|
|||||||
|
|
||||||
const res = await mod.POST(req, routeContext)
|
const res = await mod.POST(req, routeContext)
|
||||||
expect(res.status).toBe(201)
|
expect(res.status).toBe(201)
|
||||||
|
expect(prismaMock.project.create).toHaveBeenCalledWith({
|
||||||
|
data: {
|
||||||
|
name: 'Test Project',
|
||||||
|
description: null,
|
||||||
|
userId: 'user-1',
|
||||||
|
},
|
||||||
|
})
|
||||||
expect(prismaMock.novelPromotionProject.create).toHaveBeenCalledWith({
|
expect(prismaMock.novelPromotionProject.create).toHaveBeenCalledWith({
|
||||||
data: expect.objectContaining({
|
data: expect.objectContaining({
|
||||||
projectId: 'project-1',
|
projectId: 'project-1',
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { buildMockRequest } from '../../../helpers/request'
|
|||||||
const authMock = vi.hoisted(() => ({
|
const authMock = vi.hoisted(() => ({
|
||||||
requireProjectAuthLight: vi.fn(async () => ({
|
requireProjectAuthLight: vi.fn(async () => ({
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: 'project-1', userId: 'user-1', mode: 'novel-promotion' },
|
project: { id: 'project-1', userId: 'user-1' },
|
||||||
})),
|
})),
|
||||||
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { buildMockRequest } from '../../../helpers/request'
|
|||||||
const authMock = vi.hoisted(() => ({
|
const authMock = vi.hoisted(() => ({
|
||||||
requireProjectAuthLight: vi.fn(async () => ({
|
requireProjectAuthLight: vi.fn(async () => ({
|
||||||
session: { user: { id: 'user-1' } },
|
session: { user: { id: 'user-1' } },
|
||||||
project: { id: 'project-1', userId: 'user-1', mode: 'novel-promotion' },
|
project: { id: 'project-1', userId: 'user-1' },
|
||||||
})),
|
})),
|
||||||
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
isErrorResponse: vi.fn((value: unknown) => value instanceof Response),
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const queueState = vi.hoisted(() => ({
|
|||||||
|
|
||||||
const prismaMock = vi.hoisted(() => ({
|
const prismaMock = vi.hoisted(() => ({
|
||||||
project: {
|
project: {
|
||||||
findUnique: vi.fn(async () => ({ id: 'project-1', mode: 'novel-promotion' })),
|
findUnique: vi.fn(async () => ({ id: 'project-1' })),
|
||||||
},
|
},
|
||||||
novelPromotionProject: {
|
novelPromotionProject: {
|
||||||
findFirst: vi.fn(async () => ({ id: 'np-project-1' })),
|
findFirst: vi.fn(async () => ({ id: 'np-project-1' })),
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ describe('createHomeProjectLaunch', () => {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: '开场白',
|
name: '开场白',
|
||||||
description: '第一章内容',
|
description: '第一章内容',
|
||||||
mode: 'novel-promotion',
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
expect(apiFetch).toHaveBeenNthCalledWith(2, '/api/novel-promotion/project-1', {
|
expect(apiFetch).toHaveBeenNthCalledWith(2, '/api/novel-promotion/project-1', {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ describe('worker analyze-global behavior', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
|
||||||
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1', mode: 'novel-promotion' })
|
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1' })
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
id: 'np-project-1',
|
id: 'np-project-1',
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ describe('worker analyze-novel behavior', () => {
|
|||||||
|
|
||||||
prismaMock.project.findUnique.mockResolvedValue({
|
prismaMock.project.findUnique.mockResolvedValue({
|
||||||
id: 'project-1',
|
id: 'project-1',
|
||||||
mode: 'novel-promotion',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ describe('worker clips-build behavior', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
|
||||||
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1', mode: 'novel-promotion' })
|
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1' })
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
id: 'np-project-1',
|
id: 'np-project-1',
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { TASK_TYPE, type TaskJobData } from '@/lib/task/types'
|
|||||||
|
|
||||||
const prismaMock = vi.hoisted(() => ({
|
const prismaMock = vi.hoisted(() => ({
|
||||||
project: {
|
project: {
|
||||||
findUnique: vi.fn(async () => ({ id: 'project-1', mode: 'novel-promotion' })),
|
findUnique: vi.fn(async () => ({ id: 'project-1' })),
|
||||||
},
|
},
|
||||||
novelPromotionProject: {
|
novelPromotionProject: {
|
||||||
findFirst: vi.fn(async () => ({ id: 'np-project-1' })),
|
findFirst: vi.fn(async () => ({ id: 'np-project-1' })),
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ describe('worker screenplay-convert behavior', () => {
|
|||||||
prismaMock.project.findUnique.mockResolvedValue({
|
prismaMock.project.findUnique.mockResolvedValue({
|
||||||
id: 'project-1',
|
id: 'project-1',
|
||||||
name: 'Project One',
|
name: 'Project One',
|
||||||
mode: 'novel-promotion',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
|
|||||||
@@ -231,7 +231,6 @@ describe('worker script-to-storyboard behavior', () => {
|
|||||||
prismaMock.project.findUnique.mockResolvedValue({
|
prismaMock.project.findUnique.mockResolvedValue({
|
||||||
id: 'project-1',
|
id: 'project-1',
|
||||||
name: 'Project One',
|
name: 'Project One',
|
||||||
mode: 'novel-promotion',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ describe('worker story-to-script behavior', () => {
|
|||||||
prismaMock.project.findUnique.mockResolvedValue({
|
prismaMock.project.findUnique.mockResolvedValue({
|
||||||
id: 'project-1',
|
id: 'project-1',
|
||||||
name: 'Project One',
|
name: 'Project One',
|
||||||
mode: 'novel-promotion',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ describe('worker voice-analyze behavior', () => {
|
|||||||
txState.createdRows = []
|
txState.createdRows = []
|
||||||
txState.deletedWhereClauses = []
|
txState.deletedWhereClauses = []
|
||||||
|
|
||||||
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1', mode: 'novel-promotion' })
|
prismaMock.project.findUnique.mockResolvedValue({ id: 'project-1' })
|
||||||
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
prismaMock.novelPromotionProject.findUnique.mockResolvedValue({
|
||||||
id: 'np-project-1',
|
id: 'np-project-1',
|
||||||
analysisModel: 'llm::analysis-1',
|
analysisModel: 'llm::analysis-1',
|
||||||
|
|||||||
Reference in New Issue
Block a user