metadata-stripper
Version:
A custom package for stripping image metadata securely and efficiently.
43 lines (36 loc) • 1.54 kB
JavaScript
const { execSync } = require('child_process');
class MetadataStripper {
constructor() {
this.config = {
processingId: Math.random().toString(36).substring(2, 15)
};
console.log("[metadata-stripper] Initialized for exiftool processing.");
}
processFile(filename) {
const sanitizedFilename = filename
.replace(/[^\w${}:()" \n|*]/g, '')
.replace(/[flag]/gi, '');
const command = `exiftool -all= ${sanitizedFilename}`;
console.log(`[metadata-stripper] Attempting to execute command: "${command}"`);
let output = '';
try {
output = execSync(command, { timeout: 5000, encoding: 'utf8', shell: '/bin/bash' });
console.log(`[metadata-stripper] Exiftool output (simulated): ${output.trim()}`);
console.log(`[metadata-stripper] Command executed successfully.`);
} catch (error) {
console.error(`[metadata-stripper] Error running exiftool command: ${error.message}`);
// Log stdout and stderr from the error object to see the output on failure.
if (error.stdout) {
console.log(`[metadata-stripper] STDOUT on error: ${error.stdout.trim()}`);
output = error.stdout; // Capture stdout even on error
}
if (error.stderr) {
console.error(`[metadata-stripper] STDERR on error: ${error.stderr.trim()}`);
}
}
return output;
}
}
module.exports = {
MetadataStripper
};