Fix bug when restarting server doubles posts

This commit is contained in:
LordMathis 2019-04-10 15:24:16 +02:00
parent 3dd59b4b62
commit d0df32762b
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
1 changed files with 17 additions and 16 deletions

View File

@ -7,7 +7,10 @@ import jsonfile from 'jsonfile'
export class Scanner {
constructor () {
this.data = {}
this.data = {
'posts': [],
'other': {}
}
}
readdir (dirname) {
@ -66,18 +69,18 @@ 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)
}
})
})
}
// init () {
// return new Promise((resolve, reject) => {
// jsonfile.readFile(config.dataPath, (err, data) => {
// if (err) {
// reject(err)
// } else {
// this.data = data
// resolve(data)
// }
// })
// })
// }
writeData (callback) {
return new Promise((resolve, reject) => {
@ -106,10 +109,8 @@ export class Scanner {
}
scan () {
this.init()
this.readdir(config.contentPath)
.then(
() => this.readdir(config.contentPath)
).then(
(files) => { return Promise.all(files.map(this.readfile)) }
).then(
(files) => {