diff options
Diffstat (limited to 'support')
-rw-r--r-- | support/doc/plugins/guide.md | 62 |
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 | |||
384 | To add custom fields in the video form (in *Plugin settings* tab): | ||
385 | |||
386 | ``` | ||
387 | async 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 | |||
403 | PeerTube will send this field value in `body.pluginData['my-field-name']` and fetch it from `video.pluginData['my-field-name']`. | ||
404 | |||
405 | So for example, if you want to store an additional metadata for videos, register the following hooks in **server**: | ||
406 | |||
407 | ``` | ||
408 | async 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 | ||