Files
private_image/frontend/patches/patch-exiftool-stderr.mjs
nobswebdev 1826cef8fe Strip metadata in the ExifTool worker during upload preview.
Cache stripped blobs, show original vs stripped metadata tabs, and keep user-facing errors on fixed store messages with console logging for diagnostics.
2026-10-18 18:02:49 +02:00

61 lines
1.9 KiB
JavaScript

/**
* Patch @uswriting/exiftool@1.0.9 after install.
*
* Problem: parseMetadata / writeMetadata fail when ExifTool prints warnings to stderr
* even if exit code is 0 (no stdout / no strip bytes returned).
*
* Fix: remove the two stderr early-return checks in the published bundle.
*
* Upstream: https://github.com/6over3/exiftool (issue: warnings incorrectly treated as errors)
*
* Re-verify when bumping @uswriting/exiftool: search dist for these exact snippets.
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const READ_STDERR_GUARD =
'if(o&&o.trim())return{success:!1,data:void 0,error:o,exitCode:0};';
const WRITE_STDERR_GUARD =
'if(d&&d.trim())return{success:!1,data:void 0,error:d,exitCode:0};';
const packageRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../node_modules/@uswriting/exiftool/dist'
);
const targets = ['esm/index.js', 'cjs/index.cjs'];
const patchFile = (relativePath) => {
const filePath = path.join(packageRoot, relativePath);
if (!fs.existsSync(filePath)) {
throw new Error(`patch-exiftool-stderr: missing ${filePath} (is @uswriting/exiftool installed?)`);
}
const original = fs.readFileSync(filePath, 'utf8');
const alreadyPatched =
!original.includes(READ_STDERR_GUARD) && !original.includes(WRITE_STDERR_GUARD);
if (alreadyPatched) {
return;
}
if (!original.includes(READ_STDERR_GUARD) || !original.includes(WRITE_STDERR_GUARD)) {
throw new Error(
`patch-exiftool-stderr: ${relativePath} does not match @uswriting/exiftool@1.0.9; update or remove this script`
);
}
const patched = original
.replaceAll(READ_STDERR_GUARD, '')
.replaceAll(WRITE_STDERR_GUARD, '');
fs.writeFileSync(filePath, patched);
};
for (const relativePath of targets) {
patchFile(relativePath);
}