diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2018-07-25 22:01:25 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2018-07-25 22:01:25 +0200 |
commit | c1e791bad0b079af67398f6407221e6dcbb573dd (patch) | |
tree | 82e5944b4458dd35aa482a38f6b650eb93bb89ad /server/helpers | |
parent | 5f7021c33d31c5255b995ae0ff86b5bbea4ea4b9 (diff) | |
download | PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.gz PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.tar.zst PeerTube-c1e791bad0b079af67398f6407221e6dcbb573dd.zip |
expliciting type checks and predicates (server only)
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/activitypub.ts | 4 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 3 | ||||
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 8 | ||||
-rw-r--r-- | server/helpers/express-utils.ts | 2 | ||||
-rw-r--r-- | server/helpers/logger.ts | 3 | ||||
-rw-r--r-- | server/helpers/utils.ts | 3 |
7 files changed, 15 insertions, 12 deletions
diff --git a/server/helpers/activitypub.ts b/server/helpers/activitypub.ts index c49142a04..d710f5c97 100644 --- a/server/helpers/activitypub.ts +++ b/server/helpers/activitypub.ts | |||
@@ -67,8 +67,8 @@ async function activityPubCollectionPagination (url: string, handler: ActivityPu | |||
67 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 67 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
68 | const result = await handler(start, count) | 68 | const result = await handler(start, count) |
69 | 69 | ||
70 | let next: string | 70 | let next: string | undefined |
71 | let prev: string | 71 | let prev: string | undefined |
72 | 72 | ||
73 | // Assert page is a number | 73 | // Assert page is a number |
74 | page = parseInt(page, 10) | 74 | page = parseInt(page, 10) |
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index c560222d3..2951aef1e 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -42,7 +42,7 @@ function root () { | |||
42 | const paths = [ __dirname, '..', '..' ] | 42 | const paths = [ __dirname, '..', '..' ] |
43 | 43 | ||
44 | // We are under /dist directory | 44 | // We are under /dist directory |
45 | if (process.mainModule.filename.endsWith('.ts') === false) { | 45 | if (process.mainModule && process.mainModule.filename.endsWith('.ts') === false) { |
46 | paths.push('..') | 46 | paths.push('..') |
47 | } | 47 | } |
48 | 48 | ||
@@ -143,6 +143,7 @@ const renamePromise = promisify2WithVoid<string, string>(rename) | |||
143 | const writeFilePromise = promisify2WithVoid<string, any>(writeFile) | 143 | const writeFilePromise = promisify2WithVoid<string, any>(writeFile) |
144 | const readdirPromise = promisify1<string, string[]>(readdir) | 144 | const readdirPromise = promisify1<string, string[]>(readdir) |
145 | const mkdirpPromise = promisify1<string, string>(mkdirp) | 145 | const mkdirpPromise = promisify1<string, string>(mkdirp) |
146 | // we cannot modify the Promise types, so we should make the promisify instance check mkdirp | ||
146 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) | 147 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) |
147 | const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) | 148 | const createPrivateKey = promisify1<number, { key: string }>(pem.createPrivateKey) |
148 | const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) | 149 | const getPublicKey = promisify1<string, { publicKey: string }>(pem.getPublicKey) |
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 151fc852b..6d10a65a8 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -51,7 +51,7 @@ function isFileValid ( | |||
51 | files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], | 51 | files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], |
52 | mimeTypeRegex: string, | 52 | mimeTypeRegex: string, |
53 | field: string, | 53 | field: string, |
54 | maxSize: number, | 54 | maxSize: number | null, |
55 | optional = false | 55 | optional = false |
56 | ) { | 56 | ) { |
57 | // Should have files | 57 | // Should have files |
@@ -69,7 +69,7 @@ function isFileValid ( | |||
69 | if (!file || !file.originalname) return false | 69 | if (!file || !file.originalname) return false |
70 | 70 | ||
71 | // Check size | 71 | // Check size |
72 | if (maxSize && file.size > maxSize) return false | 72 | if ((maxSize !== null) && file.size > maxSize) return false |
73 | 73 | ||
74 | return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype) | 74 | return new RegExp(`^${mimeTypeRegex}$`, 'i').test(file.mimetype) |
75 | } | 75 | } |
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index b5cb126d9..70904af0c 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts | |||
@@ -150,7 +150,7 @@ function checkUserCanManageVideo (user: UserModel, video: VideoModel, right: Use | |||
150 | } | 150 | } |
151 | 151 | ||
152 | async function isVideoExist (id: string, res: Response) { | 152 | async function isVideoExist (id: string, res: Response) { |
153 | let video: VideoModel | 153 | let video: VideoModel | null |
154 | 154 | ||
155 | if (validator.isInt(id)) { | 155 | if (validator.isInt(id)) { |
156 | video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) | 156 | video = await VideoModel.loadAndPopulateAccountAndServerAndTags(+id) |
@@ -158,7 +158,7 @@ async function isVideoExist (id: string, res: Response) { | |||
158 | video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) | 158 | video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(id) |
159 | } | 159 | } |
160 | 160 | ||
161 | if (!video) { | 161 | if (video && video !== null) { |
162 | res.status(404) | 162 | res.status(404) |
163 | .json({ error: 'Video not found' }) | 163 | .json({ error: 'Video not found' }) |
164 | .end() | 164 | .end() |
@@ -173,7 +173,7 @@ async function isVideoExist (id: string, res: Response) { | |||
173 | async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { | 173 | async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, res: Response) { |
174 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { | 174 | if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { |
175 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) | 175 | const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) |
176 | if (!videoChannel) { | 176 | if (videoChannel && videoChannel !== null) { |
177 | res.status(400) | 177 | res.status(400) |
178 | .json({ error: 'Unknown video video channel on this instance.' }) | 178 | .json({ error: 'Unknown video video channel on this instance.' }) |
179 | .end() | 179 | .end() |
@@ -186,7 +186,7 @@ async function isVideoChannelOfAccountExist (channelId: number, user: UserModel, | |||
186 | } | 186 | } |
187 | 187 | ||
188 | const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) | 188 | const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) |
189 | if (!videoChannel) { | 189 | if (videoChannel && videoChannel !== null) { |
190 | res.status(400) | 190 | res.status(400) |
191 | .json({ error: 'Unknown video video channel for this account.' }) | 191 | .json({ error: 'Unknown video video channel for this account.' }) |
192 | .end() | 192 | .end() |
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index 76440348f..f136a4329 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts | |||
@@ -64,7 +64,7 @@ function createReqFiles ( | |||
64 | } | 64 | } |
65 | }) | 65 | }) |
66 | 66 | ||
67 | const fields = [] | 67 | let fields: { name: string, maxCount: number }[] = [] |
68 | for (const fieldName of fieldNames) { | 68 | for (const fieldName of fieldNames) { |
69 | fields.push({ | 69 | fields.push({ |
70 | name: fieldName, | 70 | name: fieldName, |
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 04ddf01a6..7fdfe2125 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -80,7 +80,8 @@ const logger = winston.createLogger({ | |||
80 | function bunyanLogFactory (level: string) { | 80 | function bunyanLogFactory (level: string) { |
81 | return function () { | 81 | return function () { |
82 | let meta = null | 82 | let meta = null |
83 | let args = [].concat(arguments) | 83 | let args: any[] = [] |
84 | args.concat(arguments) | ||
84 | 85 | ||
85 | if (arguments[ 0 ] instanceof Error) { | 86 | if (arguments[ 0 ] instanceof Error) { |
86 | meta = arguments[ 0 ].toString() | 87 | meta = arguments[ 0 ].toString() |
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 9efc89d92..7ff1556e3 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts | |||
@@ -52,7 +52,7 @@ async function isSignupAllowed () { | |||
52 | function isSignupAllowedForCurrentIP (ip: string) { | 52 | function isSignupAllowedForCurrentIP (ip: string) { |
53 | const addr = ipaddr.parse(ip) | 53 | const addr = ipaddr.parse(ip) |
54 | let excludeList = [ 'blacklist' ] | 54 | let excludeList = [ 'blacklist' ] |
55 | let matched: string | 55 | let matched = '' |
56 | 56 | ||
57 | // if there is a valid, non-empty whitelist, we exclude all unknown adresses too | 57 | // if there is a valid, non-empty whitelist, we exclude all unknown adresses too |
58 | if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) { | 58 | if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) { |
@@ -144,6 +144,7 @@ let serverActor: ActorModel | |||
144 | async function getServerActor () { | 144 | async function getServerActor () { |
145 | if (serverActor === undefined) { | 145 | if (serverActor === undefined) { |
146 | const application = await ApplicationModel.load() | 146 | const application = await ApplicationModel.load() |
147 | if (!application) throw Error('Could not application.') | ||
147 | serverActor = application.Account.Actor | 148 | serverActor = application.Account.Actor |
148 | } | 149 | } |
149 | 150 | ||