- services/video.py: background worker (one video at a time, low priority) makes a still frame (thumb/card/full WebP) and, when needed, play.mp4 (H.264+AAC, <=1920 px, HDR tone-mapped, faststart); the original is kept. Media.processing/progress (migration 0031, existing videos queued). ffmpeg from the pinned imageio-ffmpeg wheel; none = as uploaded. - MOV (video/quicktime) accepted; /api/media/file/<sha>/play served with ranges. - Signage plays the version (poster = still frame) and tells the screens playing it when ready. - Manager library: still frames in the grid, preparing progress, status in the details. - Tests: test_video.py (8), backend 541 passed; e2e media/signage/stack new checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
2.7 KiB
JavaScript
54 lines
2.7 KiB
JavaScript
// The media library's helpers and its nav rule (plan step 5.2).
|
||
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { duration, fileSize, imageOf, preparing, queueFrom, queueSummary, resolution, videoState } from '../src/pages/media/mediaLogic.js'
|
||
import { canSee, pageFor } from '../src/shell/nav.js'
|
||
|
||
test('sizes, resolutions and lengths for people', () => {
|
||
assert.equal(fileSize(512), '512 B')
|
||
assert.equal(fileSize(250_000), '244 KB')
|
||
assert.equal(fileSize(3.4 * 1024 * 1024, (n, o) => n.toFixed(o.maxDecimals)), '3.4 MB')
|
||
assert.equal(fileSize(null), '')
|
||
assert.equal(resolution(1920, 1080), '1920 × 1080')
|
||
assert.equal(resolution(null, 5), '')
|
||
assert.equal(duration(12_500), '0:13')
|
||
assert.equal(duration(3_909_000), '1:05:09')
|
||
})
|
||
|
||
test('a library item as the picture an app shows', () => {
|
||
const item = { id: 4, kind: 'image', name: 'Gyros', urls: { thumb: '/t', card: '/c', full: '/f', original: '/o' } }
|
||
assert.deepEqual(imageOf(item), { id: 4, name: 'Gyros', thumb: '/t', card: '/c', full: '/f' })
|
||
assert.equal(imageOf({ ...item, kind: 'video' }), null)
|
||
assert.equal(imageOf(null), null)
|
||
})
|
||
|
||
test('a video being prepared for screens (5.4e)', () => {
|
||
const v = (processing, urls = {}) => ({ kind: 'video', processing, urls: { original: '/o', ...urls } })
|
||
assert.equal(videoState(v('waiting')), 'waiting')
|
||
assert.equal(videoState(v('working')), 'working')
|
||
assert.equal(videoState(v('done', { play: '/p' })), 'ready')
|
||
assert.equal(videoState(v('done')), 'asIs')
|
||
assert.equal(videoState(v('failed')), 'failed')
|
||
assert.equal(videoState(v(null)), null)
|
||
assert.equal(videoState({ kind: 'image', processing: null }), null)
|
||
assert.equal(preparing([v('done'), v('working')]), true)
|
||
assert.equal(preparing([v('done'), v('failed'), { kind: 'image' }]), false)
|
||
assert.equal(preparing(undefined), false)
|
||
})
|
||
|
||
test('a batch upload queue and its summary', () => {
|
||
const q = queueFrom([{ name: 'a.jpg' }, { name: 'b.jpg' }], 3)
|
||
assert.deepEqual(q.map(x => [x.key, x.status]), [['3:a.jpg', 'waiting'], ['4:b.jpg', 'waiting']])
|
||
assert.equal(queueSummary(q).busy, true)
|
||
const done = [{ ...q[0], status: 'added' }, { ...q[1], status: 'existing' }, { key: 'x', status: 'failed' }]
|
||
assert.deepEqual(queueSummary(done), { total: 3, added: 1, existing: 1, failed: 1, busy: false })
|
||
})
|
||
|
||
test('the Media page is for anyone who manages something with pictures', () => {
|
||
const page = pageFor('/management/media')
|
||
const access = keys => ({ modules: new Set(['core']), permissions: new Set(keys) })
|
||
assert.equal(canSee(page, access(['customer_display.manage'])), true)
|
||
assert.equal(canSee(page, access(['catalog.menu.manage'])), true)
|
||
assert.equal(canSee(page, access(['core.dashboard.access'])), false)
|
||
})
|