|
1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 2 | import { Hono } from "hono"; |
| 3 | +import { parseHTML } from "linkedom"; |
3 | 4 | import { |
4 | 5 | existsSync, |
5 | 6 | mkdirSync, |
@@ -107,6 +108,9 @@ function postCutBatch( |
107 | 108 | splitTime: number; |
108 | 109 | elementStart: number; |
109 | 110 | elementDuration: number; |
| 111 | + playbackStart?: number; |
| 112 | + playbackRate?: number; |
| 113 | + isComposition?: boolean; |
110 | 114 | }>; |
111 | 115 | }>, |
112 | 116 | ): Promise<Response> { |
@@ -851,6 +855,55 @@ describe("registerFileRoutes", () => { |
851 | 855 | }); |
852 | 856 | }); |
853 | 857 |
|
| 858 | + it("persists media in-points for audio and video in an atomic split-all cut", async () => { |
| 859 | + const projectDir = createProjectDir(); |
| 860 | + const before = |
| 861 | + '<audio id="audio" src="voice.mp3" data-start="0" data-duration="6"></audio>' + |
| 862 | + '<video id="video" src="clip.mp4" data-start="0" data-duration="6" data-playback-rate="2"></video>'; |
| 863 | + writeFileSync(join(projectDir, "index.html"), before); |
| 864 | + const app = new Hono(); |
| 865 | + registerFileRoutes(app, createAdapter(projectDir)); |
| 866 | + |
| 867 | + const response = await postCutBatch(app, [ |
| 868 | + { |
| 869 | + path: "index.html", |
| 870 | + expectedVersion: fileContentVersion(before), |
| 871 | + targets: [ |
| 872 | + { |
| 873 | + target: { id: "audio" }, |
| 874 | + originalId: "audio", |
| 875 | + splitTime: 2, |
| 876 | + elementStart: 0, |
| 877 | + elementDuration: 6, |
| 878 | + playbackStart: 0, |
| 879 | + playbackRate: 1, |
| 880 | + }, |
| 881 | + { |
| 882 | + target: { id: "video" }, |
| 883 | + originalId: "video", |
| 884 | + splitTime: 2, |
| 885 | + elementStart: 0, |
| 886 | + elementDuration: 6, |
| 887 | + playbackStart: 0, |
| 888 | + playbackRate: 2, |
| 889 | + }, |
| 890 | + ], |
| 891 | + }, |
| 892 | + ]); |
| 893 | + const payload = (await response.json()) as { |
| 894 | + files: Array<{ after: string; splitCount: number }>; |
| 895 | + }; |
| 896 | + const { document } = parseHTML(payload.files[0].after); |
| 897 | + |
| 898 | + expect(response.status).toBe(200); |
| 899 | + expect(payload.files[0].splitCount).toBe(2); |
| 900 | + expect(document.getElementById("audio")?.getAttribute("data-media-start")).toBe("0"); |
| 901 | + expect(document.getElementById("audio-split")?.getAttribute("data-media-start")).toBe("2"); |
| 902 | + expect(document.getElementById("video")?.getAttribute("data-media-start")).toBe("0"); |
| 903 | + expect(document.getElementById("video-split")?.getAttribute("data-media-start")).toBe("4"); |
| 904 | + expect(readFileSync(join(projectDir, "index.html"), "utf-8")).toBe(payload.files[0].after); |
| 905 | + }); |
| 906 | + |
854 | 907 | it("cuts multiple id-less selector targets against their original indices", async () => { |
855 | 908 | const projectDir = createProjectDir(); |
856 | 909 | const before = |
|
0 commit comments