18 lines
1.1 KiB
JavaScript
18 lines
1.1 KiB
JavaScript
import { createHash } from 'node:crypto';
|
|
|
|
// Only these reviewed screenshots can leave the source repository.
|
|
export const screenshotSources = [
|
|
'docs/public/images/symcon-objektbaum.png',
|
|
'docs/public/images/symcon-manager.png'
|
|
];
|
|
|
|
export function screenshotInfo(source, data) {
|
|
if (!screenshotSources.includes(source) || !Buffer.isBuffer(data) || data.length < 45 || data.length > 4_000_000) throw new Error('Invalid screenshot source');
|
|
if (!data.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex')) || data.readUInt32BE(8) !== 13 || data.toString('ascii', 12, 16) !== 'IHDR' || data.toString('ascii', data.length - 8, data.length - 4) !== 'IEND') throw new Error('Expected PNG screenshot');
|
|
const width = data.readUInt32BE(16), height = data.readUInt32BE(20);
|
|
if (width < 100 || height < 100 || width > 5000 || height > 5000) throw new Error('Invalid screenshot dimensions');
|
|
const sha256 = createHash('sha256').update(data).digest('hex');
|
|
const stem = source.split('/').pop().replace(/\.png$/, '');
|
|
return { repo:'Enelix-EMS', source, output:`images/${stem}-${sha256.slice(0, 16)}.png`, width, height, sha256 };
|
|
}
|