feat: storage module refactor + UI fixes
This commit is contained in:
@@ -2,7 +2,6 @@ const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -56,7 +55,7 @@ module.exports = class Authentication extends Model {
|
||||
if (_.isPlainObject(value)) {
|
||||
let cfgValue = {
|
||||
type: typeof value.type(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
|
||||
value: !_.isNil(value.default) ? value.default : new value() // eslint-disable-line new-cap
|
||||
}
|
||||
if (_.isArray(value.enum)) {
|
||||
cfgValue.enum = value.enum
|
||||
@@ -65,7 +64,7 @@ module.exports = class Authentication extends Model {
|
||||
} else {
|
||||
_.set(result, key, {
|
||||
type: typeof value(),
|
||||
value: commonHelper.getTypeDefaultValue(value)
|
||||
value: new value() // eslint-disable-line new-cap
|
||||
})
|
||||
}
|
||||
return result
|
||||
|
@@ -1,7 +1,8 @@
|
||||
const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const _ = require('lodash')
|
||||
const yaml = require('js-yaml')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
@@ -35,9 +36,18 @@ module.exports = class Storage extends Model {
|
||||
static async refreshTargetsFromDisk() {
|
||||
try {
|
||||
const dbTargets = await WIKI.db.storage.query()
|
||||
const diskTargets = autoload(path.join(WIKI.SERVERPATH, 'modules/storage'))
|
||||
|
||||
// -> Fetch definitions from disk
|
||||
const storageDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/storage'))
|
||||
let diskTargets = []
|
||||
for (let dir of storageDirs) {
|
||||
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/storage', dir, 'definition.yml'), 'utf8')
|
||||
diskTargets.push(yaml.safeLoad(def))
|
||||
}
|
||||
|
||||
// -> Insert new targets
|
||||
let newTargets = []
|
||||
_.forOwn(diskTargets, (target, targetKey) => {
|
||||
_.forEach(diskTargets, target => {
|
||||
if (!_.some(dbTargets, ['key', target.key])) {
|
||||
newTargets.push({
|
||||
key: target.key,
|
||||
@@ -47,8 +57,8 @@ module.exports = class Storage extends Model {
|
||||
config: _.transform(target.props, (result, value, key) => {
|
||||
if (_.isPlainObject(value)) {
|
||||
let cfgValue = {
|
||||
type: typeof value.type(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value)
|
||||
type: value.type.toLowerCase(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
|
||||
}
|
||||
if (_.isArray(value.enum)) {
|
||||
cfgValue.enum = value.enum
|
||||
@@ -56,7 +66,7 @@ module.exports = class Storage extends Model {
|
||||
_.set(result, key, cfgValue)
|
||||
} else {
|
||||
_.set(result, key, {
|
||||
type: typeof value(),
|
||||
type: value.toLowerCase(),
|
||||
value: commonHelper.getTypeDefaultValue(value)
|
||||
})
|
||||
}
|
||||
|
@@ -1,17 +1,18 @@
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Get default value of type
|
||||
*
|
||||
* @param {any} Type Primitive Type
|
||||
* @param {any} type primitive type name
|
||||
* @returns Default value
|
||||
*/
|
||||
getTypeDefaultValue (Type) {
|
||||
if (_.isArray(Type)) {
|
||||
return _.head(Type)
|
||||
} else {
|
||||
return new Type()
|
||||
getTypeDefaultValue (type) {
|
||||
switch (type.toLowerCase()) {
|
||||
case 'string':
|
||||
return ''
|
||||
case 'number':
|
||||
return 0
|
||||
case 'boolean':
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'azure',
|
||||
title: 'Azure Blob Storage',
|
||||
props: {
|
||||
accountName: String,
|
||||
accountKey: String,
|
||||
container: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
7
server/modules/storage/azure/definition.yml
Normal file
7
server/modules/storage/azure/definition.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
key: azure
|
||||
title: Azure Blob Storage
|
||||
author: requarks.io
|
||||
props:
|
||||
accountName: String
|
||||
accountKey: String
|
||||
container: String
|
23
server/modules/storage/azure/storage.js
Normal file
23
server/modules/storage/azure/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'digitalocean',
|
||||
title: 'DigialOcean Spaces',
|
||||
props: {
|
||||
accessKeyId: String,
|
||||
accessSecret: String,
|
||||
region: {
|
||||
type: String,
|
||||
default: 'nyc3'
|
||||
},
|
||||
bucket: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
10
server/modules/storage/digitalocean/definition.yml
Normal file
10
server/modules/storage/digitalocean/definition.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
key: digitalocean
|
||||
title: DigialOcean Spaces
|
||||
author: requarks.io
|
||||
props:
|
||||
accessKeyId: String
|
||||
accessSecret: String
|
||||
region:
|
||||
type: String
|
||||
default: nyc3
|
||||
bucket: String
|
23
server/modules/storage/digitalocean/storage.js
Normal file
23
server/modules/storage/digitalocean/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'disk',
|
||||
title: 'Local FS',
|
||||
props: {
|
||||
path: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
5
server/modules/storage/disk/definition.yml
Normal file
5
server/modules/storage/disk/definition.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
key: disk
|
||||
title: Local FS
|
||||
author: requarks.io
|
||||
props:
|
||||
path: String
|
23
server/modules/storage/disk/storage.js
Normal file
23
server/modules/storage/disk/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'dropbox',
|
||||
title: 'Dropbox',
|
||||
props: {
|
||||
appKey: String,
|
||||
appSecret: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
6
server/modules/storage/dropbox/definition.yml
Normal file
6
server/modules/storage/dropbox/definition.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
key: dropbox
|
||||
title: Dropbox
|
||||
author: requarks.io
|
||||
props:
|
||||
appKey: String
|
||||
appSecret: String
|
23
server/modules/storage/dropbox/storage.js
Normal file
23
server/modules/storage/dropbox/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'gdrive',
|
||||
title: 'Google Drive',
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
6
server/modules/storage/gdrive/definition.yml
Normal file
6
server/modules/storage/gdrive/definition.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
key: gdrive
|
||||
title: Google Drive
|
||||
author: requarks.io
|
||||
props:
|
||||
clientId: String
|
||||
clientSecret: String
|
23
server/modules/storage/gdrive/storage.js
Normal file
23
server/modules/storage/gdrive/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'git',
|
||||
title: 'Git',
|
||||
props: {
|
||||
authType: {
|
||||
type: String,
|
||||
default: 'ssh',
|
||||
enum: ['basic', 'ssh']
|
||||
},
|
||||
repoUrl: String,
|
||||
branch: {
|
||||
type: String,
|
||||
default: 'master'
|
||||
},
|
||||
verifySSL: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
sshPrivateKeyPath: String,
|
||||
basicUsername: String,
|
||||
basicPassword: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
20
server/modules/storage/git/definition.yml
Normal file
20
server/modules/storage/git/definition.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
key: git
|
||||
title: Git
|
||||
author: requarks.io
|
||||
props:
|
||||
authType:
|
||||
type: String
|
||||
default: 'ssh'
|
||||
enum:
|
||||
- 'basic'
|
||||
- 'ssh'
|
||||
repoUrl: String
|
||||
branch:
|
||||
type: String
|
||||
default: 'master'
|
||||
verifySSL:
|
||||
type: Boolean
|
||||
default: true
|
||||
sshPrivateKeyPath: String
|
||||
basicUsername: String
|
||||
basicPassword: String
|
23
server/modules/storage/git/storage.js
Normal file
23
server/modules/storage/git/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'onedrive',
|
||||
title: 'OneDrive',
|
||||
props: {
|
||||
clientId: String,
|
||||
clientSecret: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
6
server/modules/storage/onedrive/definition.yml
Normal file
6
server/modules/storage/onedrive/definition.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
key: onedrive
|
||||
title: OneDrive
|
||||
author: requarks.io
|
||||
props:
|
||||
clientId: String
|
||||
clientSecret: String
|
23
server/modules/storage/onedrive/storage.js
Normal file
23
server/modules/storage/onedrive/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
module.exports = {
|
||||
key: 's3',
|
||||
title: 'Amazon S3',
|
||||
props: {
|
||||
accessKeyId: String,
|
||||
accessSecret: String,
|
||||
region: String,
|
||||
bucket: String
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
8
server/modules/storage/s3/definition.yml
Normal file
8
server/modules/storage/s3/definition.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
key: s3
|
||||
title: Amazon S3
|
||||
author: requarks.io
|
||||
props:
|
||||
accessKeyId: String
|
||||
accessSecret: String
|
||||
region: String
|
||||
bucket: String
|
23
server/modules/storage/s3/storage.js
Normal file
23
server/modules/storage/s3/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
module.exports = {
|
||||
key: 'scp',
|
||||
title: 'SCP (SSH)',
|
||||
props: {
|
||||
host: String,
|
||||
port: {
|
||||
type: Number,
|
||||
default: 22
|
||||
},
|
||||
username: String,
|
||||
privateKeyPath: String,
|
||||
basePath: {
|
||||
type: String,
|
||||
default: '~'
|
||||
}
|
||||
},
|
||||
activated(opts) {
|
||||
|
||||
},
|
||||
deactivated(opts) {
|
||||
|
||||
},
|
||||
init(opts) {
|
||||
|
||||
},
|
||||
created(opts) {
|
||||
|
||||
},
|
||||
updated(opts) {
|
||||
|
||||
},
|
||||
deleted(opts) {
|
||||
|
||||
},
|
||||
renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
13
server/modules/storage/scp/definition.yml
Normal file
13
server/modules/storage/scp/definition.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
key: scp
|
||||
title: SCP (SSH)
|
||||
author: requarks.io
|
||||
props:
|
||||
host: String
|
||||
port:
|
||||
type: Number
|
||||
default: 22
|
||||
username: String
|
||||
privateKeyPath: String
|
||||
basePath:
|
||||
type: String
|
||||
default: '~'
|
23
server/modules/storage/scp/storage.js
Normal file
23
server/modules/storage/scp/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated(opts) {
|
||||
|
||||
},
|
||||
async deactivated(opts) {
|
||||
|
||||
},
|
||||
async init(opts) {
|
||||
|
||||
},
|
||||
async created(opts) {
|
||||
|
||||
},
|
||||
async updated(opts) {
|
||||
|
||||
},
|
||||
async deleted(opts) {
|
||||
|
||||
},
|
||||
async renamed(opts) {
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user