From 99fc5e2ca1eb20356924c8b1f29d736f1b768c46 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 18:11:35 +0200 Subject: [PATCH 1/3] feat(author): a page's build leaves a video at its address, for a preview with no download first (#263) buildPackage of ./browser takes linked: the videos and recordings a source names that stay where they are, each by its name and the http(s) address it is played from. The content takes the address, as it takes a YouTube one, and none of the file's bytes are read. The result's linked lists the names, so a page knows the package is a preview. A file given under the same name goes before the address, which is how the package to keep is built. --- design/author.md | 12 ++++++ packages/author/README.md | 11 +++++- packages/author/lib/browser.mjs | 30 ++++++++++----- packages/author/lib/media.mjs | 45 ++++++++++++++++++++-- packages/author/tests/browser/page.test.ts | 26 +++++++++++++ packages/author/tests/page.test.ts | 43 +++++++++++++++++++++ packages/author/vitest.config.ts | 35 ++++++++++++++++- 7 files changed, 186 insertions(+), 16 deletions(-) diff --git a/design/author.md b/design/author.md index e8dcc445..549abbbb 100644 --- a/design/author.md +++ b/design/author.md @@ -255,6 +255,18 @@ text to the content check's rules, and `apps/skills` plays every example untrust and CRC in their local headers**, so the player reads each one's size off its header on a host without `Range`. The CRC is the normalizer's, through `./crc32`. An mp4 is not moved to start in a page: that is the normalizer's, in Node. + - **A page can leave a video or a recording at its address, for a preview** (#263). `linked` + names the file as the source does and gives the http(s) address it is played from: the content + takes the address, as it takes a YouTube one, with the type its name says, and none of its + bytes are read, so nothing of the file is checked and an Interactive Video's times are held + to no length. The result's `linked` lists the names: such a package is not one to keep, since + the address may stop answering, and a file given under the same name goes before the address, + which is how the package to keep is built. A picture or another file is refused: its size is + read from its bytes. The address is in no problem, since one that lets a file be read is not + for a log. Measured on 2026-11-23 with a 230 MB video on a chat app's file store: 9 min 13 s + to download and build before it played, 1.4 s to play from the address. The Chromium test + plays such a package untrusted from a server of another origin that sends no CORS header: + the content check leaves the address, and the player asks it for the file in parts. A page needs a secure context for `crypto.subtle` and `crypto.randomUUID`, and fetches media named by web address under CORS, which most image hosts refuse; the build says which where it diff --git a/packages/author/README.md b/packages/author/README.md index ede3f926..5d735e37 100644 --- a/packages/author/README.md +++ b/packages/author/README.md @@ -376,11 +376,18 @@ const { blob, notes } = await buildPackage(source, { libraries, files: { 'volga. Each part is fetched whole when a build first needs it, and checked against the index's SHA-256, as in Node. `close()` the pack when the page is done with it. -- `buildPackage(source, { libraries, files, fetch })` throws a `SourceError` as in Node, and returns - `{ blob, source, builtWith, manifest, content, libraries, install, coreApi, translations, notes, media }`, as in Node. Its options: +- `buildPackage(source, { libraries, files, linked, fetch })` throws a `SourceError` as in Node, and returns + `{ blob, source, builtWith, manifest, content, libraries, install, coreApi, translations, notes, media, linked }`, as in Node but for `linked`. Its options: - `libraries`: a pack `openPack` opened, or what to open one from for this build alone. - `files`: an object or a `Map` of the files a source names, by the names it gives them: `{ "path": "volga.png" }` takes `files['volga.png']`. + - `linked`: an object or a `Map` of the videos and recordings a source names that stay where + they are, each by its name and the http(s) address it is played from: + `linked: { 'clip.mp4': address }`. Nothing is downloaded and nothing of the file is checked, + so a large video plays at once, the browser asking the address for the parts it shows. The + result's `linked` lists those names: with one in it the package is a preview, not a file to + keep, since the address may stop answering. Build again with the file in `files`, which goes + before an address for the same name, for the package to hand over. - `fetch`: for media named by web address. - Media go in after the content and stored, each with its size and CRC in the header in front of it, as the player reads them on a host without `Range`; the libraries carried for an H5P site's diff --git a/packages/author/lib/browser.mjs b/packages/author/lib/browser.mjs index ae5bd41e..d8f8c21a 100644 --- a/packages/author/lib/browser.mjs +++ b/packages/author/lib/browser.mjs @@ -18,8 +18,9 @@ export * from './core.mjs' * as embed's SCORM writer stores its entries since #92, so that the player reads each one's size * off its header on a host without `Range`, and before the libraries carried for an H5P site's * upload check, as Node's build lays them out. An mp4's or an m4a's index is moved to the front, as - * the normalizer does in Node, by its plan (#218). It needs a secure context, https, localhost or - * a Tauri window, for `crypto.subtle` and `crypto.randomUUID`. + * the normalizer does in Node, by its plan (#218). A video or a recording can stay at a web address + * and be played from there, for a preview with no download first (`linked`, #263). It needs a + * secure context, https, localhost or a Tauri window, for `crypto.subtle` and `crypto.randomUUID`. */ /** @@ -28,17 +29,21 @@ export * from './core.mjs' * library with its part's URL * @typedef {{ * blob: Blob, source: import('./build.mjs').Source, builtWith: string, manifest: Record, content: Record, libraries: string[], install: string[], - * coreApi: import('./install.mjs').CoreApi, translations: import('./translate.mjs').TranslationReport[], notes: import('./build.mjs').Problem[], media: string[], outline: string + * coreApi: import('./install.mjs').CoreApi, translations: import('./translate.mjs').TranslationReport[], notes: import('./build.mjs').Problem[], media: string[], linked: string[], outline: string * }} BuildResult the package, and what is worth telling about it: `libraries`, the folders it plays * with; `install`, those it carries for an H5P site's upload check; `coreApi`, the newest H5P core * they ask for, which a site needs to take the package (`coreApiLine` says it); `outline`, the * content as text for a review (`outlineOf`); `builtWith`, the content type and the pack's version * of it, "H5P.Blanks 1.14", and `source`, the source as built, naming it: what to keep with the - * package, so that a build with a later pack can say the type has moved - * @typedef {{ libraries: Pack | PackIndex | string | URL, files?: Map | Record, fetch?: typeof fetch }} BuildOptions + * package, so that a build with a later pack can say the type has moved; `media`, the files it + * carries, and `linked`, the files the source names that were left at an address: where there is + * one, the package is a preview and not a file to keep, since the address may stop answering + * @typedef {{ libraries: Pack | PackIndex | string | URL, files?: Map | Record, linked?: Map | Record, fetch?: typeof fetch }} BuildOptions * `libraries`, a pack `openPack` opened, which a page keeps for its builds, or what to open one - * from; `files`, the files a source names, by the names it gives them; `fetch`, for media named by - * web address + * from; `files`, the files a source names, by the names it gives them; `linked`, the videos and + * recordings it names that stay where they are, each by its name and the http(s) address it is + * played from, none of its bytes read (#263), a file given under the same name going before it; + * `fetch`, for media named by web address */ /** What a page's build takes from the browser, which it has in a secure context only. */ @@ -102,11 +107,15 @@ export async function openPack(pack, { fetch: fetchImpl = globalThis.fetch } = { * A source's files in a page: the `File`s or `Blob`s it was given, by the names the source gives * them; downloads kept as `Blob`s. * @param {Map | Record} files + * @param {Map | Record} linked the files left at an address, by name * @returns {import('./media.mjs').MediaAccess} */ -function pageMedia(files) { +function pageMedia(files, linked) { const named = files instanceof Map ? files : new Map(Object.entries(files)) + const addresses = linked instanceof Map ? linked : new Map(Object.entries(linked)) return { + // A file given goes before an address for it: the bytes make a package to keep. + linked: (source) => (named.has(source) ? undefined : addresses.get(source)), what: 'the name of a file given', name: (source) => source.slice(source.lastIndexOf('/') + 1), async local(source) { @@ -178,14 +187,14 @@ const pageFetch = (input, init) => globalThis.fetch(input, init).catch((error) = */ export async function buildPackage(input, options) { secure() - const { libraries, files = {}, fetch: fetchImpl = pageFetch } = options ?? {} + const { libraries, files = {}, linked = {}, fetch: fetchImpl = pageFetch } = options ?? {} if (!libraries) throw new TypeError('Name the library pack: a pack openPack opened, the pack export of @missing-elements/h5p-libraries, or the address of a copy of its parts/ folder') const pack = libraries instanceof Pack ? libraries : await openPack(libraries) try { // With the pack's names, as the command's build reads a source (#174). const read = sourceOf(input, typeNames(pack)) if (!read.typed) throw new SourceError(read.problems) - const media = new MediaStore(pageMedia(files), { fetch: fetchImpl }) + const media = new MediaStore(pageMedia(files, linked), { fetch: fetchImpl }) const built = await composePackage(read.source, pack, media, read.problems) const writer = new ZipWriter(new BlobWriter('application/zip'), { useWebWorkers: false }) await writePackage(writer, built, pack, async () => { @@ -207,6 +216,7 @@ export async function buildPackage(input, options) { translations: built.translations, notes: built.notes, media: media.files.map((item) => item.name), + linked: [...media.linked], get outline() { return built.outline } } } finally { diff --git a/packages/author/lib/media.mjs b/packages/author/lib/media.mjs index a39b0226..55b7d55d 100644 --- a/packages/author/lib/media.mjs +++ b/packages/author/lib/media.mjs @@ -9,7 +9,8 @@ import { escapeText } from './text.mjs' * H5P's editor embeds it (h5peditor-av.js, its `providers`), at an address H5P.Video plays. Where * the files are, and where a download is kept, is the environment's (`MediaAccess`): `node.mjs` * reads them from disk and keeps downloads in a temporary folder, `browser.mjs` takes `File`s and - * keeps downloads as `Blob`s. + * keeps downloads as `Blob`s. A page can also name a video or a recording that stays at a web + * address of its own and is played from there (`linked`, #263): a preview, with no download first. */ /** The types H5P accepts for content (`H5PCore::$defaultContentWhitelist`), by what a field takes. */ @@ -186,11 +187,13 @@ const IDLE_MS = 60_000 * name(source: string): string, * local(source: string): Promise<{ file: F } | { missing: string }>, * keep(body: ReadableStream, extension: string): Promise, - * open(file: F): Promise<{ size: number, read(offset: number, length: number): Promise, close(): Promise }> + * open(file: F): Promise<{ size: number, read(offset: number, length: number): Promise, close(): Promise }>, + * linked?(source: string): string | undefined * }} MediaAccess * `what`, what a source's path names, for problems; `name`, the file's own name it names; * `local`, that file, or why there is none; `keep`, a download's bytes kept; `open`, a kept - * file's length, and its bytes read from an offset, fewer at its end + * file's length, and its bytes read from an offset, fewer at its end; `linked`, the web address + * a file the source names stays at and is played from, where it has one (#263) */ /** @@ -314,6 +317,8 @@ export class MediaStore { this.asked = new Map() /** @type {Set} the hosts that gave no answer at all, none of which is asked again in this build */ this.unanswered = new Set() + /** @type {string[]} the files left at an address and played from there, as the source names them (#263) */ + this.linked = [] } /** @@ -360,6 +365,8 @@ export class MediaStore { return { path: source, copyright } } const types = /** @type {Record} */ (TYPES[kind]) + const address = web ? undefined : this.access.linked?.(source) + if (address !== undefined) return { ...this.#linked(kind, source, address, types, at, report), copyright } const key = `${kind} ${source}` let known = this.known.get(key) if (!known) { @@ -486,6 +493,38 @@ export class MediaStore { return { from: found.file, extension, stem: name.slice(0, name.length - extension.length - 1) } } + /** + * A file left at a web address of its own and played from there (#263), as a video on YouTube + * is: a video or a recording only, since a picture's size is read from its bytes, its type taken + * from the name the source gives it. None of its bytes are read, so nothing of it is checked, and + * the package is a preview: the address may stop answering. The address is in no problem, since + * one that lets a file be read is not for a log. + * @param {string} kind + * @param {string} source + * @param {string} address + * @param {Record} types + * @param {string} at + * @param {(path: string, message: string) => void} report + * @returns {{ path: string, mime?: string }} + */ + #linked(kind, source, address, types, at, report) { + if (kind !== 'video' && kind !== 'audio') { + report(`${at}.path`, `${source}: only a video or a recording is played from an address; give the file itself`) + return { path: source } + } + const extension = extensionOf(this.access.name(source)) + if (!Object.hasOwn(types, extension)) { + report(`${at}.path`, `${source}: this field takes ${Object.keys(types).map((each) => `.${each}`).join(', ')}`) + return { path: source } + } + if (typeof address !== 'string' || !/^https?:\/\//i.test(address) || !URL.canParse(address)) { + report(`${at}.path`, `${source}: the address it is played from is not an http(s) address`) + return { path: source } + } + if (!this.linked.includes(source)) this.linked.push(source) + return { path: address, mime: types[extension] } + } + /** * Whether a host has a video, asked of its oEmbed endpoint where it has one (#218): an address * holds to its form only, so a made-up id built and showed a dead player. What an answer means diff --git a/packages/author/tests/browser/page.test.ts b/packages/author/tests/browser/page.test.ts index 74657cfd..bcd7164d 100644 --- a/packages/author/tests/browser/page.test.ts +++ b/packages/author/tests/browser/page.test.ts @@ -16,6 +16,8 @@ declare module 'vitest/browser' { verdict: 'pass' | 'fail', reasons: string[], warnings: string[], errors: unknown[], state: string, untrusted: boolean, contentCheck: { notes: string[], changes: unknown[] | null } | null }> + serveClip: (base64: string) => Promise + clipAsked: () => Promise } } @@ -109,4 +111,28 @@ describe('the build in a page', () => { await libraries.close() } }) + + it('plays a video left at its address from there, untrusted, the player asking the address for it in parts (#263)', async () => { + const libraries = await openPack(pack) + // A server of another origin that sends no CORS header, as a file store answers a video element. + const address = await commands.serveClip(await base64(new Blob([mp4(true, { seconds: 30, tracks: [['vide', 'avc1']] })]))) + try { + const built = await buildPackage({ + ...META, + type: 'H5P.InteractiveVideo', + params: { interactiveVideo: { video: { files: [{ path: 'clip.mp4' }] }, assets: { interactions: [{ duration: { from: 5, to: 7 }, label: 'Look', action: { library: 'H5P.Text', params: { text: 'Look' } } }] } } } + }, { libraries, linked: { 'clip.mp4': address } }) + expect(built.linked).toEqual(['clip.mp4']) + expect(built.media).toEqual([]) + expect((built.content as any).interactiveVideo.video.files[0]).toMatchObject({ path: address, mime: 'video/mp4' }) + const report = await commands.playUntrusted('linked.h5p', await base64(built.blob)) + expect(report).toMatchObject({ verdict: 'pass', reasons: [], state: 'ready', untrusted: true }) + // The content check leaves the address as it is. + expect(report.contentCheck).toEqual({ notes: [], changes: [] }) + expect(await commands.clipAsked()).toContainEqual(expect.stringMatching(/^bytes=0-/)) + } finally { + await commands.clipAsked() + await libraries.close() + } + }) }) diff --git a/packages/author/tests/page.test.ts b/packages/author/tests/page.test.ts index 63ba9011..fb8897c7 100644 --- a/packages/author/tests/page.test.ts +++ b/packages/author/tests/page.test.ts @@ -10,6 +10,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' import { buildPackage as buildInNode } from '../lib/author.mjs' import { buildPackage, openPack, SourceError } from '../lib/browser.mjs' import { png } from './helpers/media' +import { mp4 } from './helpers/mp4' // The page's build, run in Node with the pack's parts read from disk as a page fetches them from // its server. tests/browser/ runs it in Chromium and plays what it writes. @@ -32,6 +33,11 @@ const QUIZ = { }] } } +const VIDEO = (path: string, from = 5) => ({ + ...META, + type: 'H5P.InteractiveVideo', + params: { interactiveVideo: { video: { files: [{ path }] }, assets: { interactions: [{ duration: { from, to: from + 2 }, label: 'Look', action: { library: 'H5P.Text', params: { text: 'Look' } } }] } } } +}) let dir: string let opened: Awaited> let fetched: string[] @@ -139,6 +145,43 @@ describe('the build in a page', () => { ]) }) + it('leaves a video at the address a page names for it, played from there with none of its bytes read: a preview (#263)', async () => { + const address = 'https://files.example/a/clip.mp4?se=2026-11-23&sig=abc' + const asked = vi.fn(async () => { throw new Error('asked for') }) + // An interaction far past any length builds: nothing of the file is read, so nothing is held to it. + const built = await buildPackage(VIDEO('clip.mp4', 4000), { libraries: opened, linked: { 'clip.mp4': address }, fetch: asked }) + expect((built.content as any).interactiveVideo.video.files).toEqual([{ path: address, mime: 'video/mp4', copyright: { license: 'U' } }]) + expect(built.linked).toEqual(['clip.mp4']) + expect(built.media).toEqual([]) + expect(built.notes).toEqual([]) + expect(asked).not.toHaveBeenCalled() + const { entries } = await archive(new Uint8Array(await built.blob.arrayBuffer())) + expect(entries.filter(({ filename }) => /^content\/(?:videos|audios|images|files)\//.test(filename))).toEqual([]) + // A file given under the name goes before the address: the package to keep is made of its bytes. + const clip = new File([mp4(false, { seconds: 30, tracks: [['vide', 'avc1'], ['soun', 'mp4a']] })], 'clip.mp4') + const kept = await buildPackage(VIDEO('clip.mp4'), { libraries: opened, files: { 'clip.mp4': clip }, linked: new Map([['clip.mp4', address]]) }) + expect(kept.linked).toEqual([]) + expect(kept.media).toEqual(['videos/clip.mp4']) + expect((kept.content as any).interactiveVideo.video.files[0]).toMatchObject({ path: 'videos/clip.mp4', mime: 'video/mp4' }) + }) + + it('refuses a picture left at an address, a name its field does not take and what is no web address, the address in no problem (#263)', async () => { + const address = 'https://files.example/a/secret.png?sig=abc' + expect(await problems(QUIZ, { libraries: opened, linked: { 'volga.png': address } })).toEqual([ + 'params.questions[0].params.media.type.params.file.path: volga.png: only a video or a recording is played from an address; give the file itself' + ]) + expect(await problems(VIDEO('clip.mov'), { libraries: opened, linked: { 'clip.mov': address } })).toEqual([ + 'params.interactiveVideo.video.files[0].path: clip.mov: this field takes .mp4, .webm, .ogg' + ]) + expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'clip.mp4': 'blob:https://files.example/1b2c' } })).toEqual([ + 'params.interactiveVideo.video.files[0].path: clip.mp4: the address it is played from is not an http(s) address' + ]) + // A name with no address is a file the page did not give, as before. + expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'other.mp4': address } })).toEqual([ + 'params.interactiveVideo.video.files[0].path: clip.mp4: no such file among those given (none)' + ]) + }) + it('fetches each part once for a pack it was given, which stays open; one it was named it opens and closes', async () => { const before = fetched.length await buildPackage(BLANKS, { libraries: opened }) diff --git a/packages/author/vitest.config.ts b/packages/author/vitest.config.ts index e3be2b59..17f86316 100644 --- a/packages/author/vitest.config.ts +++ b/packages/author/vitest.config.ts @@ -1,4 +1,7 @@ +import { once } from 'node:events' import { mkdtemp, rm, writeFile } from 'node:fs/promises' +import { createServer, type Server } from 'node:http' +import type { AddressInfo } from 'node:net' import { tmpdir } from 'node:os' import { join, resolve } from 'node:path' import { verifyPackage } from '@missing-elements/h5p-verify' @@ -26,6 +29,36 @@ const playUntrusted: BrowserCommand<[name: string, base64: string]> = async (_co } } +/** + * A video at a web address of its own, for a build that leaves it there (#263): a server on another + * origin than the player's, answering for a part of the file and sending no CORS header, as a file + * store answers a video element. `serveClip` starts it with the bytes and gives the address, + * `clipAsked` gives the `Range` of each request it got and stops it. + */ +let clip: { server: Server, asked: string[] } | undefined +const serveClip: BrowserCommand<[base64: string]> = async (_context, base64) => { + const bytes = Buffer.from(base64, 'base64') + const asked: string[] = [] + const server = createServer((request, response) => { + asked.push(request.headers.range ?? 'whole') + const range = /^bytes=(\d+)-(\d*)$/.exec(request.headers.range ?? '') + const head = { 'content-type': 'video/mp4', 'accept-ranges': 'bytes' } + if (!range) return void response.writeHead(200, { ...head, 'content-length': bytes.length }).end(bytes) + const start = Number(range[1]) + const end = range[2] ? Math.min(Number(range[2]), bytes.length - 1) : bytes.length - 1 + response.writeHead(206, { ...head, 'content-range': `bytes ${start}-${end}/${bytes.length}`, 'content-length': end - start + 1 }).end(bytes.subarray(start, end + 1)) + }).listen(0, '127.0.0.1') + await once(server, 'listening') + clip = { server, asked } + return `http://127.0.0.1:${(server.address() as AddressInfo).port}/clip.mp4?sig=abc` +} +const clipAsked: BrowserCommand<[]> = async () => { + const asked = clip?.asked ?? [] + clip?.server.close() + clip = undefined + return asked +} + export default defineConfig({ test: { projects: [ @@ -61,7 +94,7 @@ export default defineConfig({ headless: true, provider: playwright(), instances: [{ browser: 'chromium' }], - commands: { playUntrusted } + commands: { playUntrusted, serveClip, clipAsked } } } } From 379bdf10c9a2cb11fbf5b30f17dc1e0f59e9c01a Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 18:23:57 +0200 Subject: [PATCH 2/3] fix(author): a linked address on a video host is refused, the Range the address needs is said, and the test plays a real video with no warning (#263) From the review: an address on YouTube, Vimeo, Panopto or Echo360 given as a file's is refused, since the source names such a video itself, where its form is checked; the README and the design say that a video starts at once only where the address answers for a part of the file; the design says plainly that only a video or a recording can be left at an address and that no problem quotes the address; the Chromium test serves the demo's real video, so the report is held to no warning and no error; the test server answers 416 past the end. --- design/author.md | 14 +++++++++----- packages/author/README.md | 5 ++++- packages/author/lib/media.mjs | 10 ++++++++-- packages/author/tests/browser/page.test.ts | 9 +++++---- packages/author/tests/page.test.ts | 4 ++++ packages/author/vitest.config.ts | 13 ++++++++----- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/design/author.md b/design/author.md index 549abbbb..02df5ea0 100644 --- a/design/author.md +++ b/design/author.md @@ -261,11 +261,15 @@ text to the content check's rules, and `apps/skills` plays every example untrust bytes are read, so nothing of the file is checked and an Interactive Video's times are held to no length. The result's `linked` lists the names: such a package is not one to keep, since the address may stop answering, and a file given under the same name goes before the address, - which is how the package to keep is built. A picture or another file is refused: its size is - read from its bytes. The address is in no problem, since one that lets a file be read is not - for a log. Measured on 2026-11-23 with a 230 MB video on a chat app's file store: 9 min 13 s - to download and build before it played, 1.4 s to play from the address. The Chromium test - plays such a package untrusted from a server of another origin that sends no CORS header: + which is how the package to keep is built. Only a video or a recording can be left at an + address: a picture or another file is refused and must be given as a file. So is an address + on YouTube, Vimeo, Panopto or Echo360, which the source names itself, where its form is + checked. No problem or note quotes the address, and nothing logs it: it can be one that lets + whoever has it read the file. Measured on 2026-11-23 with a 230 MB video on a chat app's file + store: 9 min 13 s to download and build before it played, 1.4 s to play from the address, + which has to answer a request for a part of the file (`Range`) for a video to start at once + and be jumped in. The Chromium test plays such a package untrusted from a server of another + origin that sends no CORS header: the content check leaves the address, and the player asks it for the file in parts. A page needs a secure context for `crypto.subtle` and `crypto.randomUUID`, and fetches media diff --git a/packages/author/README.md b/packages/author/README.md index 5d735e37..76cdbb25 100644 --- a/packages/author/README.md +++ b/packages/author/README.md @@ -384,7 +384,10 @@ const { blob, notes } = await buildPackage(source, { libraries, files: { 'volga. - `linked`: an object or a `Map` of the videos and recordings a source names that stay where they are, each by its name and the http(s) address it is played from: `linked: { 'clip.mp4': address }`. Nothing is downloaded and nothing of the file is checked, - so a large video plays at once, the browser asking the address for the parts it shows. The + so a large video plays at once where the address answers a request for a part of the file + (HTTP `Range`), the browser asking for the parts it shows; where it does not, the video plays + as its bytes arrive and cannot be jumped ahead in. An address on YouTube, Vimeo, Panopto or + Echo360 is refused here: the source names such a video itself. The result's `linked` lists those names: with one in it the package is a preview, not a file to keep, since the address may stop answering. Build again with the file in `files`, which goes before an address for the same name, for the package to hand over. diff --git a/packages/author/lib/media.mjs b/packages/author/lib/media.mjs index 55b7d55d..35876dee 100644 --- a/packages/author/lib/media.mjs +++ b/packages/author/lib/media.mjs @@ -497,8 +497,9 @@ export class MediaStore { * A file left at a web address of its own and played from there (#263), as a video on YouTube * is: a video or a recording only, since a picture's size is read from its bytes, its type taken * from the name the source gives it. None of its bytes are read, so nothing of it is checked, and - * the package is a preview: the address may stop answering. The address is in no problem, since - * one that lets a file be read is not for a log. + * the package is a preview: the address may stop answering. An address on YouTube, Vimeo, Panopto + * or Echo360 is no file's: the source names such a video itself, where its form is checked. No + * problem quotes the address: it can be one that lets whoever has it read the file. * @param {string} kind * @param {string} source * @param {string} address @@ -521,6 +522,11 @@ export class MediaStore { report(`${at}.path`, `${source}: the address it is played from is not an http(s) address`) return { path: source } } + const hosted = HOSTED.find(({ on }) => on(new URL(address))) + if (hosted) { + report(`${at}.path`, `${source}: the address it is played from is on ${hosted.host}, whose player shows a video, not a file; write the video's address there as the path instead`) + return { path: source } + } if (!this.linked.includes(source)) this.linked.push(source) return { path: address, mime: types[extension] } } diff --git a/packages/author/tests/browser/page.test.ts b/packages/author/tests/browser/page.test.ts index bcd7164d..e184985e 100644 --- a/packages/author/tests/browser/page.test.ts +++ b/packages/author/tests/browser/page.test.ts @@ -16,7 +16,7 @@ declare module 'vitest/browser' { verdict: 'pass' | 'fail', reasons: string[], warnings: string[], errors: unknown[], state: string, untrusted: boolean, contentCheck: { notes: string[], changes: unknown[] | null } | null }> - serveClip: (base64: string) => Promise + serveClip: () => Promise clipAsked: () => Promise } } @@ -114,8 +114,9 @@ describe('the build in a page', () => { it('plays a video left at its address from there, untrusted, the player asking the address for it in parts (#263)', async () => { const libraries = await openPack(pack) - // A server of another origin that sends no CORS header, as a file store answers a video element. - const address = await commands.serveClip(await base64(new Blob([mp4(true, { seconds: 30, tracks: [['vide', 'avc1']] })]))) + // A real video on a server of another origin that sends no CORS header, as a file store answers a + // video element: the verifier warns of a video that does not play, and it says nothing here. + const address = await commands.serveClip() try { const built = await buildPackage({ ...META, @@ -126,7 +127,7 @@ describe('the build in a page', () => { expect(built.media).toEqual([]) expect((built.content as any).interactiveVideo.video.files[0]).toMatchObject({ path: address, mime: 'video/mp4' }) const report = await commands.playUntrusted('linked.h5p', await base64(built.blob)) - expect(report).toMatchObject({ verdict: 'pass', reasons: [], state: 'ready', untrusted: true }) + expect(report).toMatchObject({ verdict: 'pass', reasons: [], warnings: [], errors: [], state: 'ready', untrusted: true }) // The content check leaves the address as it is. expect(report.contentCheck).toEqual({ notes: [], changes: [] }) expect(await commands.clipAsked()).toContainEqual(expect.stringMatching(/^bytes=0-/)) diff --git a/packages/author/tests/page.test.ts b/packages/author/tests/page.test.ts index fb8897c7..764e295e 100644 --- a/packages/author/tests/page.test.ts +++ b/packages/author/tests/page.test.ts @@ -176,6 +176,10 @@ describe('the build in a page', () => { expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'clip.mp4': 'blob:https://files.example/1b2c' } })).toEqual([ 'params.interactiveVideo.video.files[0].path: clip.mp4: the address it is played from is not an http(s) address' ]) + // A video on a host with a player of its own is named in the source, where its form is checked. + expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'clip.mp4': 'https://www.youtube.com/shorts/abcdefghijk?sig=abc' } })).toEqual([ + 'params.interactiveVideo.video.files[0].path: clip.mp4: the address it is played from is on YouTube, whose player shows a video, not a file; write the video\'s address there as the path instead' + ]) // A name with no address is a file the page did not give, as before. expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'other.mp4': address } })).toEqual([ 'params.interactiveVideo.video.files[0].path: clip.mp4: no such file among those given (none)' diff --git a/packages/author/vitest.config.ts b/packages/author/vitest.config.ts index 17f86316..e71d3a62 100644 --- a/packages/author/vitest.config.ts +++ b/packages/author/vitest.config.ts @@ -1,5 +1,5 @@ import { once } from 'node:events' -import { mkdtemp, rm, writeFile } from 'node:fs/promises' +import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { createServer, type Server } from 'node:http' import type { AddressInfo } from 'node:net' import { tmpdir } from 'node:os' @@ -32,12 +32,14 @@ const playUntrusted: BrowserCommand<[name: string, base64: string]> = async (_co /** * A video at a web address of its own, for a build that leaves it there (#263): a server on another * origin than the player's, answering for a part of the file and sending no CORS header, as a file - * store answers a video element. `serveClip` starts it with the bytes and gives the address, - * `clipAsked` gives the `Range` of each request it got and stops it. + * store answers a video element. The video is the demo's, a real one, since the verifier warns of + * one that does not play. `serveClip` starts the server and gives the address, `clipAsked` gives + * the `Range` of each request it got and stops it. */ +const clipFile = resolve(import.meta.dirname, '../../apps/demo/demo/content/src/video/videos/big-buck-bunny.mp4') let clip: { server: Server, asked: string[] } | undefined -const serveClip: BrowserCommand<[base64: string]> = async (_context, base64) => { - const bytes = Buffer.from(base64, 'base64') +const serveClip: BrowserCommand<[]> = async () => { + const bytes = await readFile(clipFile) const asked: string[] = [] const server = createServer((request, response) => { asked.push(request.headers.range ?? 'whole') @@ -46,6 +48,7 @@ const serveClip: BrowserCommand<[base64: string]> = async (_context, base64) => if (!range) return void response.writeHead(200, { ...head, 'content-length': bytes.length }).end(bytes) const start = Number(range[1]) const end = range[2] ? Math.min(Number(range[2]), bytes.length - 1) : bytes.length - 1 + if (start > end) return void response.writeHead(416, { 'content-range': `bytes */${bytes.length}` }).end() response.writeHead(206, { ...head, 'content-range': `bytes ${start}-${end}/${bytes.length}`, 'content-length': end - start + 1 }).end(bytes.subarray(start, end + 1)) }).listen(0, '127.0.0.1') await once(server, 'listening') From ec776043b1c65a82a97606d1d162eeeac6bf6872 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Mon, 23 Nov 2026 18:36:59 +0200 Subject: [PATCH 3/3] fix(author): the refusal of a video host's address says the form to write, and the test's video is named apart from the server's comment (#263) --- packages/author/lib/media.mjs | 2 +- packages/author/tests/page.test.ts | 2 +- packages/author/vitest.config.ts | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/author/lib/media.mjs b/packages/author/lib/media.mjs index 35876dee..b068ebaa 100644 --- a/packages/author/lib/media.mjs +++ b/packages/author/lib/media.mjs @@ -524,7 +524,7 @@ export class MediaStore { } const hosted = HOSTED.find(({ on }) => on(new URL(address))) if (hosted) { - report(`${at}.path`, `${source}: the address it is played from is on ${hosted.host}, whose player shows a video, not a file; write the video's address there as the path instead`) + report(`${at}.path`, `${source}: the address it is played from is on ${hosted.host}, whose player shows a video, not a file; give ${hosted.form} as the path instead`) return { path: source } } if (!this.linked.includes(source)) this.linked.push(source) diff --git a/packages/author/tests/page.test.ts b/packages/author/tests/page.test.ts index 764e295e..cdd58f25 100644 --- a/packages/author/tests/page.test.ts +++ b/packages/author/tests/page.test.ts @@ -178,7 +178,7 @@ describe('the build in a page', () => { ]) // A video on a host with a player of its own is named in the source, where its form is checked. expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'clip.mp4': 'https://www.youtube.com/shorts/abcdefghijk?sig=abc' } })).toEqual([ - 'params.interactiveVideo.video.files[0].path: clip.mp4: the address it is played from is on YouTube, whose player shows a video, not a file; write the video\'s address there as the path instead' + 'params.interactiveVideo.video.files[0].path: clip.mp4: the address it is played from is on YouTube, whose player shows a video, not a file; give https://www.youtube.com/watch?v= and the video\'s id as the path instead' ]) // A name with no address is a file the page did not give, as before. expect(await problems(VIDEO('clip.mp4'), { libraries: opened, linked: { 'other.mp4': address } })).toEqual([ diff --git a/packages/author/vitest.config.ts b/packages/author/vitest.config.ts index e71d3a62..a7415ade 100644 --- a/packages/author/vitest.config.ts +++ b/packages/author/vitest.config.ts @@ -29,14 +29,15 @@ const playUntrusted: BrowserCommand<[name: string, base64: string]> = async (_co } } +/** The demo's video, a real one: the verifier warns of one that does not play. */ +const clipFile = resolve(import.meta.dirname, '../../apps/demo/demo/content/src/video/videos/big-buck-bunny.mp4') + /** * A video at a web address of its own, for a build that leaves it there (#263): a server on another * origin than the player's, answering for a part of the file and sending no CORS header, as a file - * store answers a video element. The video is the demo's, a real one, since the verifier warns of - * one that does not play. `serveClip` starts the server and gives the address, `clipAsked` gives - * the `Range` of each request it got and stops it. + * store answers a video element. `serveClip` starts the server and gives the address, `clipAsked` + * gives the `Range` of each request it got and stops it. */ -const clipFile = resolve(import.meta.dirname, '../../apps/demo/demo/content/src/video/videos/big-buck-bunny.mp4') let clip: { server: Server, asked: string[] } | undefined const serveClip: BrowserCommand<[]> = async () => { const bytes = await readFile(clipFile)