(
videoId: string,
sourceKey: string,
previousSpec: VideoEditSpec,
editSpec: VideoEditSpec,
metadata: { duration: number; width: number; height: number; fps: number },
)
| 663 | } |
| 664 | |
| 665 | async function saveEditResultAndComplete( |
| 666 | videoId: string, |
| 667 | sourceKey: string, |
| 668 | previousSpec: VideoEditSpec, |
| 669 | editSpec: VideoEditSpec, |
| 670 | metadata: { duration: number; width: number; height: number; fps: number }, |
| 671 | ): Promise<void> { |
| 672 | "use step"; |
| 673 | |
| 674 | const duration = getValidDuration(metadata.duration); |
| 675 | const [video] = await db() |
| 676 | .select() |
| 677 | .from(videos) |
| 678 | .where(eq(videos.id, videoId as Video.VideoId)); |
| 679 | |
| 680 | if (!video) { |
| 681 | throw new FatalError("Video does not exist"); |
| 682 | } |
| 683 | |
| 684 | const nextMetadata = clearAiMetadata(video.metadata as VideoMetadata | null); |
| 685 | |
| 686 | await db().transaction(async (tx) => { |
| 687 | await tx |
| 688 | .update(videos) |
| 689 | .set({ |
| 690 | width: metadata.width, |
| 691 | height: metadata.height, |
| 692 | fps: metadata.fps, |
| 693 | metadata: nextMetadata, |
| 694 | transcriptionStatus: null, |
| 695 | ...(duration === undefined ? {} : { duration }), |
| 696 | }) |
| 697 | .where(eq(videos.id, videoId as Video.VideoId)); |
| 698 | |
| 699 | await tx |
| 700 | .insert(videoEdits) |
| 701 | .values({ |
| 702 | videoId: videoId as Video.VideoId, |
| 703 | sourceKey, |
| 704 | editSpec, |
| 705 | updatedAt: new Date(), |
| 706 | }) |
| 707 | .onDuplicateKeyUpdate({ |
| 708 | set: { |
| 709 | sourceKey, |
| 710 | editSpec, |
| 711 | updatedAt: new Date(), |
| 712 | }, |
| 713 | }); |
| 714 | |
| 715 | const timestampedComments = await tx |
| 716 | .select({ |
| 717 | id: comments.id, |
| 718 | timestamp: comments.timestamp, |
| 719 | }) |
| 720 | .from(comments) |
| 721 | .where(eq(comments.videoId, videoId as Video.VideoId)); |
| 722 |
no test coverage detected