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,
|
2020-04-28 12:58:40 +00:00
|
|
|
videoLanguageManager,
|
2020-04-30 07:06:39 +00:00
|
|
|
registerExternalAuth,
|
|
|
|
peertubeHelpers
|
2019-07-26 12:45:53 +00:00
|
|
|
}) {
|
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')
|
|
|
|
})
|
|
|
|
|
2019-12-05 16:08:33 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|
2020-05-18 08:04:58 +00:00
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'filter:api.video.post-import-url.accept.result',
|
|
|
|
handler: ({ accepted }, { video }) => {
|
|
|
|
if (!accepted) return { accepted: false }
|
|
|
|
if (video.name.includes('small video - youtube')) return { accepted: false, errorMessage: 'bad word' }
|
|
|
|
|
|
|
|
return { accepted: true }
|
|
|
|
}
|
|
|
|
})
|
2019-12-05 16:08:33 +00:00
|
|
|
|
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
|
|
|
|
})
|
|
|
|
|
2020-04-24 12:25:43 +00:00
|
|
|
registerSetting({
|
|
|
|
name: 'my-markdown-area',
|
|
|
|
label: 'Markdown text',
|
|
|
|
type: 'markdown-text',
|
|
|
|
default: 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
|
|
|
|
2020-04-30 07:06:39 +00:00
|
|
|
settingsManager.onSettingsChange(settings => {
|
|
|
|
peertubeHelpers.logger.info('Settings changed!', { settings })
|
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
})
|
2020-04-28 12:58:40 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const result = registerExternalAuth({
|
|
|
|
authName: 'fake-auth',
|
2020-04-30 08:14:51 +00:00
|
|
|
authDisplayName: () => 'fake auth',
|
2020-04-28 12:58:40 +00:00
|
|
|
onAuthRequest: (req, res) => {
|
|
|
|
result.userAuthenticated({
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
username: 'fake_auth_username',
|
|
|
|
email: 'fake_auth_username@example.com'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
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)
|
|
|
|
}
|