2026-06-13 10:18:39 +08:00
|
|
|
import { readFile } from "node:fs/promises";
|
|
|
|
|
import { resolveGs } from "@snapotter/doc-engine";
|
|
|
|
|
import { ffmpegAvailable } from "@snapotter/media-engine";
|
|
|
|
|
import { describe, expect, it } from "vitest";
|
2026-06-20 05:07:46 +08:00
|
|
|
import { pdfFirstPagePreview, videoPosterPreview } from "../../../apps/api/src/modality/preview.js";
|
|
|
|
|
import { fixtures, readFixture } from "../../fixtures/index.js";
|
2026-06-13 10:18:39 +08:00
|
|
|
|
|
|
|
|
describe.skipIf(!ffmpegAvailable())("video poster preview (requires ffmpeg)", () => {
|
|
|
|
|
it("renders a webp poster", async () => {
|
2026-06-20 04:20:17 +08:00
|
|
|
const buf = readFixture(fixtures.video.tiny("mp4"));
|
2026-06-13 10:18:39 +08:00
|
|
|
const poster = await videoPosterPreview(buf);
|
|
|
|
|
expect(poster).not.toBeNull();
|
|
|
|
|
expect(poster?.length).toBeGreaterThan(50);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe.skipIf(!resolveGs())("pdf first-page preview (requires ghostscript)", () => {
|
|
|
|
|
it("renders a png of page 1", async () => {
|
2026-06-20 04:20:17 +08:00
|
|
|
const buf = readFixture(fixtures.document.pdf3);
|
2026-06-13 10:18:39 +08:00
|
|
|
const png = await pdfFirstPagePreview(buf);
|
|
|
|
|
expect(png).not.toBeNull();
|
|
|
|
|
expect(png?.subarray(1, 4).toString()).toBe("PNG");
|
|
|
|
|
});
|
|
|
|
|
});
|