diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-15 15:41:56 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 503c6f440abc8f5924c38c4bd63591cb6cefacec (patch) | |
tree | f369e338d3f6c4c0af574b234b8c53d368350fa5 | |
parent | 30ff39e7f07898ebb716c938123825c678b4e5af (diff) | |
download | PeerTube-503c6f440abc8f5924c38c4bd63591cb6cefacec.tar.gz PeerTube-503c6f440abc8f5924c38c4bd63591cb6cefacec.tar.zst PeerTube-503c6f440abc8f5924c38c4bd63591cb6cefacec.zip |
Add peertube plugin index website models
-rw-r--r-- | server/helpers/custom-validators/plugins.ts | 7 | ||||
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/middlewares/validators/config.ts | 5 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 5 | ||||
-rw-r--r-- | server/models/account/user.ts | 4 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-index.model.ts | 11 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-latest-version.model.ts | 5 | ||||
-rw-r--r-- | shared/models/plugins/peertube-plugin-list.model.ts | 10 |
8 files changed, 38 insertions, 11 deletions
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts index 064af9ead..e0a6f98a7 100644 --- a/server/helpers/custom-validators/plugins.ts +++ b/server/helpers/custom-validators/plugins.ts | |||
@@ -4,7 +4,6 @@ import { PluginType } from '../../../shared/models/plugins/plugin.type' | |||
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
5 | import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model' | 5 | import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model' |
6 | import { isUrlValid } from './activitypub/misc' | 6 | import { isUrlValid } from './activitypub/misc' |
7 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | ||
8 | 7 | ||
9 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS | 8 | const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS |
10 | 9 | ||
@@ -66,8 +65,8 @@ function isCSSPathsValid (css: any[]) { | |||
66 | return isArray(css) && css.every(c => isSafePath(c)) | 65 | return isArray(css) && css.every(c => isSafePath(c)) |
67 | } | 66 | } |
68 | 67 | ||
69 | function isThemeValid (name: string) { | 68 | function isThemeNameValid (name: string) { |
70 | return isPluginNameValid(name) && isThemeRegistered(name) | 69 | return isPluginNameValid(name) |
71 | } | 70 | } |
72 | 71 | ||
73 | function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { | 72 | function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { |
@@ -91,7 +90,7 @@ function isLibraryCodeValid (library: any) { | |||
91 | export { | 90 | export { |
92 | isPluginTypeValid, | 91 | isPluginTypeValid, |
93 | isPackageJSONValid, | 92 | isPackageJSONValid, |
94 | isThemeValid, | 93 | isThemeNameValid, |
95 | isPluginHomepage, | 94 | isPluginHomepage, |
96 | isPluginVersionValid, | 95 | isPluginVersionValid, |
97 | isPluginNameValid, | 96 | isPluginNameValid, |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 4163fe49d..2d487a263 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -171,7 +171,7 @@ const SCHEDULER_INTERVALS_MS = { | |||
171 | 171 | ||
172 | // --------------------------------------------------------------------------- | 172 | // --------------------------------------------------------------------------- |
173 | 173 | ||
174 | let CONSTRAINTS_FIELDS = { | 174 | const CONSTRAINTS_FIELDS = { |
175 | USERS: { | 175 | USERS: { |
176 | NAME: { min: 1, max: 120 }, // Length | 176 | NAME: { min: 1, max: 120 }, // Length |
177 | DESCRIPTION: { min: 3, max: 1000 }, // Length | 177 | DESCRIPTION: { min: 3, max: 1000 }, // Length |
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts index 31b131914..9c43da165 100644 --- a/server/middlewares/validators/config.ts +++ b/server/middlewares/validators/config.ts | |||
@@ -5,7 +5,8 @@ import { logger } from '../../helpers/logger' | |||
5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' | 5 | import { CustomConfig } from '../../../shared/models/server/custom-config.model' |
6 | import { Emailer } from '../../lib/emailer' | 6 | import { Emailer } from '../../lib/emailer' |
7 | import { areValidationErrors } from './utils' | 7 | import { areValidationErrors } from './utils' |
8 | import { isThemeValid } from '../../helpers/custom-validators/plugins' | 8 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
9 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | ||
9 | 10 | ||
10 | const customConfigUpdateValidator = [ | 11 | const customConfigUpdateValidator = [ |
11 | body('instance.name').exists().withMessage('Should have a valid instance name'), | 12 | body('instance.name').exists().withMessage('Should have a valid instance name'), |
@@ -48,7 +49,7 @@ const customConfigUpdateValidator = [ | |||
48 | body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), | 49 | body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), |
49 | body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), | 50 | body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), |
50 | 51 | ||
51 | body('theme.default').custom(isThemeValid).withMessage('Should have a valid theme'), | 52 | body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), |
52 | 53 | ||
53 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 54 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
54 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) | 55 | logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index df7f77b84..a507afc5b 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -28,7 +28,8 @@ import { ActorModel } from '../../models/activitypub/actor' | |||
28 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' | 28 | import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' |
29 | import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | 29 | import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' |
30 | import { UserRegister } from '../../../shared/models/users/user-register.model' | 30 | import { UserRegister } from '../../../shared/models/users/user-register.model' |
31 | import { isThemeValid } from '../../helpers/custom-validators/plugins' | 31 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
32 | import { isThemeRegistered } from '../../lib/plugins/theme-utils' | ||
32 | 33 | ||
33 | const usersAddValidator = [ | 34 | const usersAddValidator = [ |
34 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), | 35 | body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), |
@@ -207,7 +208,7 @@ const usersUpdateMeValidator = [ | |||
207 | .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), | 208 | .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), |
208 | body('theme') | 209 | body('theme') |
209 | .optional() | 210 | .optional() |
210 | .custom(isThemeValid).withMessage('Should have a valid theme'), | 211 | .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), |
211 | 212 | ||
212 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | 213 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { |
213 | logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) | 214 | logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) |
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 6f0b0e00f..0041bf577 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -52,7 +52,7 @@ import { ActorModel } from '../activitypub/actor' | |||
52 | import { ActorFollowModel } from '../activitypub/actor-follow' | 52 | import { ActorFollowModel } from '../activitypub/actor-follow' |
53 | import { VideoImportModel } from '../video/video-import' | 53 | import { VideoImportModel } from '../video/video-import' |
54 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' | 54 | import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' |
55 | import { isThemeValid } from '../../helpers/custom-validators/plugins' | 55 | import { isThemeNameValid } from '../../helpers/custom-validators/plugins' |
56 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' | 56 | import { getThemeOrDefault } from '../../lib/plugins/theme-utils' |
57 | 57 | ||
58 | enum ScopeNames { | 58 | enum ScopeNames { |
@@ -191,7 +191,7 @@ export class UserModel extends Model<UserModel> { | |||
191 | 191 | ||
192 | @AllowNull(false) | 192 | @AllowNull(false) |
193 | @Default(DEFAULT_THEME_NAME) | 193 | @Default(DEFAULT_THEME_NAME) |
194 | @Is('UserTheme', value => throwIfNotValid(value, isThemeValid, 'theme')) | 194 | @Is('UserTheme', value => throwIfNotValid(value, isThemeNameValid, 'theme')) |
195 | @Column | 195 | @Column |
196 | theme: string | 196 | theme: string |
197 | 197 | ||
diff --git a/shared/models/plugins/peertube-plugin-index.model.ts b/shared/models/plugins/peertube-plugin-index.model.ts new file mode 100644 index 000000000..2957a338d --- /dev/null +++ b/shared/models/plugins/peertube-plugin-index.model.ts | |||
@@ -0,0 +1,11 @@ | |||
1 | export interface PeerTubePluginIndex { | ||
2 | npmName: string | ||
3 | description: string | ||
4 | homepage: string | ||
5 | createdAt: Date | ||
6 | updatedAt: Date | ||
7 | |||
8 | popularity: number | ||
9 | |||
10 | latestVersion: string | ||
11 | } | ||
diff --git a/shared/models/plugins/peertube-plugin-latest-version.model.ts b/shared/models/plugins/peertube-plugin-latest-version.model.ts new file mode 100644 index 000000000..36dd3af54 --- /dev/null +++ b/shared/models/plugins/peertube-plugin-latest-version.model.ts | |||
@@ -0,0 +1,5 @@ | |||
1 | export interface PeertubePluginLatestVersion { | ||
2 | currentPeerTubeEngine?: string, | ||
3 | |||
4 | npmNames: string[] | ||
5 | } | ||
diff --git a/shared/models/plugins/peertube-plugin-list.model.ts b/shared/models/plugins/peertube-plugin-list.model.ts new file mode 100644 index 000000000..5f0ecce68 --- /dev/null +++ b/shared/models/plugins/peertube-plugin-list.model.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | import { PluginType } from './plugin.type' | ||
2 | |||
3 | export interface PeertubePluginList { | ||
4 | start: number | ||
5 | count: number | ||
6 | sort: string | ||
7 | pluginType?: PluginType | ||
8 | currentPeerTubeEngine?: string | ||
9 | search?: string | ||
10 | } | ||