From ced38c0ffe1e7d30f1f80fe704e571f39b0cc78b Mon Sep 17 00:00:00 2001 From: lutangar Date: Wed, 15 Dec 2021 09:35:17 +0100 Subject: fix plugin storage return value when storing a Json array --- server/models/server/plugin.ts | 12 ++++-------- server/tests/fixtures/peertube-plugin-test-six/main.js | 5 +++++ server/tests/plugins/plugin-storage.ts | 6 +++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index a8de64dd4..c79178782 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts @@ -197,15 +197,11 @@ export class PluginModel extends Model>> { if (!c) return undefined const value = c.value - if (typeof value === 'string' && value.startsWith('{')) { - try { - return JSON.parse(value) - } catch { - return value - } + try { + return JSON.parse(value) + } catch { + return value } - - return c.value }) } diff --git a/server/tests/fixtures/peertube-plugin-test-six/main.js b/server/tests/fixtures/peertube-plugin-test-six/main.js index 858bdb2df..4a9d56ea7 100644 --- a/server/tests/fixtures/peertube-plugin-test-six/main.js +++ b/server/tests/fixtures/peertube-plugin-test-six/main.js @@ -11,9 +11,14 @@ async function register ({ { await storageManager.storeData('superkey', { value: 'toto' }) await storageManager.storeData('anotherkey', { value: 'toto2' }) + await storageManager.storeData('storedArrayKey', ['toto', 'toto2']) const result = await storageManager.getData('superkey') logger.info('superkey stored value is %s', result.value) + + const storedArrayValue = await storageManager.getData('storedArrayKey') + logger.info('storedArrayKey value type is %s', typeof storedArrayValue) + logger.info('storedArrayKey stored value is %s', storedArrayValue.join(', ')) } { diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts index e20c36dba..ac519045d 100644 --- a/server/tests/plugins/plugin-storage.ts +++ b/server/tests/plugins/plugin-storage.ts @@ -27,10 +27,14 @@ describe('Test plugin storage', function () { }) describe('DB storage', function () { - it('Should correctly store a subkey', async function () { await server.servers.waitUntilLog('superkey stored value is toto') }) + + it('Should correctly retrieve an array as array from the storage.', async function () { + await server.servers.waitUntilLog('storedArrayKey value type is array') + await server.servers.waitUntilLog('storedArrayKey stored value is toto, toto2') + }) }) describe('Disk storage', function () { -- cgit v1.2.3