feat: storage actions + git module actions

This commit is contained in:
Nick
2019-04-06 19:05:47 -04:00
parent 16d88a7c7a
commit 10df1b4b0c
10 changed files with 261 additions and 83 deletions

View File

@@ -130,21 +130,7 @@ module.exports = class Page extends Model {
* Inject page metadata into contents
*/
injectMetadata () {
let meta = [
['title', this.title],
['description', this.description],
['published', this.isPublished.toString()],
['date', this.updatedAt],
['tags', '']
]
switch (this.contentType) {
case 'markdown':
return '---\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n---\n\n' + this.content
case 'html':
return '<!--\n' + meta.map(mt => `${mt[0]}: ${mt[1]}`).join('\n') + '\n-->\n\n' + this.content
default:
return this.content
}
return pageHelper.injectPageMetadata(this)
}
/**

View File

@@ -60,7 +60,7 @@ module.exports = class Storage extends Model {
newTargets.push({
key: target.key,
isEnabled: false,
mode: target.defaultMode || 'push',
mode: target.defaultMode || 'push',
syncInterval: target.schedule || 'P0D',
config: _.transform(target.props, (result, value, key) => {
_.set(result, key, value.default)
@@ -116,7 +116,7 @@ module.exports = class Storage extends Model {
}
// -> Initialize targets
for(let target of this.targets) {
for (let target of this.targets) {
const targetDef = _.find(WIKI.data.storage, ['key', target.key])
target.fn = require(`../modules/storage/${target.key}/storage`)
target.fn.config = target.config
@@ -161,7 +161,7 @@ module.exports = class Storage extends Model {
static async pageEvent({ event, page }) {
try {
for(let target of this.targets) {
for (let target of this.targets) {
await target.fn[event](page)
}
} catch (err) {
@@ -169,4 +169,22 @@ module.exports = class Storage extends Model {
throw err
}
}
static async executeAction(targetKey, handler) {
try {
const target = _.find(this.targets, ['key', targetKey])
if (target) {
if (_.has(target.fn, handler)) {
await target.fn[handler]()
} else {
throw new Error('Invalid Handler for Storage Target')
}
} else {
throw new Error('Invalid or Inactive Storage Target')
}
} catch (err) {
WIKI.logger.warn(err)
throw err
}
}
}