Implemented file deletion from mongo

This commit is contained in:
LordMathis 2019-12-30 16:11:47 +01:00
parent 120fbaccd4
commit c0d14fe247
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
5 changed files with 20 additions and 33 deletions

View File

@ -18,8 +18,6 @@ export default class ContentContainer extends Component {
delete window.__INITIAL_DATA__
}
console.log('ContentContainer: ', data)
this.state = {
isLoading: !data,
type: data[0].type,

View File

@ -7,7 +7,6 @@ import mongoose from 'mongoose'
import jsonfile from 'jsonfile'
import { ServerRenderer } from './utils/serverRender'
import { Scanner } from './utils/scanner'
import { DataHolder } from './utils/dataHolder'
import { FileStorage } from './utils/storage/file'
import { MongoStorage } from './utils/storage/mongo'
@ -49,15 +48,14 @@ if (head == null) {
let storage
if (config.storage === 'file') {
storage = new FileStorage()
storage = new FileStorage(config)
} else if (config.storage === 'mongo') {
storage = new MongoStorage()
storage = new MongoStorage(config)
}
const dataHolder = new DataHolder(storage)
const scanner = new Scanner(config, dataHolder)
const scanner = new Scanner(config, storage)
const serverRenderer = new ServerRenderer(head, config, dataHolder)
const serverRenderer = new ServerRenderer(head, config, storage)
app.get('*', serverRenderer.render.bind(serverRenderer))
if (config.storage === 'mongo') {

View File

@ -1,22 +0,0 @@
export class DataHolder {
constructor (storage) {
this.storage = storage
}
addPost (post) {
this.storage.addPost(post)
}
addOther (filename, data) {
this.storage.addOther(filename, data)
}
deleteFile (filepath) {
this.storage.deleteFile(filepath)
}
getData (reqPath) {
return this.storage.getData(reqPath)
}
}

View File

@ -2,7 +2,8 @@ import fs from 'fs'
import path from 'path'
export class FileStorage {
constructor () {
constructor (config) {
this.config = config
this.data = {
posts: [],
other: {}

View File

@ -1,7 +1,9 @@
import mongoose, { Schema } from 'mongoose'
export class MongoStorage {
constructor () {
constructor (config) {
this.config = config
const PostSchema = new Schema({
filename: String,
published: String,
@ -49,7 +51,17 @@ export class MongoStorage {
}
deleteFile (filepath) {
//
const filename = filepath.split('/').pop()
const basename = filename.split('.')[0]
if (this.config['non-content-files'].indexOf(filename) === -1) {
this.Post.findOneAndDelete({ filename: basename }, (err) => {
if (err) throw err
})
} else {
this.Other.findOneAndDelete({ filename: basename }, (err) => {
if (err) throw err
})
}
}
getData (reqPath) {