From fe279c73e1bf82bdd3bedc2acf322cf36a1cc9a6 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Thu, 23 Jan 2025 00:39:25 -0800 Subject: [PATCH] Encode lastmod dates in `engine_files` Apropos #177 --- src/common/interface.ts | 1 + src/iplayif.com/app/src/front-page.ts | 1 + src/tools/index-processing.ts | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/src/common/interface.ts b/src/common/interface.ts index 6f683ec9..096dffd1 100644 --- a/src/common/interface.ts +++ b/src/common/interface.ts @@ -51,6 +51,7 @@ export interface ParchmentOptions extends Omit { theme_cookie: string, /** Whether to test the AsyncGlk GlkApi library */ use_asyncglk?: TruthyOption, + engine_files?: {[key: string]: string} // Modules to pass to other modules diff --git a/src/iplayif.com/app/src/front-page.ts b/src/iplayif.com/app/src/front-page.ts index a18ffd95..11811684 100644 --- a/src/iplayif.com/app/src/front-page.ts +++ b/src/iplayif.com/app/src/front-page.ts @@ -54,6 +54,7 @@ export default class FrontPage { const options: SingleFileOptions = { domain: `http${this.options.https ? 's' : ''}://${this.options.domain}`, + cdn_domain: this.options.cdn_domain, story: { author: data.author, cover: !!data.cover, diff --git a/src/tools/index-processing.ts b/src/tools/index-processing.ts index 543b80fb..9660e7e6 100644 --- a/src/tools/index-processing.ts +++ b/src/tools/index-processing.ts @@ -16,6 +16,7 @@ import {escape, truncate} from 'lodash-es' import type {TruthyOption} from '../upstream/asyncglk/src/index-common.js' import {Uint8Array_to_base64} from '../common/file.js' import type {FileSize, ParchmentOptions} from '../common/interface.js' +import {find_format} from '../common/formats.js' // Is ASCII really okay here? const utf8decoder = new TextDecoder('ascii', {fatal: true}) @@ -36,6 +37,7 @@ export interface Story { export interface SingleFileOptions { date?: TruthyOption domain?: string + cdn_domain?: string font?: TruthyOption gzip?: TruthyOption single_file?: TruthyOption @@ -99,6 +101,14 @@ export async function process_index_html(options: SingleFileOptions, files: Map< } if (story.format) { parchment_options.story.format = story.format + const {engines} = find_format(story.format) + if (engines) { + parchment_options.engine_files = Object.fromEntries(await Promise.all(engines[0].load.map(async (path) => { + const response = await fetch(`https://${options.cdn_domain}/dist/web/${path}`, {method: 'head'}) + const last_modified = response.headers.get('last-modified') ?? '' + return [path, Math.floor(new Date(last_modified).getTime()/1000)] + }))) + } } }