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
@@ -12,20 +12,6 @@ const localeFolderRegex = /^([a-z]{2}(?:-[a-z]{2})?\/)?(.*)/i
|
||||
|
||||
/* 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'
|
||||
}
|
||||
}
|
||||
|
||||
const getContenType = (filePath) => {
|
||||
const ext = _.last(filePath.split('.'))
|
||||
switch (ext) {
|
||||
@@ -256,7 +242,7 @@ module.exports = {
|
||||
*/
|
||||
async created(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing new file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -275,7 +261,7 @@ module.exports = {
|
||||
*/
|
||||
async updated(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing updated file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -294,7 +280,7 @@ module.exports = {
|
||||
*/
|
||||
async deleted(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing removed file ${page.path}...`)
|
||||
let fileName = `${page.path}.${getFileExtension(page.contentType)}`
|
||||
let fileName = `${page.path}.${page.getFileExtension()}`
|
||||
if (WIKI.config.lang.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
@@ -311,8 +297,8 @@ module.exports = {
|
||||
*/
|
||||
async renamed(page) {
|
||||
WIKI.logger.info(`(STORAGE/GIT) Committing file move from ${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.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
sourceFilePath = `${page.localeCode}/${sourceFilePath}`
|
||||
@@ -363,7 +349,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.namespacing && WIKI.config.lang.code !== page.localeCode) {
|
||||
fileName = `${page.localeCode}/${fileName}`
|
||||
}
|
||||
|
Reference in New Issue
Block a user