diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-12 14:06:33 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | b2195fafc292d6761c25fe51ca4e0328ab403424 (patch) | |
tree | 3c390aeb5c5b9648668961871e866bd5e1dde5a4 /server/models | |
parent | b5f919ac8eb2a1c20e26582fdfd377d687710d8f (diff) | |
download | PeerTube-b2195fafc292d6761c25fe51ca4e0328ab403424.tar.gz PeerTube-b2195fafc292d6761c25fe51ca4e0328ab403424.tar.zst PeerTube-b2195fafc292d6761c25fe51ca4e0328ab403424.zip |
WIP plugins: add storage manager
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/server/plugin.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index 340d49f3b..bd3d7a81e 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts | |||
@@ -9,7 +9,7 @@ import { | |||
9 | } from '../../helpers/custom-validators/plugins' | 9 | } from '../../helpers/custom-validators/plugins' |
10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' | 10 | import { PluginType } from '../../../shared/models/plugins/plugin.type' |
11 | import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model' | 11 | import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.model' |
12 | import { FindAndCountOptions } from 'sequelize' | 12 | import { FindAndCountOptions, json } from 'sequelize' |
13 | 13 | ||
14 | @DefaultScope(() => ({ | 14 | @DefaultScope(() => ({ |
15 | attributes: { | 15 | attributes: { |
@@ -142,6 +142,40 @@ export class PluginModel extends Model<PluginModel> { | |||
142 | .then(() => undefined) | 142 | .then(() => undefined) |
143 | } | 143 | } |
144 | 144 | ||
145 | static getData (pluginName: string, pluginType: PluginType, key: string) { | ||
146 | const query = { | ||
147 | raw: true, | ||
148 | attributes: [ [ json('storage.' + key), 'value' ] as any ], // FIXME: typings | ||
149 | where: { | ||
150 | name: pluginName, | ||
151 | type: pluginType | ||
152 | } | ||
153 | } | ||
154 | |||
155 | return PluginModel.findOne(query) | ||
156 | .then((c: any) => { | ||
157 | if (!c) return undefined | ||
158 | |||
159 | return c.value | ||
160 | }) | ||
161 | } | ||
162 | |||
163 | static storeData (pluginName: string, pluginType: PluginType, key: string, data: any) { | ||
164 | const query = { | ||
165 | where: { | ||
166 | name: pluginName, | ||
167 | type: pluginType | ||
168 | } | ||
169 | } | ||
170 | |||
171 | const toSave = { | ||
172 | [`storage.${key}`]: data | ||
173 | } | ||
174 | |||
175 | return PluginModel.update(toSave, query) | ||
176 | .then(() => undefined) | ||
177 | } | ||
178 | |||
145 | static listForApi (options: { | 179 | static listForApi (options: { |
146 | type?: PluginType, | 180 | type?: PluginType, |
147 | uninstalled?: boolean, | 181 | uninstalled?: boolean, |