feat: storage actions + git module actions
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user