aboutsummaryrefslogtreecommitdiffhomepage
path: root/support/doc/plugins/guide.md
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-22 10:55:28 +0200
committerChocobozzz <me@florianbigard.com>2021-04-22 10:55:28 +0200
commit302eba0d898e38dca14739486441c27c0be6c62f (patch)
tree280d18bfe2ad1b16248277371e609c31d6b3aaa4 /support/doc/plugins/guide.md
parent3e0e8d4afded28559b7c473061bbdc31ab542e1c (diff)
downloadPeerTube-302eba0d898e38dca14739486441c27c0be6c62f.tar.gz
PeerTube-302eba0d898e38dca14739486441c27c0be6c62f.tar.zst
PeerTube-302eba0d898e38dca14739486441c27c0be6c62f.zip
Add data directory for plugins and some helpers
Diffstat (limited to 'support/doc/plugins/guide.md')
-rw-r--r--support/doc/plugins/guide.md40
1 files changed, 38 insertions, 2 deletions
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index 5b5a3065d..36ade117b 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -195,12 +195,30 @@ Plugins can store/load JSON data, that PeerTube will store in its database (so d
195Example: 195Example:
196 196
197```js 197```js
198function register (...) { 198function register ({
199 storageManager
200}) {
199 const value = await storageManager.getData('mykey') 201 const value = await storageManager.getData('mykey')
200 await storageManager.storeData('mykey', { subkey: 'value' }) 202 await storageManager.storeData('mykey', { subkey: 'value' })
201} 203}
202``` 204```
203 205
206You can also store files in the plugin data directory (`/{plugins-directory}/data/{npm-plugin-name}`).
207This directory and its content won't be deleted when your plugin is uninstalled/upgraded.
208
209```js
210function register ({
211 storageManager,
212 peertubeHelpers
213}) {
214 const basePath = peertubeHelpers.plugin.getDataDirectoryPath()
215
216 fs.writeFile(path.join(basePath, 'filename.txt'), 'content of my file', function (err) {
217 ...
218 })
219}
220```
221
204#### Update video constants 222#### Update video constants
205 223
206You can add/delete video categories, licences or languages using the appropriate managers: 224You can add/delete video categories, licences or languages using the appropriate managers:
@@ -226,9 +244,27 @@ function register (...) {
226You can create custom routes using an [express Router](https://expressjs.com/en/4x/api.html#router) for your plugin: 244You can create custom routes using an [express Router](https://expressjs.com/en/4x/api.html#router) for your plugin:
227 245
228```js 246```js
229function register (...) { 247function register ({
248 router
249}) {
230 const router = getRouter() 250 const router = getRouter()
231 router.get('/ping', (req, res) => res.json({ message: 'pong' })) 251 router.get('/ping', (req, res) => res.json({ message: 'pong' }))
252
253 // Users are automatically authenticated
254 router.get('/auth', (res, res) => {
255 const user = peertubeHelpers.user.getAuthUser(res)
256
257 const isAdmin = user.role === 0
258 const isModerator = user.role === 1
259 const isUser = user.role === 2
260
261 res.json({
262 username: user.username,
263 isAdmin,
264 isModerator,
265 isUser
266 })
267 })
232} 268}
233``` 269```
234 270