mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 21:03:47 -10:00
Compare commits
1
Commits
v0.1.16-rc5
...
sizes-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c89470125 |
No files matched your search
@@ -11,11 +11,24 @@ import { check, found } from "raea/check"
|
||||
import type { Job } from "../facts.ts"
|
||||
import { adOf, bookkeeping, sizeOf } from "./naming.ts"
|
||||
|
||||
/** The size a made file is in, as a name says one (9x16): its name's, else a video's own shape (1080x1920 is 9x16).
|
||||
* A picture with no size in its name is a still of the work, a sheet or a strip, not a size of an ad. Told by pixels
|
||||
* alone, an ad named _9x16 beside its own 1080x1920 renders and one 540x960 still read as three sizes, and an agent
|
||||
* with one size made couldn't stop for its sign-off (12-01). */
|
||||
export function shapeOf(f: { path: string; kind?: string; width?: number; height?: number }): string | null {
|
||||
const named = sizeOf(f.path)
|
||||
if (named) return named
|
||||
if (f.kind !== "video" || !f.width || !f.height) return null
|
||||
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a)
|
||||
const g = gcd(f.width, f.height)
|
||||
return `${f.width / g}x${f.height / g}`
|
||||
}
|
||||
|
||||
export default check<Job>({ id: "sizes", text: "one size first: no other size before the first is approved", over: "job", at: ["render", "publish", "done"] }, async (j) => {
|
||||
const made = j.files.filter((f) => f.made && !bookkeeping(f.path) && (f.kind === "video" || f.kind === "image"))
|
||||
const sizes = new Map<string, string[]>()
|
||||
for (const f of made) {
|
||||
const s = sizeOf(f.path) ?? (f.width && f.height ? `${f.width}x${f.height}` : null)
|
||||
const s = shapeOf(f)
|
||||
if (s) sizes.set(s, [...(sizes.get(s) ?? []), f.path])
|
||||
}
|
||||
if (sizes.size < 2) return
|
||||
|
||||
@@ -4,6 +4,7 @@ import { beforeAll, expect, test } from "bun:test"
|
||||
import { goalCheck } from "../src/run.ts"
|
||||
import { CLIP, project, put } from "./project.ts"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { shapeOf } from "../src/packs/sizes.ts"
|
||||
|
||||
beforeAll(() => {
|
||||
process.env.RAEA_REAL = "/usr/bin/false"
|
||||
@@ -31,3 +32,13 @@ test("every size of the newest version passes; a person's answer can say fewer",
|
||||
expect((await all(answered, sizes)).filter((x) => x.check === "sizes-all")).toEqual([])
|
||||
expect((await all(answered, ["out/cuts/dutch_vetbill_hooka_v2_9x16.mp4"])).filter((x) => x.check === "sizes-all")).toEqual([])
|
||||
})
|
||||
|
||||
test("one size is one size however it's told: a name's 9x16, a 1080x1920 video, never a still", () => {
|
||||
expect(shapeOf({ path: "out/cuts/dutch_vetbill_hooka_v1_9x16.mp4", kind: "video", width: 1080, height: 1920 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka.mp4", kind: "video", width: 1080, height: 1920 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka_small.mp4", kind: "video", width: 540, height: 960 })).toBe("9x16")
|
||||
expect(shapeOf({ path: "out/cuts/hooka.mp4", kind: "video", width: 1080, height: 1350 })).toBe("4x5")
|
||||
expect(shapeOf({ path: "out/stills/a1_38.jpg", kind: "image", width: 540, height: 960 })).toBe(null)
|
||||
expect(shapeOf({ path: "out/stills/strip.png", kind: "image", width: 1080, height: 480 })).toBe(null)
|
||||
expect(shapeOf({ path: "out/stills/dutch_vetbill_end_v1_1x1.png", kind: "image", width: 1080, height: 1080 })).toBe("1x1")
|
||||
})
|
||||
Reference in new issue
Block a user