feat: AWS S3 + Digitalocean Spaces storage modules (#1015)
* Provide basic implementation of AWS S3 storage module * Abstract S3 Compatible Storage Module logic * Refactor `getFileExtension()` into the `page` object * Add implementation for Digitalocean storage module * Remove accidental `async`/`await` in S3 Storage Module * Remove argument from the call to `page.getFileExtension()` https://github.com/Requarks/wiki/pull/1015#discussion_r321990073
This commit is contained in:
committed by
Nicolas Giard
parent
3ab7bcf8ea
commit
5202eadebb
@@ -10,20 +10,6 @@ const moment = require('moment')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Get file extension based on content type
|
||||
*/
|
||||
const getFileExtension = (contentType) => {
|
||||
switch (contentType) {
|
||||
case 'markdown':
|
||||
return 'md'
|
||||
case 'html':
|
||||
return 'html'
|
||||
default:
|
||||
return 'txt'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
async activated() {
|
||||
// not used
|
||||
@@ -58,7 +44,7 @@ module.exports = {
|
||||
},
|
||||
async created(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Creating file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -67,7 +53,7 @@ module.exports = {
|
||||
},
|
||||
async updated(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Updating file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -76,7 +62,7 @@ module.exports = {
|
||||
},
|
||||
async deleted(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Deleting file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -85,8 +71,8 @@ module.exports = {
|
||||
},
|
||||
async renamed(page) {
|
||||
WIKI.logger.info(`(STORAGE/DISK) Renaming file ${page.sourcePath} to ${page.destinationPath}...`)
|
||||
let sourceFilePath = `${page.sourcePath}.${getFileExtension(page.contentType)}`
|
||||
let destinationFilePath = `${page.destinationPath}.${getFileExtension(page.contentType)}`
|
||||
let sourceFilePath = `${page.sourcePath}.${page.getFileExtension()}`
|
||||
let destinationFilePath = `${page.destinationPath}.${page.getFileExtension()}`
|
||||
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
@@ -107,7 +93,7 @@ module.exports = {
|
||||
new stream.Transform({
|
||||
objectMode: true,
|
||||
transform: async (page, enc, cb) => {
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
|
Reference in New Issue
Block a user