-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathroute.ts
More file actions
55 lines (47 loc) · 1.5 KB
/
Copy pathroute.ts
File metadata and controls
55 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { db } from "@cap/database";
import { getCurrentUser } from "@cap/database/auth/session";
import { videos } from "@cap/database/schema";
import { eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
export async function POST(
_request: Request,
{ params }: { params: { videoId: string } },
) {
try {
const user = await getCurrentUser();
if (!user) {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
const { videoId } = params;
if (!videoId) {
return Response.json({ error: "Video ID is required" }, { status: 400 });
}
// Verify user owns the video
const videoQuery = await db()
.select()
.from(videos)
.where(eq(videos.id, videoId))
.limit(1);
if (videoQuery.length === 0) {
return Response.json({ error: "Video not found" }, { status: 404 });
}
const video = videoQuery[0];
if (!video || video.ownerId !== user.id) {
return Response.json({ error: "Unauthorized" }, { status: 403 });
}
// Reset status to null - this will trigger automatic retry via get-status.ts
await db()
.update(videos)
.set({ transcriptionStatus: null })
.where(eq(videos.id, videoId));
// Revalidate the video page to ensure UI updates with fresh data
revalidatePath(`/s/${videoId}`);
return Response.json({
success: true,
message: "Transcription retry triggered",
});
} catch (error) {
console.error("Error resetting transcription status:", error);
return Response.json({ error: "Internal server error" }, { status: 500 });
}
}