982f9048e1
CI / build (push) Has been cancelled
A bind-mounted host directory made the app report storage as ready while media landed on the container host's local filesystem, so the NFS export was never actually used. mediaStorage() now reads the mount table: a share written as host:/export is only accepted when the media root is on a network filesystem, otherwise uploads, edits and filing are blocked with the real device and the fix. Settings and the Media page show the detected filesystem and host-mount steps, README section 9 documents the OS-level mount (including Docker-in-LXC) with docker-compose.nfs.yml as the alternative, and the E2E suites use path-style shares for local test directories. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
335 lines
11 KiB
TypeScript
335 lines
11 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
||
import { execFile } from "node:child_process";
|
||
import { promisify } from "node:util";
|
||
import { access, mkdir, readFile, rm, stat } from "node:fs/promises";
|
||
import path from "node:path";
|
||
import { signInAs, resetDb, BASE } from "./dev";
|
||
|
||
/**
|
||
* Video library workflow: a generated MP4 is uploaded to an event, the camera
|
||
* original lands on the NFS mount, FFmpeg builds a playable derivative, the
|
||
* original survives a trim, and the public watch/embed/oEmbed endpoints work
|
||
* anonymously. Deleting the event removes both the NFS original and derivatives.
|
||
*/
|
||
|
||
const execFileAsync = promisify(execFile);
|
||
const ARCHIVE_ROOT = process.env.ARCHIVE_DIR ?? "/tmp/glenloch-e2e-archive";
|
||
const ARCHIVE_FOLDER = "E2E Video Archive";
|
||
// Originals and every derivative live on the configured share, never in the
|
||
// app container's upload volume.
|
||
const MEDIA_ROOT = path.join(ARCHIVE_ROOT, ARCHIVE_FOLDER);
|
||
const SAMPLE = "/tmp/glenloch-e2e-media-sample.mp4";
|
||
|
||
// A real 32×24 JPEG, so the media page renders a normal browser image.
|
||
const PHOTO = Buffer.from(
|
||
"/9j/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAAYACADASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAcICf/EABgQAQADAQAAAAAAAAAAAAAAAAAXZaTi/8QAFQEBAQAAAAAAAAAAAAAAAAAACAf/xAAbEQEAAQUBAAAAAAAAAAAAAAAAAQMEFFKh0f/aAAwDAQACEQMRAD8AuYAvrq5kinQtc5eyFrnL2XmDca9j0ccyhtyW6ABDI5mQA6BNf//Z",
|
||
"base64",
|
||
);
|
||
|
||
let sampleBytes: Buffer;
|
||
|
||
type VideoPayload = {
|
||
video: {
|
||
id: string;
|
||
status: "processing" | "ready" | "failed";
|
||
durationMs: number | null;
|
||
trimStartMs: number;
|
||
trimEndMs: number | null;
|
||
canPlay: boolean;
|
||
isShareable: boolean;
|
||
embedCode: string | null;
|
||
};
|
||
};
|
||
|
||
test.describe("media library and video sharing", () => {
|
||
test.beforeAll(async ({ browser }) => {
|
||
const context = await browser.newContext();
|
||
const page = await context.newPage();
|
||
await resetDb(page);
|
||
await context.close();
|
||
|
||
await mkdir(ARCHIVE_ROOT, { recursive: true });
|
||
await rm(path.join(ARCHIVE_ROOT, ARCHIVE_FOLDER), {
|
||
recursive: true,
|
||
force: true,
|
||
});
|
||
|
||
await execFileAsync("ffmpeg", [
|
||
"-hide_banner",
|
||
"-loglevel",
|
||
"error",
|
||
"-y",
|
||
"-f",
|
||
"lavfi",
|
||
"-i",
|
||
"color=c=0x204060:s=1280x720:d=3:r=24",
|
||
"-f",
|
||
"lavfi",
|
||
"-i",
|
||
"sine=frequency=440:duration=3",
|
||
"-c:v",
|
||
"libx264",
|
||
"-pix_fmt",
|
||
"yuv420p",
|
||
"-c:a",
|
||
"aac",
|
||
"-shortest",
|
||
SAMPLE,
|
||
]);
|
||
sampleBytes = await readFile(SAMPLE);
|
||
});
|
||
|
||
test("uploads, trims, publishes, and cleans up a video", async ({ page }) => {
|
||
test.setTimeout(240_000);
|
||
await page.setViewportSize({ width: 1200, height: 900 });
|
||
await signInAs(page, "admin@glenloch.local");
|
||
|
||
const configured = await page.request.put(`${BASE}/api/dev/storage`, {
|
||
data: {
|
||
// Path-style share: this suite writes to a local E2E directory. A
|
||
// NAS-style share name would (correctly) demand a real network mount.
|
||
nfsShare: ARCHIVE_ROOT,
|
||
archivePath: ARCHIVE_ROOT,
|
||
archiveFolder: ARCHIVE_FOLDER,
|
||
},
|
||
});
|
||
expect(configured.ok()).toBe(true);
|
||
|
||
const eventResponse = await page.request.post(`${BASE}/api/events`, {
|
||
data: {
|
||
title: "E2E media event",
|
||
eventType: "photoshoot",
|
||
startsAtLocal: "2026-11-21T10:00",
|
||
location: "Main campus",
|
||
},
|
||
});
|
||
expect(eventResponse.ok()).toBe(true);
|
||
const event = (await eventResponse.json()) as { event: { id: string } };
|
||
const eventId = event.event.id;
|
||
|
||
const folderResponse = await page.request.post(
|
||
`${BASE}/api/events/${eventId}/folders`,
|
||
{ data: { name: "Originals", kind: "originals" } },
|
||
);
|
||
expect(folderResponse.ok()).toBe(true);
|
||
const folder = (await folderResponse.json()) as {
|
||
folder: { id: string };
|
||
};
|
||
|
||
const photoUpload = await page.request.post(
|
||
`${BASE}/api/events/${eventId}/folders/${folder.folder.id}/photos?name=media-test.jpg`,
|
||
{
|
||
headers: { "content-type": "image/jpeg" },
|
||
data: PHOTO,
|
||
},
|
||
);
|
||
expect(photoUpload.ok()).toBe(true);
|
||
|
||
const upload = await page.request.post(
|
||
`${BASE}/api/events/${eventId}/videos?name=recap.mp4&title=E2E%20video&visibility=team`,
|
||
{
|
||
headers: { "content-type": "video/mp4" },
|
||
data: sampleBytes,
|
||
},
|
||
);
|
||
expect(upload.status()).toBe(201);
|
||
const created = (await upload.json()) as VideoPayload;
|
||
const videoId = created.video.id;
|
||
expect(created.video.status).toBe("processing");
|
||
|
||
const readVideo = async (): Promise<VideoPayload> => {
|
||
const response = await page.request.get(
|
||
`${BASE}/api/events/${eventId}/videos/${videoId}`,
|
||
);
|
||
expect(response.ok()).toBe(true);
|
||
return (await response.json()) as VideoPayload;
|
||
};
|
||
|
||
await expect
|
||
.poll(async () => (await readVideo()).video.status, {
|
||
timeout: 120_000,
|
||
intervals: [500, 1000, 2000],
|
||
})
|
||
.toBe("ready");
|
||
|
||
const ready = await readVideo();
|
||
expect(ready.video.durationMs).toBeGreaterThan(2500);
|
||
expect(ready.video.canPlay).toBe(true);
|
||
expect(ready.video.isShareable).toBe(false);
|
||
|
||
const nfsOriginal = path.join(
|
||
ARCHIVE_ROOT,
|
||
ARCHIVE_FOLDER,
|
||
"videos",
|
||
eventId,
|
||
videoId,
|
||
"original.mp4",
|
||
);
|
||
expect((await stat(nfsOriginal)).size).toBe(sampleBytes.length);
|
||
expect((await readFile(nfsOriginal)).equals(sampleBytes)).toBe(true);
|
||
|
||
const sidecar = JSON.parse(
|
||
await readFile(path.join(path.dirname(nfsOriginal), "video.json"), "utf8"),
|
||
) as { checksumSha256: string; eventId: string };
|
||
expect(sidecar.eventId).toBe(eventId);
|
||
expect(sidecar.checksumSha256).toMatch(/^[a-f0-9]{64}$/);
|
||
|
||
const original = await page.request.get(
|
||
`${BASE}/api/events/${eventId}/videos/${videoId}/original`,
|
||
);
|
||
expect(original.ok()).toBe(true);
|
||
expect((await original.body()).equals(sampleBytes)).toBe(true);
|
||
|
||
const poster = await page.request.get(
|
||
`${BASE}/api/media/${videoId}/poster`,
|
||
);
|
||
expect(poster.ok()).toBe(true);
|
||
expect(poster.headers()["content-type"]).toContain("image/jpeg");
|
||
|
||
const edit = await page.request.post(
|
||
`${BASE}/api/events/${eventId}/videos/${videoId}/edit`,
|
||
{
|
||
data: {
|
||
title: "E2E video public",
|
||
visibility: "public",
|
||
trimStartMs: 500,
|
||
trimEndMs: 2000,
|
||
},
|
||
},
|
||
);
|
||
expect(edit.ok()).toBe(true);
|
||
const edited = (await edit.json()) as VideoPayload;
|
||
expect(edited.video.status).toBe("processing");
|
||
|
||
await expect
|
||
.poll(async () => (await readVideo()).video.status, {
|
||
timeout: 120_000,
|
||
intervals: [500, 1000, 2000],
|
||
})
|
||
.toBe("ready");
|
||
|
||
const trimmed = await readVideo();
|
||
expect(trimmed.video.trimStartMs).toBe(500);
|
||
expect(trimmed.video.trimEndMs).toBe(2000);
|
||
expect(trimmed.video.isShareable).toBe(true);
|
||
expect(trimmed.video.embedCode).toContain(`/embed/${videoId}`);
|
||
|
||
const webPath = path.join(
|
||
MEDIA_ROOT,
|
||
"videos",
|
||
eventId,
|
||
videoId,
|
||
"web.mp4",
|
||
);
|
||
const probe = await execFileAsync(
|
||
"ffprobe",
|
||
[
|
||
"-v",
|
||
"error",
|
||
"-show_entries",
|
||
"format=duration",
|
||
"-of",
|
||
"default=nw=1:nk=1",
|
||
webPath,
|
||
],
|
||
{ encoding: "utf8" },
|
||
);
|
||
const trimmedSeconds = Number(String(probe.stdout).trim());
|
||
expect(trimmedSeconds).toBeGreaterThan(1.2);
|
||
expect(trimmedSeconds).toBeLessThan(1.9);
|
||
|
||
// A 720p upload gets a smaller 480p sibling for slow connections.
|
||
const lowPath = path.join(
|
||
MEDIA_ROOT,
|
||
"videos",
|
||
eventId,
|
||
videoId,
|
||
"web-480.mp4",
|
||
);
|
||
expect((await stat(lowPath)).size).toBeGreaterThan(0);
|
||
|
||
const lowStream = await fetch(
|
||
`${BASE}/api/media/${videoId}/stream?quality=480`,
|
||
{ headers: { range: "bytes=0-255" } },
|
||
);
|
||
expect(lowStream.status).toBe(206);
|
||
expect(lowStream.headers.get("content-range")).toContain("bytes 0-255/");
|
||
expect((await lowStream.arrayBuffer()).byteLength).toBe(256);
|
||
|
||
// The non-destructive trim must never touch the NFS camera original.
|
||
expect((await readFile(nfsOriginal)).equals(sampleBytes)).toBe(true);
|
||
|
||
const stream = await fetch(`${BASE}/api/media/${videoId}/stream`, {
|
||
headers: { range: "bytes=0-255" },
|
||
});
|
||
expect(stream.status).toBe(206);
|
||
expect(stream.headers.get("content-range")).toContain("bytes 0-255/");
|
||
expect((await stream.arrayBuffer()).byteLength).toBe(256);
|
||
|
||
const watch = await fetch(`${BASE}/watch/${videoId}`);
|
||
expect(watch.status).toBe(200);
|
||
const watchHtml = await watch.text();
|
||
expect(watchHtml).toContain("E2E video public");
|
||
expect(watchHtml).toContain("Glenloch Baptist Church");
|
||
expect(watchHtml).not.toContain("Media Team Hub");
|
||
expect(watchHtml).toContain('property="og:video"');
|
||
expect(watchHtml).toContain('name="twitter:player"');
|
||
expect(watchHtml).toContain("application/json+oembed");
|
||
|
||
const embed = await fetch(`${BASE}/embed/${videoId}`);
|
||
expect(embed.status).toBe(200);
|
||
expect(embed.headers.get("x-frame-options")).toBeNull();
|
||
expect(await embed.text()).toContain("<video");
|
||
|
||
const oembed = await fetch(
|
||
`${BASE}/api/oembed?url=${encodeURIComponent(`${BASE}/watch/${videoId}`)}&format=json`,
|
||
);
|
||
expect(oembed.status).toBe(200);
|
||
expect(oembed.headers.get("access-control-allow-origin")).toBe("*");
|
||
const payload = (await oembed.json()) as {
|
||
type: string;
|
||
width: number;
|
||
height: number;
|
||
html: string;
|
||
thumbnail_url: string;
|
||
};
|
||
expect(payload.type).toBe("video");
|
||
expect(payload.width).toBe(1280);
|
||
expect(payload.height).toBe(720);
|
||
expect(payload.html).toContain(`/embed/${videoId}`);
|
||
expect(payload.thumbnail_url).toContain(`/api/media/${videoId}/poster`);
|
||
|
||
await page.goto(`${BASE}/media`);
|
||
await expect(
|
||
page.getByRole("heading", { name: "Media", exact: true }),
|
||
).toBeVisible();
|
||
await expect(page.getByText("media-test.jpg").first()).toBeVisible();
|
||
await expect(page.getByText("E2E video public").first()).toBeVisible();
|
||
await page.getByRole("link", { name: /E2E video public/ }).click();
|
||
await expect(page).toHaveURL(new RegExp(`/media/${videoId}$`));
|
||
await expect(
|
||
page.getByRole("heading", { name: "Edit video" }),
|
||
).toBeVisible();
|
||
await expect(page.getByLabel("Visibility")).toHaveValue("public");
|
||
await expect(page.getByLabel("Embed code")).toHaveValue(/<iframe/);
|
||
|
||
await page.goto(`${BASE}/events/${eventId}`);
|
||
await expect(
|
||
page.getByRole("heading", { name: "E2E media event" }),
|
||
).toBeVisible();
|
||
await expect(page.getByText("E2E video public").first()).toBeVisible();
|
||
await expect(page.getByLabel("Video file")).toBeVisible();
|
||
|
||
page.once("dialog", (dialog) => dialog.accept());
|
||
await page.getByRole("button", { name: "Delete event" }).click();
|
||
await expect(page).toHaveURL(`${BASE}/events`);
|
||
|
||
await expect(access(nfsOriginal)).rejects.toThrow();
|
||
await expect(
|
||
access(path.join(MEDIA_ROOT, "videos", eventId)),
|
||
).rejects.toThrow();
|
||
const gone = await fetch(`${BASE}/watch/${videoId}`);
|
||
expect(gone.status).toBe(404);
|
||
});
|
||
});
|