Deploy implemented Videoreg interface and persistent theme cycle

This commit is contained in:
huncode committed 2026-10-27 15:49:46 +03:00
1 parent 6405a8d101
commit a12eefa1de
98 files changed
+4094 -2319

No files matched your search

+26 -1
View File
@@ -1,12 +1,32 @@
/** Fully decode all raster pixels with npm-lockfile-pinned sharp; no network. */
import sharp from 'sharp';
import { realpath } from 'node:fs/promises';
import { realpath, readFile } from 'node:fs/promises';
import { resolve, sep } from 'node:path';
import { fileURLToPath } from 'node:url';
sharp.cache(false);
sharp.concurrency(1);
/** Decode every PNG-backed ICO directory member, not just its largest frame. */
export async function decodeIco(bytes) {
if (bytes.length < 6 || bytes.length > 25 * 1024 * 1024 || bytes.readUInt16LE(0) !== 0 || bytes.readUInt16LE(2) !== 1) throw new Error('Invalid ICO header');
const count = bytes.readUInt16LE(4), ranges = [], frames = [];
if (count < 1 || count > 64 || bytes.length < 6 + count * 16) throw new Error('Invalid ICO directory');
for (let i = 0; i < count; i++) {
const at = 6 + i * 16, width = bytes[at] || 256, height = bytes[at + 1] || 256;
const size = bytes.readUInt32LE(at + 8), offset = bytes.readUInt32LE(at + 12), end = offset + size;
if (size < 8 || offset < 6 + count * 16 || end > bytes.length || ranges.some(([a, b]) => offset < b && end > a)) throw new Error('Invalid ICO member bounds/overlap');
ranges.push([offset, end]);
const png = bytes.subarray(offset, end);
if (!png.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) throw new Error('ICO member must be PNG-backed; unsupported DIB is not skipped');
const image = sharp(png, { failOn: 'error', limitInputPixels: 65536 });
const { info } = await image.raw().toBuffer({ resolveWithObject: true });
if (info.width !== width || info.height !== height) throw new Error('ICO directory/pixels dimension mismatch');
frames.push({ width, height, decodedBytes: info.size });
}
return { width: Math.max(...frames.map(f => f.width)), height: Math.max(...frames.map(f => f.height)), format: 'ico', pages: count, decodedBytes: frames.reduce((n, f) => n + f.decodedBytes, 0), frames };
}
export async function decodeBatch({ root, files }) {
if (sharp.versions.sharp !== '0.34.5') {
throw new Error(`Expected lockfile sharp0.34.5, found ${sharp.versions.sharp}`);
@@ -20,6 +40,11 @@ export async function decodeBatch({ root, files }) {
try {
const candidate = await realpath(resolve(boundary, file));
if (!candidate.startsWith(boundary + sep)) throw new Error('Raster path outside public root');
if (candidate.toLowerCase().endsWith('.ico')) {
const decoded = await decodeIco(await readFile(candidate));
results.push({ file, type: 'raster', valid: true, ...decoded, decoder: `sharp${sharp.versions.sharp}/all-ICO-PNG-frames` });
continue;
}
const image = sharp(candidate, { failOn: 'error', animated: true, limitInputPixels: 64000000 });
const metadata = await image.metadata();
// metadata() alone is insufficient: force actual decode of every pixel.