Complete major refactor

This commit is contained in:
Jerome Wu
2020-11-03 15:36:44 +08:00
parent 25f37fa00b
commit 265cf4c580
21 changed files with 248 additions and 239 deletions

View File

@@ -1,8 +1,6 @@
const defaultOptions = require('../constants/defaultOptions');
/*
* Default options for node environment
*/
module.exports = {
...defaultOptions,
corePath: '@ffmpeg/core',
};

View File

@@ -10,14 +10,21 @@ module.exports = async (_data) => {
}
if (typeof _data === 'string') {
if (isURL(_data) || _data.startsWith('chrome-extension://') || _data.startsWith('file://')) {
/* From remote URL/server */
if (isURL(_data)
|| _data.startsWith('moz-extension://')
|| _data.startsWith('chrome-extension://')
|| _data.startsWith('file://')) {
const res = await fetch(_data);
data = await res.arrayBuffer();
/* From base64 format */
} else if (/data:_data\/([a-zA-Z]*);base64,([^"]*)/.test(_data)) {
data = Buffer.from(_data.split(',')[1], 'base64');
/* From local file path */
} else {
data = await util.promisify(fs.readFile)(_data);
}
/* From Buffer */
} else if (Buffer.isBuffer(_data)) {
data = _data;
}

View File

@@ -0,0 +1,7 @@
const { log } = require('../utils/log');
module.exports = ({ corePath }) => new Promise((resolve) => {
log('info', `fetch ffmpeg.wasm-core script from ${corePath}`);
// eslint-disable-next-line import/no-dynamic-require
resolve(require(corePath));
});

View File

@@ -1,6 +0,0 @@
module.exports = () => new Promise((resolve) => {
const Module = require('@ffmpeg/core');
Module.onRuntimeInitialized = () => {
resolve(Module);
};
});

View File

@@ -1,9 +1,9 @@
const defaultOptions = require('./defaultOptions');
const getModule = require('./getModule');
const getCreateFFmpegCore = require('./getCreateFFmpegCore');
const fetchFile = require('./fetchFile');
module.exports = {
defaultOptions,
getModule,
getCreateFFmpegCore,
fetchFile,
};