peertube-theme-nctv-dark/peertube-plugin-hello-world/main.js

94 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-07-26 12:45:53 +00:00
async function register ({
registerHook,
2020-04-10 12:42:34 +00:00
getRouter,
2019-07-26 12:45:53 +00:00
registerSetting,
settingsManager,
storageManager,
videoCategoryManager,
videoLicenceManager,
videoLanguageManager
}) {
2019-07-16 09:53:38 +00:00
const defaultAdmin = 'PeerTube admin'
registerHook({
target: 'action:application.listening',
handler: () => displayHelloWorld(settingsManager, defaultAdmin)
})
2019-07-22 14:40:52 +00:00
registerHook({
target: 'unknown-hook',
handler: () => console.log('fake hook')
})
registerHook({
target: 'filter:api.user.signup.allowed.result',
handler: (result, params) => {
if (result.allowed === false) return result
if (params && params.body.email.includes('laposte.net')) {
return { allowed: false, errorMessage: 'laposte.net emails are not allowed on this instance' }
}
return result
}
})
2019-07-16 09:53:38 +00:00
registerSetting({
name: 'admin-name',
label: 'Admin name',
type: 'input',
2019-07-26 07:42:52 +00:00
private: true,
2019-07-16 09:53:38 +00:00
default: defaultAdmin
})
2019-07-26 07:42:52 +00:00
registerSetting({
name: 'user-name',
label: 'User name',
type: 'input',
private: false
})
2019-07-16 09:53:38 +00:00
const value = await storageManager.getData('toto')
console.log(value)
await storageManager.storeData('toto', 'hello' + new Date())
2020-04-10 12:42:34 +00:00
await storageManager.storeData('toto2', { toto2: [ 'user 1', 'user 2' ] })
console.log(await storageManager.getData('toto2'))
console.log(await storageManager.getData('toto2.toto2'))
2019-07-26 12:45:53 +00:00
videoLanguageManager.addLanguage('al_bhed', 'Al Bhed')
videoLanguageManager.deleteLanguage('fr')
videoCategoryManager.addCategory(42, 'Best category')
videoCategoryManager.deleteCategory(1) // Music
videoLicenceManager.addLicence(42, 'Best licence')
videoLicenceManager.deleteLicence(7) // Public domain
2020-04-10 12:42:34 +00:00
const router = getRouter()
router.get('/ping', (req, res) => res.json({ message: 'pong' }))
router.post('/form/post/mirror', (req, res) => {
res.json(req.body)
})
2019-07-16 09:53:38 +00:00
}
async function unregister () {
return
}
module.exports = {
register,
unregister
}
// ############################################################################
async function displayHelloWorld (settingsManager, defaultAdmin) {
let value = await settingsManager.getSetting('admin-name')
if (!value) value = defaultAdmin
console.log('hello world ' + value)
}