Skip to content

Commit

Permalink
Added file transformer that bridges the gap between multer and mime-t…
Browse files Browse the repository at this point in the history
…ypes.
  • Loading branch information
NotTimTam committed Sep 13, 2024
1 parent 6f95080 commit c77a131
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nottimtam/file-converter",
"version": "1.2.15",
"version": "1.2.16",
"description": "A headless, self-hostable, open-source file conversion express middleware.",
"main": "index.js",
"type": "module",
Expand Down
16 changes: 14 additions & 2 deletions util/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ export default class Job {
return { ...defaults, ...options };
}

/**
* Does necessary transformations to bridge the gap between multer and mime-types.
* @param {Array<Object>} files The multer file references for the files this job will convert.
* @returns {Array<Object>} The transformed files.
*/
static __transformFiles = (files) =>
files.map((file) => {
if (file.mimetype === "video/avi")
file.mimetype = "video/x-msvideo";

return file;
});

/**
* Run the job.
* @param {function} onStep An optional asynchronous callback to run when each step of the job is complete.
*
* `onStep` is passed one argument, the job's `status` property.
*/
async run(onStep) {
Expand All @@ -94,7 +106,7 @@ export default class Job {

try {
await module.convert(
files,
Job.__transformFiles(files),
async ({ size }) => {
fileConverter.stats.dataConverted += size / 1e6;
fileConverter.stats.filesConverted++;
Expand Down

0 comments on commit c77a131

Please sign in to comment.