Browse Source

feat: storage module refactor + UI fixes

pull/621/head
NGPixel 6 years ago
parent
commit
9e2f1caaf7
40 changed files with 334 additions and 329 deletions
  1. 2
      client/components/admin/admin-auth.vue
  2. 6
      client/components/admin/admin-contribute.vue
  3. 4
      client/components/admin/admin-general.vue
  4. 8
      client/components/admin/admin-groups.vue
  5. 4
      client/components/admin/admin-locale.vue
  6. 4
      client/components/admin/admin-rendering.vue
  7. 2
      client/components/admin/admin-storage.vue
  8. 6
      client/components/admin/admin-system.vue
  9. 2
      client/components/admin/admin-theme.vue
  10. 1
      client/scss/app.scss
  11. 5
      server/db/models/authentication.js
  12. 22
      server/db/models/storage.js
  13. 17
      server/helpers/common.js
  14. 30
      server/modules/storage/azure.js
  15. 7
      server/modules/storage/azure/definition.yml
  16. 23
      server/modules/storage/azure/storage.js
  17. 34
      server/modules/storage/digitalocean.js
  18. 10
      server/modules/storage/digitalocean/definition.yml
  19. 23
      server/modules/storage/digitalocean/storage.js
  20. 28
      server/modules/storage/disk.js
  21. 5
      server/modules/storage/disk/definition.yml
  22. 23
      server/modules/storage/disk/storage.js
  23. 29
      server/modules/storage/dropbox.js
  24. 6
      server/modules/storage/dropbox/definition.yml
  25. 23
      server/modules/storage/dropbox/storage.js
  26. 29
      server/modules/storage/gdrive.js
  27. 6
      server/modules/storage/gdrive/definition.yml
  28. 23
      server/modules/storage/gdrive/storage.js
  29. 44
      server/modules/storage/git.js
  30. 20
      server/modules/storage/git/definition.yml
  31. 23
      server/modules/storage/git/storage.js
  32. 29
      server/modules/storage/onedrive.js
  33. 6
      server/modules/storage/onedrive/definition.yml
  34. 23
      server/modules/storage/onedrive/storage.js
  35. 31
      server/modules/storage/s3.js
  36. 8
      server/modules/storage/s3/definition.yml
  37. 23
      server/modules/storage/s3/storage.js
  38. 38
      server/modules/storage/scp.js
  39. 13
      server/modules/storage/scp/definition.yml
  40. 23
      server/modules/storage/scp/storage.js

2
client/components/admin/admin-auth.vue

@ -51,7 +51,7 @@
v-model='cfg.value.value'
prepend-icon='settings_applications'
)
v-divider
v-divider.mt-3
v-subheader.pl-0 Registration
.pr-3
v-switch.ml-3(

6
client/components/admin/admin-contribute.vue

@ -9,14 +9,14 @@
a(href='https://requarks.io', target='_blank') requarks.io
a(href='https://github.com/Requarks/wiki/graphs/contributors', target='_blank') {{ $t('admin:contribute.openSourceContributors') }}
.body-1.pt-3.pl-3 {{ $t('admin:contribute.needYourHelp') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.fundOurWork') }}
.body-1.pl-3 {{ $t('admin:contribute.openCollective') }}
v-card-actions.mt-3.ml-2
v-btn(depressed, color='primary', href='https://opencollective.com/wikijs')
v-icon(left) local_atm
span {{ $t('admin:contribute.makeADonation') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.contribute') }}
.body-1.pl-3
ul
@ -26,7 +26,7 @@
a(href='https://github.com/Requarks/wiki/issues', target='_blank') Github
i18next(path='admin:contribute.helpTranslate', tag='li')
a(href='https://gitter.im/Requarks/wiki', target='_blank') Gitter
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:contribute.spreadTheWord') }}
.body-1.pl-3
ul

4
client/components/admin/admin-general.vue

@ -15,7 +15,7 @@
v-subheader General
.px-3
v-text-field(label='Site Title', required, :counter='50', v-model='siteTitle', prepend-icon='public')
v-divider
v-divider.mt-3
v-subheader SEO
.px-3
v-text-field(label='Site Description', :counter='255', prepend-icon='public')
@ -51,7 +51,7 @@
persistent-hint
hint='Check this option if a round logo frame doesn\'t work with your logo.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='displayMascot'
label='Display Wiki.js Mascot'

8
client/components/admin/admin-groups.vue

@ -22,10 +22,10 @@
v-spacer
v-text-field(solo, append-icon='search', label='Search', single-line, hide-details, v-model='search')
v-data-table(
:items='groups',
:headers='headers',
:search='search',
:pagination.sync='pagination',
:items='groups'
:headers='headers'
:search='search'
:pagination.sync='pagination'
:rows-per-page-items='[15]'
hide-actions
)

4
client/components/admin/admin-locale.vue

@ -31,7 +31,7 @@
v-list-tile-content
v-list-tile-title(v-html='data.item.name')
v-list-tile-sub-title(v-html='data.item.nativeName')
v-divider
v-divider.mt-3
v-switch(
v-model='autoUpdate'
:label='$t("admin:locale.autoUpdate.label")'
@ -65,7 +65,7 @@
)
span {{ $t('admin:locale.namespacingPrefixWarning.title', { langCode: selectedLocale }) }}
.caption.grey--text {{ $t('admin:locale.namespacingPrefixWarning.subtitle') }}
v-divider
v-divider.mt-3.mb-4
v-select(
:disabled='!namespacing'
:items='installedLocales'

4
client/components/admin/admin-rendering.vue

@ -169,7 +169,7 @@
persistent-hint
hint='Links will automatically be converted to clickable links.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='linkify'
label='Automatically convert line breaks'
@ -177,7 +177,7 @@
persistent-hint
hint='Add linebreaks within paragraphs.'
)
v-divider
v-divider.mt-3
v-switch(
v-model='linkify'
label='Highlight code blocks'

2
client/components/admin/admin-storage.vue

@ -51,7 +51,7 @@
v-model='cfg.value.value'
prepend-icon='settings_applications'
)
v-divider
v-divider.mt-3
v-subheader.pl-0 Sync Direction
.body-1.ml-3 Choose how content synchronization is handled for this storage target.
.pr-3.pt-3

6
client/components/admin/admin-system.vue

@ -25,7 +25,7 @@
v-list-tile-action
v-list-tile-action-text {{ $t('admin:system.published') }} {{ info.latestVersionReleaseDate | moment('from') }}
v-divider
v-divider.mt-3
v-subheader {{ $t('admin:system.hostInfo') }}
v-list-tile(avatar)
@ -76,7 +76,7 @@
v-list-tile-content
v-list-tile-title {{ info.nodeVersion }}
v-divider
v-divider.mt-3
v-subheader Redis
v-list-tile(avatar)
@ -89,7 +89,7 @@
v-list-tile-action
v-list-tile-action-text {{ $t('admin:system.ramUsage', { used: info.redisUsedRAM, total: info.redisTotalRAM }) }}
v-divider
v-divider.mt-3
v-subheader {{ info.dbType }}
v-list-tile(avatar)

2
client/components/admin/admin-theme.vue

@ -26,7 +26,7 @@
v-list-tile-content
v-list-tile-title(v-html='data.item.text')
v-list-tile-sub-title(v-html='data.item.author')
v-divider
v-divider.mt-3
v-switch(
v-model='darkMode'
label='Dark Mode'

1
client/scss/app.scss

@ -1,6 +1,5 @@
@import "global";
@import "base/reset";
@import "base/base";
@import 'base/icons';

5
server/db/models/authentication.js

@ -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

22
server/db/models/storage.js

@ -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)
})
}

17
server/helpers/common.js

@ -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
}
}
}

30
server/modules/storage/azure.js

@ -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

@ -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

@ -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) {
}
}

34
server/modules/storage/digitalocean.js

@ -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

@ -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

@ -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) {
}
}

28
server/modules/storage/disk.js

@ -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

@ -0,0 +1,5 @@
key: disk
title: Local FS
author: requarks.io
props:
path: String

23
server/modules/storage/disk/storage.js

@ -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) {
}
}

29
server/modules/storage/dropbox.js

@ -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

@ -0,0 +1,6 @@
key: dropbox
title: Dropbox
author: requarks.io
props:
appKey: String
appSecret: String

23
server/modules/storage/dropbox/storage.js

@ -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) {
}
}

29
server/modules/storage/gdrive.js

@ -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

@ -0,0 +1,6 @@
key: gdrive
title: Google Drive
author: requarks.io
props:
clientId: String
clientSecret: String

23
server/modules/storage/gdrive/storage.js

@ -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) {
}
}

44
server/modules/storage/git.js

@ -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

@ -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

@ -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) {
}
}

29
server/modules/storage/onedrive.js

@ -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

@ -0,0 +1,6 @@
key: onedrive
title: OneDrive
author: requarks.io
props:
clientId: String
clientSecret: String

23
server/modules/storage/onedrive/storage.js

@ -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) {
}
}

31
server/modules/storage/s3.js

@ -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

@ -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

@ -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) {
}
}

38
server/modules/storage/scp.js

@ -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

@ -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

@ -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) {
}
}
Loading…
Cancel
Save