MCPcopy Index your code
hub / github.com/CapSoftware/Cap / editTranscriptEntry

Function editTranscriptEntry

apps/web/actions/videos/edit-transcript.ts:15–97  ·  view source on GitHub ↗
(
	videoId: Video.VideoId,
	entryId: number,
	newText: string,
)

Source from the content-addressed store, hash-verified

13import { decodeStorageVideo } from "@/lib/video-storage";
14
15export async function editTranscriptEntry(
16 videoId: Video.VideoId,
17 entryId: number,
18 newText: string,
19): Promise<{ success: boolean; message: string }> {
20 const user = await getCurrentUser();
21
22 if (!user || !videoId || entryId === undefined || !newText?.trim()) {
23 return {
24 success: false,
25 message: "Missing required data for updating transcript entry",
26 };
27 }
28
29 const userId = user.id;
30 const query = await db()
31 .select({ video: videos })
32 .from(videos)
33 .where(eq(videos.id, videoId));
34
35 if (query.length === 0) {
36 return { success: false, message: "Video not found" };
37 }
38
39 const result = query[0];
40 if (!result?.video) {
41 return { success: false, message: "Video information is missing" };
42 }
43
44 const { video } = result;
45
46 if (video.ownerId !== userId) {
47 return {
48 success: false,
49 message: "You don't have permission to edit this transcript",
50 };
51 }
52
53 const [bucket] = await Storage.getAccessForVideo(
54 decodeStorageVideo(video),
55 ).pipe(runPromise);
56
57 try {
58 const transcriptKey = `${video.ownerId}/${videoId}/transcription.vtt`;
59
60 const vttContent = await bucket.getObject(transcriptKey).pipe(runPromise);
61 if (Option.isNone(vttContent))
62 return { success: false, message: "Transcript file not found" };
63
64 const { content: updatedVttContent, updated } = updateVttEntryText(
65 vttContent.value,
66 entryId,
67 newText,
68 );
69 if (!updated) {
70 return { success: false, message: "Transcript entry not found" };
71 }
72

Callers 1

saveEditFunction · 0.90

Calls 3

dbFunction · 0.90
decodeStorageVideoFunction · 0.90
updateVttEntryTextFunction · 0.90

Tested by

no test coverage detected