Filter files during scan

This commit is contained in:
LordMathis 2019-10-13 12:53:21 +02:00
parent 92bbcec4d0
commit e017e22582
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
2 changed files with 8 additions and 16 deletions

View File

@ -72,19 +72,6 @@ export class Scanner {
} }
} }
// init () {
// return new Promise((resolve, reject) => {
// jsonfile.readFile(config.dataPath, (err, data) => {
// if (err) {
// reject(err)
// } else {
// this.data = data
// resolve(data)
// }
// })
// })
// }
writeData (callback) { writeData (callback) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
jsonfile.writeFile(config.dataPath, this.data, (err, data) => { jsonfile.writeFile(config.dataPath, this.data, (err, data) => {
@ -114,7 +101,12 @@ export class Scanner {
scan () { scan () {
this.readdir(config.contentPath) this.readdir(config.contentPath)
.then( .then(
(files) => { return Promise.all(files.map(this.readfile)) } (files) => {
const filtered = files.filter(
(file) => fs.statSync(path.join(process.cwd(), config.contentPath, file)).isFile()
)
return Promise.all(filtered.map(this.readfile))
}
).then( ).then(
(files) => { (files) => {
files.forEach( files.forEach(