Prepare for mongodb storage backend

This commit is contained in:
LordMathis 2019-12-08 16:31:47 +01:00
parent 1d621ea239
commit b53a7c3509
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
2 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import fs from 'fs'
import jsonfile from 'jsonfile'
import path from 'path'
import mongoose from 'mongoose'
export class DataHolder {
constructor (config) {
@ -11,6 +12,25 @@ export class DataHolder {
posts: [],
other: {}
}
} else if (this.config.storage === 'mongo') {
mongoose.connect(config.mongourl, { useNewUrlParser: true })
this.db = mongoose.connection
this.db.on('error', (error) => console.error(`[DataHolder] ${error}`))
this.db.once('open', () => console.log('[DataHolder] Connected to database'))
this.Post = mongoose.model('Post', {
filename: String,
published: String,
title: String,
summary: String,
link: String,
body: String
})
this.Other = mongoose.model('Other', {
filename: String,
body: String
})
}
}
@ -52,6 +72,7 @@ export class DataHolder {
}
addPost (post) {
delete post.body
this.data.posts.push(post)
}

View File

@ -99,7 +99,8 @@ export class Scanner {
filename: metadata.filename,
title: frontMatter.attributes.title,
summary: summary,
link: '/post/' + metadata.filename
link: '/post/' + metadata.filename,
body: frontMatter.body
}
this.dataHolder.addPost(post)