Skip to content

Instantly share code, notes, and snippets.

@parthnvaswani
Created June 28, 2024 12:33
Show Gist options
  • Save parthnvaswani/81ccb1c978881008d2b07a0dc5715e3e to your computer and use it in GitHub Desktop.
Save parthnvaswani/81ccb1c978881008d2b07a0dc5715e3e to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
// File to get the error files from
const file = path.join(__dirname, 'media-import-caris-1718959862750.txt');
// Read the file
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
// Get the file locations with the error and store them in a JSON string
const errorFiles = data.match(/File Name: (.*)\n\nErrors:\n\t- Failed to upload file: Detected MIME type \( image\/(png|jpeg) \) does not match expected types for file (.*)\.webp/g);
const errorFilesArr = errorFiles.map((errorFile) => {
const fileName = errorFile.match(
/File Name: (.*)\n\nErrors:\n\t- Failed to upload file: Detected MIME type \( image\/(png|jpeg) \) does not match expected types for file (.*)\.webp/
);
return fileName[1];
});
const result = JSON.stringify(errorFilesArr, null, 4);
// Write the result to a file
fs.writeFile('error_files.json', result, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log('File created');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment