MCPcopy
hub / github.com/CapSoftware/Cap / restoreVideoToOriginal

Function restoreVideoToOriginal

apps/web/actions/videos/save-edits.ts:218–277  ·  view source on GitHub ↗
(videoId: Video.VideoId)

Source from the content-addressed store, hash-verified

216}
217
218export async function restoreVideoToOriginal(videoId: Video.VideoId) {
219 const { user, video } = await loadEditableVideo(videoId);
220
221 const [existingEdit] = await db()
222 .select()
223 .from(videoEdits)
224 .where(eq(videoEdits.videoId, videoId));
225
226 if (!existingEdit) {
227 revalidatePath(`/s/${videoId}/edit`);
228 return { success: true, skipped: true };
229 }
230
231 const previousSpec = existingEdit.editSpec;
232 const restoredSpec = createIdentityEditSpec(previousSpec.sourceDuration);
233
234 if (getEditSpecOutputDuration(restoredSpec) <= 0) {
235 throw new Error("Original video is no longer available");
236 }
237
238 if (areEditSpecsEquivalent(previousSpec, restoredSpec)) {
239 revalidatePath(`/s/${videoId}/edit`);
240 return { success: true, skipped: true };
241 }
242
243 const sourceKey = existingEdit.sourceKey;
244 const bucket = await getVideoBucket(video);
245 if (!(await objectExists(bucket, sourceKey))) {
246 throw new Error("Original video is no longer available");
247 }
248
249 const aiGenerationEnabled = await isAiGenerationEnabled(user);
250
251 await markEditProcessing({ videoId, sourceKey });
252
253 try {
254 await start(editVideoWorkflow, [
255 {
256 videoId,
257 userId: user.id,
258 sourceKey,
259 previousSpec,
260 editSpec: restoredSpec,
261 keepRanges: restoredSpec.keepRanges,
262 aiGenerationEnabled,
263 },
264 ]);
265 } catch (error) {
266 await db().delete(videoUploads).where(eq(videoUploads.videoId, videoId));
267 throw error instanceof Error
268 ? error
269 : new Error("Video restore could not start");
270 }
271
272 revalidatePath(`/s/${videoId}`);
273 revalidatePath(`/s/${videoId}/edit`);
274 revalidatePath("/dashboard/caps");
275

Callers 1

EditVideoClientFunction · 0.90

Calls 10

dbFunction · 0.90
createIdentityEditSpecFunction · 0.90
areEditSpecsEquivalentFunction · 0.90
isAiGenerationEnabledFunction · 0.90
startFunction · 0.90
loadEditableVideoFunction · 0.85
getVideoBucketFunction · 0.85
objectExistsFunction · 0.85
markEditProcessingFunction · 0.85

Tested by

no test coverage detected