fs-thumbnail
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -13,2 +13,4 @@ /** | ||
const Prefix = '[fs-thumbnail]'; | ||
// Load peer dependencies if they are available | ||
@@ -89,5 +91,5 @@ const LibNames = { | ||
if (!LibLoaded[libName]) return resolve(null); | ||
if (LibTries[libName] && !LibTries[libName].has(data.path, true)) resolve(null); | ||
console.log(LibTries[libName].has(data.path, true)); | ||
console.log(LibTries[libName] && !LibTries[libName].has(data.path, true)); | ||
if (LibTries[libName] && !LibTries[libName].hasWithCheckpoints(p, '.', true)) { | ||
return resolve(null); | ||
} | ||
@@ -98,6 +100,5 @@ const input = Libs[LibNames.sharp](p, {failOnError: false}); | ||
.jpeg({quality: q}) | ||
.toFile(o, err => { | ||
if (err) return reject(err); | ||
resolve(o); | ||
}); | ||
.toFile(o) | ||
.then(() => resolve(o)) | ||
.catch(reject); | ||
} catch (error) { | ||
@@ -143,15 +144,2 @@ reject(error); | ||
_resolveWithFallback(promise, fallback, name, data) { | ||
if (!promise) promise = Promise.resolve(); | ||
return promise | ||
.then(result => { | ||
if (result) return result; | ||
return fallback(data).catch(error => { | ||
if (this.verbose) console.error(`[fs-thumbnail] "${name}" failed. Reason: ${error.message}`); | ||
return fallback(data); | ||
}); | ||
}); | ||
} | ||
/** | ||
@@ -181,6 +169,18 @@ * @param {object} data | ||
let currPromise = null; | ||
let currPromise = Promise.resolve(); | ||
for (let i = 0; i < this.functionsToTry.length; ++i) { | ||
const func = this.functionsToTry[i]; | ||
currPromise = this._resolveWithFallback(currPromise, func, func.name, fullData); | ||
const name = func.name; | ||
currPromise = currPromise | ||
.then(result => { | ||
if (result) return result; | ||
return func(data) | ||
.then(result => { | ||
if (result) return result; | ||
console.warn(`${Prefix} "${name}" could not generate a thumbnail.`); | ||
}) | ||
.catch(err => console.error(`${Prefix} "${name}" failed. Reason: ${err.message}`)); | ||
}); | ||
} | ||
@@ -187,0 +187,0 @@ |
{ | ||
"name": "fs-thumbnail", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Library for generation of thumbnails based on file system paths.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha --recursive ./lib/" | ||
"test": "node ./test/generator-test.js" | ||
}, | ||
@@ -37,3 +37,3 @@ "repository": { | ||
"bluebird": "^3.5.5", | ||
"exact-trie": "^1.0.0", | ||
"exact-trie": "^1.0.2", | ||
"fluent-ffmpeg": "^2.1.2", | ||
@@ -40,0 +40,0 @@ "fs-extra": "^8.0.1" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
77934
8
0
193
Updatedexact-trie@^1.0.2