|
@@ -16,7 +16,8 @@ const loggers_1 = require("./loggers");
|
|
|
const logger = loggers_1.getLogger('gifski');
|
|
|
const sizeLimit = 10 * Math.pow(2, 20);
|
|
|
const roundToEven = (n) => Math.ceil(n / 2) * 2;
|
|
|
-const isEmpty = (path) => fs_1.statSync(path).size === 0;
|
|
|
+const safeStatSync = (path) => !fs_1.existsSync(path) ? null : fs_1.statSync(path);
|
|
|
+const isEmptyNullable = (path) => !fs_1.existsSync(path) ? null : fs_1.statSync(path).size === 0;
|
|
|
function default_1(data, targetWidth) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
const outputFilePath = temp.path({ suffix: '.gif' });
|
|
@@ -32,11 +33,11 @@ function default_1(data, targetWidth) {
|
|
|
'-vn',
|
|
|
inputFile.path + '.mka',
|
|
|
]);
|
|
|
- if (fs_1.statSync(inputFile.path + '.mka').size === 0) {
|
|
|
- fs_1.unlinkSync(inputFile.path + '.mka');
|
|
|
- }
|
|
|
- else {
|
|
|
- logger.info(`extracted audio to ${inputFile.path + '.mka'}`);
|
|
|
+ switch (isEmptyNullable(inputFile.path + '.mka')) {
|
|
|
+ case true:
|
|
|
+ fs_1.unlinkSync(inputFile.path + '.mka');
|
|
|
+ break;
|
|
|
+ case false: logger.info(`extracted audio to ${inputFile.path + '.mka'}`);
|
|
|
}
|
|
|
logger.info(`saved video file to ${inputFile.path}, starting gif conversion...`);
|
|
|
const args = [
|
|
@@ -56,7 +57,8 @@ function default_1(data, targetWidth) {
|
|
|
const gifskiSpawn = child_process_1.spawn('gifski', args);
|
|
|
const gifskiResult = new Promise((resolve, reject) => {
|
|
|
const sizeChecker = setInterval(() => {
|
|
|
- if (fs_1.existsSync(outputFilePath) && fs_1.statSync(outputFilePath).size > sizeLimit)
|
|
|
+ var _a;
|
|
|
+ if (((_a = safeStatSync(outputFilePath)) === null || _a === void 0 ? void 0 : _a.size) > sizeLimit)
|
|
|
gifskiSpawn.kill();
|
|
|
}, 5000);
|
|
|
gifskiSpawn.on('exit', () => {
|
|
@@ -71,7 +73,7 @@ function default_1(data, targetWidth) {
|
|
|
'-c', 'copy',
|
|
|
outputFilePath + '.mkv',
|
|
|
]);
|
|
|
- if (isEmpty(outputFilePath + '.mkv'))
|
|
|
+ if (isEmptyNullable(outputFilePath + '.mkv'))
|
|
|
reject('remux to mkv failed');
|
|
|
logger.info(`mkv remuxing succeeded, file path: ${outputFilePath}.mkv`);
|
|
|
resolve(fs_1.readFileSync(outputFilePath + '.mkv').buffer);
|