mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
new backend plugin system!
This commit is contained in:
parent
d43cfbd6f9
commit
fcd4428c6b
3 changed files with 58 additions and 2 deletions
28
plugins/gancioPluginExample.js
Normal file
28
plugins/gancioPluginExample.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
const plugin = {
|
||||
gancio: null,
|
||||
load (gancio) {
|
||||
console.error('Plugin GancioPluginExample loaded!')
|
||||
plugin.gancio = gancio
|
||||
},
|
||||
|
||||
onEventCreate (event) {
|
||||
const eventLink = `${plugin.gancio.settings.baseurl}/event/${event.slug}`
|
||||
if (!event.is_visible) {
|
||||
console.error(`Unconfirmed event created: ${event.title} / ${eventLink}`)
|
||||
} else {
|
||||
console.error(`Event created: ${event.title} / ${eventLink}`)
|
||||
}
|
||||
},
|
||||
|
||||
onEventUpdate (event) {
|
||||
console.error(`Event "${event.title}" updated`)
|
||||
},
|
||||
|
||||
onEventDelete (event) {
|
||||
console.error(`Event "${event.title}" deleted`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = plugin
|
|
@ -106,6 +106,30 @@ const settingsController = {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
const plugins_path = path.resolve(process.env.cwd || '', 'plugins')
|
||||
if (fs.existsSync(plugins_path)) {
|
||||
const notifier = require('../../notifier')
|
||||
const pluginsFile = fs.readdirSync(plugins_path).filter(e => path.extname(e).toLowerCase() === '.js')
|
||||
pluginsFile.forEach( pluginFile => {
|
||||
log.info(`Loading plugin ${pluginFile}`)
|
||||
try {
|
||||
const plugin = require(path.resolve(plugins_path, pluginFile))
|
||||
plugin.load({ settings: settingsController.settings })
|
||||
if (typeof plugin.onEventCreate === 'function') {
|
||||
notifier.emitter.on('Create', plugin.onEventCreate)
|
||||
}
|
||||
if (typeof plugin.onEventDelete === 'function') {
|
||||
notifier.emitter.on('Delete', plugin.onEventDelete)
|
||||
}
|
||||
if (typeof plugin.onEventUpdate === 'function') {
|
||||
notifier.emitter.on('Update', plugin.onEventUpdate)
|
||||
}
|
||||
} catch (e) {
|
||||
log.error(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async set (key, value, is_secret = false) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const events = require('events')
|
||||
|
||||
const mail = require('./api/mail')
|
||||
const config = require('./config')
|
||||
const log = require('./log')
|
||||
const fediverseHelpers = require('./federation/helpers')
|
||||
|
||||
|
@ -15,6 +16,8 @@ const settingsController = require('./api/controller/settings')
|
|||
|
||||
const notifier = {
|
||||
|
||||
emitter: new events.EventEmitter(),
|
||||
|
||||
sendNotification (notification, event) {
|
||||
const promises = []
|
||||
log.info(`Send ${notification.type} notification ${notification.action}`)
|
||||
|
@ -38,7 +41,8 @@ const notifier = {
|
|||
const event = await Event.findByPk(eventId, {
|
||||
include: [Tag, Place, Notification, User]
|
||||
})
|
||||
|
||||
|
||||
notifier.emitter.emit(action, event.get({ plain: true, raw: true }))
|
||||
log.debug(action, event.title)
|
||||
|
||||
// insert notifications
|
||||
|
|
Loading…
Reference in a new issue