aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-23 14:39:52 +0200
committerChocobozzz <me@florianbigard.com>2018-04-23 14:39:52 +0200
commit9d3ef9fe052ed29bd67566754cb28662bd122234 (patch)
tree7b704dbc0b2c8b4ca18bef2409d640d0019c3d0a /server/helpers
parent2a2c19dfef7a9aa313c6ca0798f271c9a63449a9 (diff)
downloadPeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.tar.gz
PeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.tar.zst
PeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.zip
Use ISO 639 for languages
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts13
-rw-r--r--server/helpers/custom-validators/videos.ts9
-rw-r--r--server/helpers/database-utils.ts2
3 files changed, 15 insertions, 9 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index d8986b2a0..8ec7df49a 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -49,9 +49,9 @@ function isVideoTorrentObjectValid (video: any) {
49 isActivityPubVideoDurationValid(video.duration) && 49 isActivityPubVideoDurationValid(video.duration) &&
50 isUUIDValid(video.uuid) && 50 isUUIDValid(video.uuid) &&
51 setValidRemoteTags(video) && 51 setValidRemoteTags(video) &&
52 (!video.category || isRemoteIdentifierValid(video.category)) && 52 (!video.category || isRemoteNumberIdentifierValid(video.category)) &&
53 (!video.licence || isRemoteIdentifierValid(video.licence)) && 53 (!video.licence || isRemoteNumberIdentifierValid(video.licence)) &&
54 (!video.language || isRemoteIdentifierValid(video.language)) && 54 (!video.language || isRemoteStringIdentifierValid(video.language)) &&
55 isVideoViewsValid(video.views) && 55 isVideoViewsValid(video.views) &&
56 isBooleanValid(video.sensitive) && 56 isBooleanValid(video.sensitive) &&
57 isBooleanValid(video.commentsEnabled) && 57 isBooleanValid(video.commentsEnabled) &&
@@ -72,6 +72,7 @@ export {
72 isVideoTorrentCreateActivityValid, 72 isVideoTorrentCreateActivityValid,
73 isVideoTorrentUpdateActivityValid, 73 isVideoTorrentUpdateActivityValid,
74 isVideoTorrentDeleteActivityValid, 74 isVideoTorrentDeleteActivityValid,
75 isRemoteStringIdentifierValid,
75 isVideoFlagValid, 76 isVideoFlagValid,
76 isVideoTorrentObjectValid 77 isVideoTorrentObjectValid
77} 78}
@@ -89,10 +90,14 @@ function setValidRemoteTags (video: any) {
89 return true 90 return true
90} 91}
91 92
92function isRemoteIdentifierValid (data: any) { 93function isRemoteNumberIdentifierValid (data: any) {
93 return validator.isInt(data.identifier, { min: 0 }) 94 return validator.isInt(data.identifier, { min: 0 })
94} 95}
95 96
97function isRemoteStringIdentifierValid (data: any) {
98 return typeof data.identifier === 'string'
99}
100
96function isRemoteVideoContentValid (mediaType: string, content: string) { 101function isRemoteVideoContentValid (mediaType: string, content: string) {
97 return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content) 102 return mediaType === 'text/markdown' && isVideoTruncatedDescriptionValid(content)
98} 103}
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index a46d715ba..23d2d8ac6 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -18,16 +18,17 @@ import { exists, isArray, isFileValid } from './misc'
18const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 18const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
19const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 19const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
20 20
21function isVideoCategoryValid (value: number) { 21function isVideoCategoryValid (value: any) {
22 return value === null || VIDEO_CATEGORIES[value] !== undefined 22 return value === null || VIDEO_CATEGORIES[value] !== undefined
23} 23}
24 24
25function isVideoLicenceValid (value: number) { 25function isVideoLicenceValid (value: any) {
26 return value === null || VIDEO_LICENCES[value] !== undefined 26 return value === null || VIDEO_LICENCES[value] !== undefined
27} 27}
28 28
29function isVideoLanguageValid (value: number) { 29function isVideoLanguageValid (value: any) {
30 return value === null || VIDEO_LANGUAGES[value] !== undefined 30 return value === null ||
31 (typeof value === 'string' && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.LANGUAGE))
31} 32}
32 33
33function isVideoDurationValid (value: string) { 34function isVideoDurationValid (value: string) {
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts
index 47a0abfd2..b3ff42a37 100644
--- a/server/helpers/database-utils.ts
+++ b/server/helpers/database-utils.ts
@@ -28,7 +28,7 @@ function transactionRetryer <T> (func: (err: any, data: T) => any) {
28 28
29 errorFilter: err => { 29 errorFilter: err => {
30 const willRetry = (err.name === 'SequelizeDatabaseError') 30 const willRetry = (err.name === 'SequelizeDatabaseError')
31 logger.debug('Maybe retrying the transaction function.', { willRetry }) 31 logger.debug('Maybe retrying the transaction function.', { willRetry, err })
32 return willRetry 32 return willRetry
33 } 33 }
34 }, func, (err, data) => err ? rej(err) : res(data)) 34 }, func, (err, data) => err ? rej(err) : res(data))