fix plugin storage return value when storing a Json array
This commit is contained in:
parent
8530211822
commit
ced38c0ffe
|
@ -197,15 +197,11 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> {
|
|||
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
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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(', '))
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue