mirror of https://github.com/requarks/wiki
parent
2500d8b054
commit
bb102c3356
@ -0,0 +1,12 @@
|
||||
mutation($strategies: [AuthenticationStrategyInput]) {
|
||||
authentication {
|
||||
updateStrategies(strategies: $strategies) {
|
||||
responseResult {
|
||||
succeeded
|
||||
errorCode
|
||||
slug
|
||||
message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
query {
|
||||
storage {
|
||||
targets(orderBy: "title ASC") {
|
||||
isEnabled
|
||||
key
|
||||
title
|
||||
mode
|
||||
config {
|
||||
key
|
||||
value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
const Model = require('objection').Model
|
||||
const autoload = require('auto-load')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
/**
|
||||
* Storage model
|
||||
*/
|
||||
module.exports = class Storage extends Model {
|
||||
static get tableName() { return 'storage' }
|
||||
|
||||
static get jsonSchema () {
|
||||
return {
|
||||
type: 'object',
|
||||
required: ['key', 'title', 'isEnabled'],
|
||||
|
||||
properties: {
|
||||
id: {type: 'integer'},
|
||||
key: {type: 'string'},
|
||||
title: {type: 'string'},
|
||||
isEnabled: {type: 'boolean'},
|
||||
mode: {type: 'string'},
|
||||
config: {type: 'object'}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async getTargets() {
|
||||
return WIKI.db.storage.query()
|
||||
}
|
||||
|
||||
static async refreshTargetsFromDisk() {
|
||||
try {
|
||||
const dbTargets = await WIKI.db.storage.query()
|
||||
const diskTargets = autoload(path.join(WIKI.SERVERPATH, 'modules/storage'))
|
||||
let newTargets = []
|
||||
_.forOwn(diskTargets, (target, targetKey) => {
|
||||
if (!_.some(dbTargets, ['key', target.key])) {
|
||||
newTargets.push({
|
||||
key: target.key,
|
||||
title: target.title,
|
||||
isEnabled: false,
|
||||
mode: 'push',
|
||||
config: _.reduce(target.props, (result, value, key) => {
|
||||
_.set(result, value, '')
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
}
|
||||
})
|
||||
if (newTargets.length > 0) {
|
||||
await WIKI.db.storage.query().insert(newTargets)
|
||||
WIKI.logger.info(`Loaded ${newTargets.length} new storage targets: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new storage targets found: [ SKIPPED ]`)
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to scan or load new storage providers: [ FAILED ]`)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
const _ = require('lodash')
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async storage() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async storage() { return {} }
|
||||
},
|
||||
StorageQuery: {
|
||||
async targets(obj, args, context, info) {
|
||||
let targets = await WIKI.db.storage.getTargets()
|
||||
targets = targets.map(stg => ({
|
||||
...stg,
|
||||
config: _.transform(stg.config, (res, value, key) => {
|
||||
res.push({ key, value })
|
||||
}, [])
|
||||
}))
|
||||
if (args.filter) { targets = graphHelper.filter(targets, args.filter) }
|
||||
if (args.orderBy) { targets = graphHelper.orderBy(targets, args.orderBy) }
|
||||
return targets
|
||||
}
|
||||
},
|
||||
StorageMutation: {
|
||||
async updateTargets(obj, args, context) {
|
||||
try {
|
||||
for (let tgt of args.targets) {
|
||||
await WIKI.db.storage.query().patch({
|
||||
isEnabled: tgt.isEnabled,
|
||||
mode: tgt.mode,
|
||||
config: _.reduce(tgt.config, (result, value, key) => {
|
||||
_.set(result, value.key, value.value)
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', tgt.key)
|
||||
}
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Storage targets updated successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
# ===============================================
|
||||
# STORAGE
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
storage: StorageQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
storage: StorageMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type StorageQuery {
|
||||
targets(
|
||||
filter: String
|
||||
orderBy: String
|
||||
): [StorageTarget]
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type StorageMutation {
|
||||
updateTargets(
|
||||
targets: [StorageTargetInput]
|
||||
): DefaultResponse
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type StorageTarget {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
title: String!
|
||||
mode: String
|
||||
config: [KeyValuePair]
|
||||
}
|
||||
|
||||
input StorageTargetInput {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
mode: String!
|
||||
config: [KeyValuePairInput]
|
||||
}
|
Loading…
Reference in new issue