aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/models/server/plugin.ts19
-rw-r--r--server/tests/fixtures/peertube-plugin-test-six/main.js25
-rw-r--r--server/tests/fixtures/peertube-plugin-test-six/package.json20
-rw-r--r--server/tests/plugins/index.ts1
-rw-r--r--server/tests/plugins/plugin-storage.ts30
5 files changed, 85 insertions, 10 deletions
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts
index c72846343..53b6227d7 100644
--- a/server/models/server/plugin.ts
+++ b/server/models/server/plugin.ts
@@ -1,5 +1,5 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { FindAndCountOptions, json } from 'sequelize' 2import { FindAndCountOptions, json, QueryTypes } from 'sequelize'
3import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 3import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
4import { MPlugin, MPluginFormattable } from '@server/typings/models' 4import { MPlugin, MPluginFormattable } from '@server/typings/models'
5import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model' 5import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model'
@@ -212,18 +212,17 @@ export class PluginModel extends Model<PluginModel> {
212 } 212 }
213 213
214 static storeData (pluginName: string, pluginType: PluginType, key: string, data: any) { 214 static storeData (pluginName: string, pluginType: PluginType, key: string, data: any) {
215 const query = { 215 const query = 'UPDATE "plugin" SET "storage" = jsonb_set(coalesce("storage", \'{}\'), :key, :data::jsonb) ' +
216 where: { 216 'WHERE "name" = :pluginName AND "type" = :pluginType'
217 name: pluginName,
218 type: pluginType
219 }
220 }
221 217
222 const toSave = { 218 const jsonPath = '{' + key + '}'
223 [`storage.${key}`]: data 219
220 const options = {
221 replacements: { pluginName, pluginType, key: jsonPath, data: JSON.stringify(data) },
222 type: QueryTypes.UPDATE
224 } 223 }
225 224
226 return PluginModel.update(toSave, query) 225 return PluginModel.sequelize.query(query, options)
227 .then(() => undefined) 226 .then(() => undefined)
228 } 227 }
229 228
diff --git a/server/tests/fixtures/peertube-plugin-test-six/main.js b/server/tests/fixtures/peertube-plugin-test-six/main.js
new file mode 100644
index 000000000..bb9aaffa7
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-six/main.js
@@ -0,0 +1,25 @@
1async function register ({
2 storageManager,
3 peertubeHelpers
4}) {
5 const { logger } = peertubeHelpers
6
7 {
8 await storageManager.storeData('superkey', { value: 'toto' })
9 await storageManager.storeData('anotherkey', { value: 'toto2' })
10
11 const result = await storageManager.getData('superkey')
12 logger.info('superkey stored value is %s', result.value)
13 }
14}
15
16async function unregister () {
17 return
18}
19
20module.exports = {
21 register,
22 unregister
23}
24
25// ###########################################################################
diff --git a/server/tests/fixtures/peertube-plugin-test-six/package.json b/server/tests/fixtures/peertube-plugin-test-six/package.json
new file mode 100644
index 000000000..8c97826b0
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-six/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-six",
3 "version": "0.0.1",
4 "description": "Plugin test 6",
5 "engine": {
6 "peertube": ">=1.3.0"
7 },
8 "keywords": [
9 "peertube",
10 "plugin"
11 ],
12 "homepage": "https://github.com/Chocobozzz/PeerTube",
13 "author": "Chocobozzz",
14 "bugs": "https://github.com/Chocobozzz/PeerTube/issues",
15 "library": "./main.js",
16 "staticDirs": {},
17 "css": [],
18 "clientScripts": [],
19 "translations": {}
20}
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts
index d2bd69131..39c4c958a 100644
--- a/server/tests/plugins/index.ts
+++ b/server/tests/plugins/index.ts
@@ -6,3 +6,4 @@ import './translations'
6import './video-constants' 6import './video-constants'
7import './plugin-helpers' 7import './plugin-helpers'
8import './plugin-router' 8import './plugin-router'
9import './plugin-storage'
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts
new file mode 100644
index 000000000..356692eb9
--- /dev/null
+++ b/server/tests/plugins/plugin-storage.ts
@@ -0,0 +1,30 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils'
5import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
6
7describe('Test plugin storage', function () {
8 let server: ServerInfo
9
10 before(async function () {
11 this.timeout(30000)
12
13 server = await flushAndRunServer(1)
14 await setAccessTokensToServers([ server ])
15
16 await installPlugin({
17 url: server.url,
18 accessToken: server.accessToken,
19 path: getPluginTestPath('-six')
20 })
21 })
22
23 it('Should correctly store a subkey', async function () {
24 await waitUntilLog(server, 'superkey stored value is toto')
25 })
26
27 after(async function () {
28 await cleanupTests([ server ])
29 })
30})