mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
Updates
* Updated utilsController.js: Unlink thumb of type symlink whenever generateThumbs() is called. * Updated thumbs.js: Add stats (success/error/skipped).
This commit is contained in:
parent
29f9187e92
commit
7587bfa408
@ -68,14 +68,25 @@ utilsController.generateThumbs = (name, force) => {
|
||||
return new Promise(resolve => {
|
||||
const extname = pce(name).toLowerCase()
|
||||
const thumbname = path.join(thumbsDir, name.slice(0, -extname.length) + '.png')
|
||||
fs.access(thumbname, error => {
|
||||
fs.lstat(thumbname, async (error, stats) => {
|
||||
if (error && error.code !== 'ENOENT') {
|
||||
console.error(error)
|
||||
return resolve(false)
|
||||
}
|
||||
|
||||
if (!error && stats.isSymbolicLink()) {
|
||||
// Unlink symlink
|
||||
const unlink = await new Promise((resolve, reject) => {
|
||||
fs.unlink(thumbname, error => {
|
||||
if (error) { return reject(error) }
|
||||
return resolve(true)
|
||||
})
|
||||
}).catch(console.error)
|
||||
if (!unlink) { return resolve(false) }
|
||||
}
|
||||
|
||||
// Only make thumbnail if it does not exist (ENOENT)
|
||||
if (!error && !force) { return resolve(true) }
|
||||
if (!error && !stats.isSymbolicLink() && !force) { return resolve(true) }
|
||||
|
||||
// If image extension
|
||||
if (utilsController.imageExtensions.includes(extname)) {
|
||||
|
@ -19,9 +19,9 @@ thumbs.getFiles = directory => {
|
||||
const files = []
|
||||
await Promise.all(names.map(name => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.lstat(path.join(directory, name), (error, stat) => {
|
||||
fs.lstat(path.join(directory, name), (error, stats) => {
|
||||
if (error) { return reject(error) }
|
||||
if (stat.isFile() && !name.startsWith('.')) { files.push(name) }
|
||||
if (stats.isFile() && !name.startsWith('.')) { files.push(name) }
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
@ -56,6 +56,9 @@ thumbs.do = async () => {
|
||||
return _thumb.slice(0, -extname.length)
|
||||
})
|
||||
|
||||
let success = 0
|
||||
let error = 0
|
||||
let skipped = 0
|
||||
await new Promise((resolve, reject) => {
|
||||
const generate = async i => {
|
||||
const _upload = _uploads[i]
|
||||
@ -66,16 +69,20 @@ thumbs.do = async () => {
|
||||
|
||||
if (_thumbs.includes(basename) && !thumbs.force) {
|
||||
if (thumbs.verbose) { console.log(`${_upload}: thumb exists.`) }
|
||||
skipped++
|
||||
} else if (!thumbs.mayGenerateThumb(extname)) {
|
||||
if (thumbs.verbose) { console.log(`${_upload}: extension skipped.`) }
|
||||
skipped++
|
||||
} else {
|
||||
const generated = await utils.generateThumbs(_upload, thumbs.force)
|
||||
console.log(`${_upload}: ${String(generated)}`)
|
||||
console.log(`${_upload}: ${generated ? 'OK' : 'ERROR'}`)
|
||||
generated ? success++ : error++
|
||||
}
|
||||
generate(i + 1)
|
||||
return generate(i + 1)
|
||||
}
|
||||
generate(0)
|
||||
return generate(0)
|
||||
})
|
||||
console.log(`Success: ${success}\nError: ${error}\nSkipped: ${skipped}`)
|
||||
}
|
||||
|
||||
thumbs.do()
|
||||
|
Loading…
Reference in New Issue
Block a user