for (const hook of this.hooks[hookName]) {
try {
- if (wait) result = await hook.handler(param)
- else result = hook.handler()
+ const p = hook.handler(param)
+
+ if (wait) {
+ result = await p
+ } else if (p.catch) {
+ p.catch((err: Error) => {
+ console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.plugin, hook.clientScript, err)
+ })
+ }
} catch (err) {
console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.plugin, hook.clientScript, err)
}
// ---------------------------------------------------------------------------
const API_VERSION = 'v1'
-const PEERTUBE_VERSION = process.env.npm_package_version || 'unknown'
+const PEERTUBE_VERSION = require(join(root(), 'package.json')).version
const PAGINATION = {
COUNT: {
for (const hook of this.hooks[hookName]) {
try {
+ const p = hook.handler(param)
+
if (wait) {
- result = await hook.handler(param)
- } else {
- result = hook.handler()
+ result = await p
+ } else if (p.catch) {
+ p.catch(err => logger.warn('Hook %s of plugin %s thrown an error.', hookName, hook.pluginName, { err }))
}
} catch (err) {
logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err })
registerSetting,
settingsManager,
storageManager
- })
+ }).catch(err => logger.error('Cannot register plugin %s.', npmName, { err }))
logger.info('Add plugin %s CSS to global file.', npmName)
private async regeneratePluginGlobalCSS () {
await this.resetCSSGlobalFile()
- for (const key of Object.keys(this.registeredPlugins)) {
+ for (const key of Object.keys(this.getRegisteredPlugins())) {
const plugin = this.registeredPlugins[key]
await this.addCSSToGlobalFile(plugin.path, plugin.css)
return PluginModel.findOne(query)
.then((c: any) => {
if (!c) return undefined
+ const value = c.value
+
+ if (typeof value === 'string' && value.startsWith('{')) {
+ try {
+ return JSON.parse(value)
+ } catch {
+ return value
+ }
+ }
return c.value
})
import { RegisterOptions } from './register-options.model'
export interface PluginLibrary {
- register: (options: RegisterOptions) => void
+ register: (options: RegisterOptions) => Promise<any>
unregister: () => Promise<any>
}
Example:
```js
-registerHook({
- target: 'action:application.listening',
- handler: () => displayHelloWorld()
-})
+// This register function is called by PeerTube, and **must** return a promise
+async function register ({ registerHook }) {
+ registerHook({
+ target: 'action:application.listening',
+ handler: () => displayHelloWorld()
+ })
+}
```
On server side, these hooks are registered by the `library` file defined in `package.json`.
Plugins can declare CSS files that PeerTube will automatically inject in the client.
-### Server helpers
-
-**Only for plugins**
+### Server helpers (only for plugins)
#### Settings
```js
const value = await storageManager.getData('mykey')
-await storageManager.storeData('mykey', 'myvalue')
+await storageManager.storeData('mykey', { subkey: 'value' })
```
### Publishing
}
```
-And if you don't need CSS files, use an empty `array`:
+And if you don't need CSS or client script files, use an empty `array`:
```json
{
...,
"css": [],
+ "clientScripts": [],
...
}
```
```
$ npm run build -- --light
+```
+
+ * Build the CLI:
+
+```
+$ npm run setup:cli
```
- * Run it (you can access to your instance on http://localhost:9000):
+ * Run PeerTube (you can access to your instance on http://localhost:9000):
```
$ NODE_ENV=test npm start