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