Implemented file deletion from mongo
This commit is contained in:
parent
120fbaccd4
commit
c0d14fe247
|
@ -18,8 +18,6 @@ export default class ContentContainer extends Component {
|
||||||
delete window.__INITIAL_DATA__
|
delete window.__INITIAL_DATA__
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('ContentContainer: ', data)
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isLoading: !data,
|
isLoading: !data,
|
||||||
type: data[0].type,
|
type: data[0].type,
|
||||||
|
|
|
@ -7,7 +7,6 @@ import mongoose from 'mongoose'
|
||||||
import jsonfile from 'jsonfile'
|
import jsonfile from 'jsonfile'
|
||||||
import { ServerRenderer } from './utils/serverRender'
|
import { ServerRenderer } from './utils/serverRender'
|
||||||
import { Scanner } from './utils/scanner'
|
import { Scanner } from './utils/scanner'
|
||||||
import { DataHolder } from './utils/dataHolder'
|
|
||||||
import { FileStorage } from './utils/storage/file'
|
import { FileStorage } from './utils/storage/file'
|
||||||
import { MongoStorage } from './utils/storage/mongo'
|
import { MongoStorage } from './utils/storage/mongo'
|
||||||
|
|
||||||
|
@ -49,15 +48,14 @@ if (head == null) {
|
||||||
|
|
||||||
let storage
|
let storage
|
||||||
if (config.storage === 'file') {
|
if (config.storage === 'file') {
|
||||||
storage = new FileStorage()
|
storage = new FileStorage(config)
|
||||||
} else if (config.storage === 'mongo') {
|
} else if (config.storage === 'mongo') {
|
||||||
storage = new MongoStorage()
|
storage = new MongoStorage(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataHolder = new DataHolder(storage)
|
const scanner = new Scanner(config, storage)
|
||||||
const scanner = new Scanner(config, dataHolder)
|
|
||||||
|
|
||||||
const serverRenderer = new ServerRenderer(head, config, dataHolder)
|
const serverRenderer = new ServerRenderer(head, config, storage)
|
||||||
app.get('*', serverRenderer.render.bind(serverRenderer))
|
app.get('*', serverRenderer.render.bind(serverRenderer))
|
||||||
|
|
||||||
if (config.storage === 'mongo') {
|
if (config.storage === 'mongo') {
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,8 @@ import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
export class FileStorage {
|
export class FileStorage {
|
||||||
constructor () {
|
constructor (config) {
|
||||||
|
this.config = config
|
||||||
this.data = {
|
this.data = {
|
||||||
posts: [],
|
posts: [],
|
||||||
other: {}
|
other: {}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import mongoose, { Schema } from 'mongoose'
|
import mongoose, { Schema } from 'mongoose'
|
||||||
|
|
||||||
export class MongoStorage {
|
export class MongoStorage {
|
||||||
constructor () {
|
constructor (config) {
|
||||||
|
this.config = config
|
||||||
|
|
||||||
const PostSchema = new Schema({
|
const PostSchema = new Schema({
|
||||||
filename: String,
|
filename: String,
|
||||||
published: String,
|
published: String,
|
||||||
|
@ -49,7 +51,17 @@ export class MongoStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteFile (filepath) {
|
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) {
|
getData (reqPath) {
|
||||||
|
|
Loading…
Reference in New Issue