aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-21 16:00:48 +0200
committerChocobozzz <me@florianbigard.com>2020-08-21 16:00:48 +0200
commite08a26e23dcd0b94200df92c4e7e290f3db4e2fd (patch)
tree322cfafe9115855b620e1cb1c57f1443b32546d9 /support/doc
parent781ba981263ee6524fea1a95836108d252a124f4 (diff)
downloadPeerTube-e08a26e23dcd0b94200df92c4e7e290f3db4e2fd.tar.gz
PeerTube-e08a26e23dcd0b94200df92c4e7e290f3db4e2fd.tar.zst
PeerTube-e08a26e23dcd0b94200df92c4e7e290f3db4e2fd.zip
Add doc for custom video fields
Diffstat (limited to 'support/doc')
-rw-r--r--support/doc/plugins/guide.md62
1 files changed, 62 insertions, 0 deletions
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index d6d2114da..7f359d408 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -379,6 +379,68 @@ peertubeHelpers.getSettings()
379 }) 379 })
380``` 380```
381 381
382### Add custom fields to video form
383
384To add custom fields in the video form (in *Plugin settings* tab):
385
386```
387async function register ({ registerVideoField, peertubeHelpers }) {
388 const descriptionHTML = await peertubeHelpers.translate(descriptionSource)
389 const commonOptions = {
390 name: 'my-field-name,
391 label: 'My added field',
392 descriptionHTML: 'Optional description',
393 type: 'input-textarea',
394 default: ''
395 }
396
397 for (const type of [ 'upload', 'import-url', 'import-torrent', 'update' ]) {
398 registerVideoField(commonOptions, { type })
399 }
400}
401```
402
403PeerTube will send this field value in `body.pluginData['my-field-name']` and fetch it from `video.pluginData['my-field-name']`.
404
405So for example, if you want to store an additional metadata for videos, register the following hooks in **server**:
406
407```
408async function register ({
409 registerHook,
410 storageManager
411}) {
412 const fieldName = 'my-field-name'
413
414 // Store data associated to this video
415 registerHook({
416 target: 'action:api.video.updated',
417 handler: ({ video, body }) => {
418 if (!body.pluginData) return
419
420 const value = body.pluginData[fieldName]
421 if (!value) return
422
423 storageManager.storeData(fieldName + '-' + video.id, value)
424 }
425 })
426
427 // Add your custom value to the video, so the client autofill your field using the previously stored value
428 registerHook({
429 target: 'filter:api.video.get.result',
430 handler: async (video) => {
431 if (!video) return video
432 if (!video.pluginData) video.pluginData = {}
433
434 const result = await storageManager.getData(fieldName + '-' + video.id)
435 video.pluginData[fieldName] = result
436
437 return video
438 }
439 })
440}
441
442```
443
382 444
383### Publishing 445### Publishing
384 446