diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/rate.ts | 4 | ||||
-rw-r--r-- | server/controllers/client.ts | 3 | ||||
-rw-r--r-- | server/helpers/core-utils.ts | 4 | ||||
-rw-r--r-- | server/helpers/database-utils.ts | 2 | ||||
-rw-r--r-- | server/helpers/peertube-crypto.ts | 6 | ||||
-rw-r--r-- | server/helpers/requests.ts | 4 | ||||
-rw-r--r-- | server/initializers/migrations/0080-video-channels.ts | 4 | ||||
-rw-r--r-- | server/middlewares/validators/pods.ts | 3 | ||||
-rw-r--r-- | server/models/user/user.ts | 3 | ||||
-rw-r--r-- | server/models/video/video.ts | 3 | ||||
-rw-r--r-- | server/tests/api/check-params/video-abuses.ts | 2 | ||||
-rw-r--r-- | server/tests/api/friends-advanced.ts | 12 | ||||
-rw-r--r-- | server/tests/real-world/real-world.ts | 14 | ||||
-rw-r--r-- | server/tests/real-world/tools/upload-directory.ts | 3 | ||||
-rw-r--r-- | server/tests/utils/servers.ts | 2 |
15 files changed, 32 insertions, 37 deletions
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 354c3d8f9..727984506 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -19,7 +19,7 @@ import { | |||
19 | videoRateValidator, | 19 | videoRateValidator, |
20 | asyncMiddleware | 20 | asyncMiddleware |
21 | } from '../../../middlewares' | 21 | } from '../../../middlewares' |
22 | import { UserVideoRateUpdate, VideoRateType } from '../../../../shared' | 22 | import { UserVideoRateUpdate } from '../../../../shared' |
23 | 23 | ||
24 | const rateVideoRouter = express.Router() | 24 | const rateVideoRouter = express.Router() |
25 | 25 | ||
@@ -73,7 +73,7 @@ async function rateVideo (req: express.Request, res: express.Response) { | |||
73 | if (rateType === 'none') { // Destroy previous rate | 73 | if (rateType === 'none') { // Destroy previous rate |
74 | await previousRate.destroy() | 74 | await previousRate.destroy() |
75 | } else { // Update previous rate | 75 | } else { // Update previous rate |
76 | previousRate.type = rateType as VideoRateType | 76 | previousRate.type = rateType |
77 | 77 | ||
78 | await previousRate.save() | 78 | await previousRate.save() |
79 | } | 79 | } |
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 2071b5f01..67ebfcf1d 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -122,9 +122,6 @@ async function generateWatchHtmlPage (req: express.Request, res: express.Respons | |||
122 | videoPromise | 122 | videoPromise |
123 | ]) | 123 | ]) |
124 | 124 | ||
125 | file = file as Buffer | ||
126 | video = video as VideoInstance | ||
127 | |||
128 | const html = file.toString() | 125 | const html = file.toString() |
129 | 126 | ||
130 | // Let Angular application handle errors | 127 | // Let Angular application handle errors |
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 33bbdca8b..3dae78144 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts | |||
@@ -103,11 +103,11 @@ const writeFilePromise = promisify2WithVoid<string, any>(writeFile) | |||
103 | const readdirPromise = promisify1<string, string[]>(readdir) | 103 | const readdirPromise = promisify1<string, string[]>(readdir) |
104 | const mkdirpPromise = promisify1<string, string>(mkdirp) | 104 | const mkdirpPromise = promisify1<string, string>(mkdirp) |
105 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) | 105 | const pseudoRandomBytesPromise = promisify1<number, Buffer>(pseudoRandomBytes) |
106 | const accessPromise = promisify1WithVoid<string|Buffer>(access) | 106 | const accessPromise = promisify1WithVoid<string | Buffer>(access) |
107 | const opensslExecPromise = promisify2WithVoid<string, any>(openssl.exec) | 107 | const opensslExecPromise = promisify2WithVoid<string, any>(openssl.exec) |
108 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | 108 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) |
109 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 109 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) |
110 | const bcryptHashPromise = promisify2<any, string|number, string>(bcrypt.hash) | 110 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) |
111 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) | 111 | const createTorrentPromise = promisify2<string, any, any>(createTorrent) |
112 | const rimrafPromise = promisify1WithVoid<string>(rimraf) | 112 | const rimrafPromise = promisify1WithVoid<string>(rimraf) |
113 | const statPromise = promisify1<string, Stats>(stat) | 113 | const statPromise = promisify1<string, Stats>(stat) |
diff --git a/server/helpers/database-utils.ts b/server/helpers/database-utils.ts index dcc9e2577..d62462d35 100644 --- a/server/helpers/database-utils.ts +++ b/server/helpers/database-utils.ts | |||
@@ -4,7 +4,7 @@ import * as retry from 'async/retry' | |||
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | 5 | ||
6 | type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } | 6 | type RetryTransactionWrapperOptions = { errorMessage: string, arguments?: any[] } |
7 | function retryTransactionWrapper (functionToRetry: (... args) => Promise<any>, options: RetryTransactionWrapperOptions) { | 7 | function retryTransactionWrapper (functionToRetry: (...args) => Promise<any>, options: RetryTransactionWrapperOptions) { |
8 | const args = options.arguments ? options.arguments : [] | 8 | const args = options.arguments ? options.arguments : [] |
9 | 9 | ||
10 | return transactionRetryer(callback => { | 10 | return transactionRetryer(callback => { |
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index fbc3bdcc2..10a226af4 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -40,7 +40,7 @@ function checkSignature (publicKey: string, data: string, hexSignature: string) | |||
40 | return isValid | 40 | return isValid |
41 | } | 41 | } |
42 | 42 | ||
43 | async function sign (data: string|Object) { | 43 | async function sign (data: string | Object) { |
44 | const sign = crypto.createSign(SIGNATURE_ALGORITHM) | 44 | const sign = crypto.createSign(SIGNATURE_ALGORITHM) |
45 | 45 | ||
46 | let dataString: string | 46 | let dataString: string |
@@ -71,13 +71,13 @@ async function createCertsIfNotExist () { | |||
71 | return | 71 | return |
72 | } | 72 | } |
73 | 73 | ||
74 | return await createCerts() | 74 | return createCerts() |
75 | } | 75 | } |
76 | 76 | ||
77 | async function cryptPassword (password: string) { | 77 | async function cryptPassword (password: string) { |
78 | const salt = await bcryptGenSaltPromise(BCRYPT_SALT_SIZE) | 78 | const salt = await bcryptGenSaltPromise(BCRYPT_SALT_SIZE) |
79 | 79 | ||
80 | return await bcryptHashPromise(password, salt) | 80 | return bcryptHashPromise(password, salt) |
81 | } | 81 | } |
82 | 82 | ||
83 | function getMyPrivateCert () { | 83 | function getMyPrivateCert () { |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 8c5d848f3..af1f401de 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -13,7 +13,7 @@ import { sign } from './peertube-crypto' | |||
13 | 13 | ||
14 | type MakeRetryRequestParams = { | 14 | type MakeRetryRequestParams = { |
15 | url: string, | 15 | url: string, |
16 | method: 'GET'|'POST', | 16 | method: 'GET' | 'POST', |
17 | json: Object | 17 | json: Object |
18 | } | 18 | } |
19 | function makeRetryRequest (params: MakeRetryRequestParams) { | 19 | function makeRetryRequest (params: MakeRetryRequestParams) { |
@@ -31,7 +31,7 @@ function makeRetryRequest (params: MakeRetryRequestParams) { | |||
31 | } | 31 | } |
32 | 32 | ||
33 | type MakeSecureRequestParams = { | 33 | type MakeSecureRequestParams = { |
34 | method: 'GET'|'POST' | 34 | method: 'GET' | 'POST' |
35 | toPod: PodInstance | 35 | toPod: PodInstance |
36 | path: string | 36 | path: string |
37 | data?: Object | 37 | data?: Object |
diff --git a/server/initializers/migrations/0080-video-channels.ts b/server/initializers/migrations/0080-video-channels.ts index fc55ef3a2..f19721517 100644 --- a/server/initializers/migrations/0080-video-channels.ts +++ b/server/initializers/migrations/0080-video-channels.ts | |||
@@ -34,7 +34,7 @@ async function up (utils: { | |||
34 | // Create one author per user that does not already exist | 34 | // Create one author per user that does not already exist |
35 | const users = await utils.db.User.findAll() | 35 | const users = await utils.db.User.findAll() |
36 | for (const user of users) { | 36 | for (const user of users) { |
37 | const author = await utils.db.Author.find({ where: { userId: user.id }}) | 37 | const author = await utils.db.Author.find({ where: { userId: user.id } }) |
38 | if (!author) { | 38 | if (!author) { |
39 | await utils.db.Author.create({ | 39 | await utils.db.Author.create({ |
40 | name: user.username, | 40 | name: user.username, |
@@ -72,7 +72,7 @@ async function up (utils: { | |||
72 | const rawVideos = await utils.sequelize.query(query, options) | 72 | const rawVideos = await utils.sequelize.query(query, options) |
73 | 73 | ||
74 | for (const rawVideo of rawVideos) { | 74 | for (const rawVideo of rawVideos) { |
75 | const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId }}) | 75 | const videoChannel = await utils.db.VideoChannel.findOne({ where: { authorId: rawVideo.authorId } }) |
76 | 76 | ||
77 | const video = await utils.db.Video.findById(rawVideo.id) | 77 | const video = await utils.db.Video.findById(rawVideo.id) |
78 | video.channelId = videoChannel.id | 78 | video.channelId = videoChannel.id |
diff --git a/server/middlewares/validators/pods.ts b/server/middlewares/validators/pods.ts index 575c36526..8465fea53 100644 --- a/server/middlewares/validators/pods.ts +++ b/server/middlewares/validators/pods.ts | |||
@@ -3,10 +3,9 @@ import * as express from 'express' | |||
3 | 3 | ||
4 | import { database as db } from '../../initializers/database' | 4 | import { database as db } from '../../initializers/database' |
5 | import { checkErrors } from './utils' | 5 | import { checkErrors } from './utils' |
6 | import { logger, isEachUniqueHostValid } from '../../helpers' | 6 | import { logger, isEachUniqueHostValid, isTestInstance } from '../../helpers' |
7 | import { CONFIG } from '../../initializers' | 7 | import { CONFIG } from '../../initializers' |
8 | import { hasFriends } from '../../lib' | 8 | import { hasFriends } from '../../lib' |
9 | import { isTestInstance } from '../../helpers' | ||
10 | 9 | ||
11 | const makeFriendsValidator = [ | 10 | const makeFriendsValidator = [ |
12 | body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), | 11 | body('hosts').custom(isEachUniqueHostValid).withMessage('Should have an array of unique hosts'), |
diff --git a/server/models/user/user.ts b/server/models/user/user.ts index 3c625e450..c1e7abea6 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { getSort } from '../utils' | 4 | import { getSort, addMethodsToModel } from '../utils' |
5 | import { | 5 | import { |
6 | cryptPassword, | 6 | cryptPassword, |
7 | comparePassword, | 7 | comparePassword, |
@@ -13,7 +13,6 @@ import { | |||
13 | } from '../../helpers' | 13 | } from '../../helpers' |
14 | import { UserRight, USER_ROLE_LABELS, hasUserRight } from '../../../shared' | 14 | import { UserRight, USER_ROLE_LABELS, hasUserRight } from '../../../shared' |
15 | 15 | ||
16 | import { addMethodsToModel } from '../utils' | ||
17 | import { | 16 | import { |
18 | UserInstance, | 17 | UserInstance, |
19 | UserAttributes, | 18 | UserAttributes, |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2c1bd6b6e..02dde1726 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1,12 +1,11 @@ | |||
1 | import * as safeBuffer from 'safe-buffer' | 1 | import * as safeBuffer from 'safe-buffer' |
2 | const Buffer = safeBuffer.Buffer | 2 | const Buffer = safeBuffer.Buffer |
3 | import * as magnetUtil from 'magnet-uri' | 3 | import * as magnetUtil from 'magnet-uri' |
4 | import { map } from 'lodash' | 4 | import { map, maxBy, truncate } from 'lodash' |
5 | import * as parseTorrent from 'parse-torrent' | 5 | import * as parseTorrent from 'parse-torrent' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import * as Sequelize from 'sequelize' | 7 | import * as Sequelize from 'sequelize' |
8 | import * as Promise from 'bluebird' | 8 | import * as Promise from 'bluebird' |
9 | import { maxBy, truncate } from 'lodash' | ||
10 | 9 | ||
11 | import { TagInstance } from './tag-interface' | 10 | import { TagInstance } from './tag-interface' |
12 | import { | 11 | import { |
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts index 30d15778d..eac12b6f0 100644 --- a/server/tests/api/check-params/video-abuses.ts +++ b/server/tests/api/check-params/video-abuses.ts | |||
@@ -106,7 +106,7 @@ describe('Test video abuses API validators', function () { | |||
106 | it('Should fail with a wrong video', async function () { | 106 | it('Should fail with a wrong video', async function () { |
107 | const wrongPath = '/api/v1/videos/blabla/abuse' | 107 | const wrongPath = '/api/v1/videos/blabla/abuse' |
108 | const fields = {} | 108 | const fields = {} |
109 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields}) | 109 | await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) |
110 | }) | 110 | }) |
111 | 111 | ||
112 | it('Should fail with a non authenticated user', async function () { | 112 | it('Should fail with a non authenticated user', async function () { |
diff --git a/server/tests/api/friends-advanced.ts b/server/tests/api/friends-advanced.ts index 139019398..654c959fd 100644 --- a/server/tests/api/friends-advanced.ts +++ b/server/tests/api/friends-advanced.ts | |||
@@ -25,12 +25,12 @@ describe('Test advanced friends', function () { | |||
25 | 25 | ||
26 | async function makeFriendsWrapper (podNumber: number) { | 26 | async function makeFriendsWrapper (podNumber: number) { |
27 | const server = servers[podNumber - 1] | 27 | const server = servers[podNumber - 1] |
28 | return await makeFriends(server.url, server.accessToken) | 28 | return makeFriends(server.url, server.accessToken) |
29 | } | 29 | } |
30 | 30 | ||
31 | async function quitFriendsWrapper (podNumber: number) { | 31 | async function quitFriendsWrapper (podNumber: number) { |
32 | const server = servers[podNumber - 1] | 32 | const server = servers[podNumber - 1] |
33 | return await quitFriends(server.url, server.accessToken) | 33 | return quitFriends(server.url, server.accessToken) |
34 | } | 34 | } |
35 | 35 | ||
36 | async function removeFriendWrapper (podNumber: number, podNumberToRemove: number) { | 36 | async function removeFriendWrapper (podNumber: number, podNumberToRemove: number) { |
@@ -42,12 +42,12 @@ describe('Test advanced friends', function () { | |||
42 | let friendsList = res.body.data | 42 | let friendsList = res.body.data |
43 | let podToRemove = friendsList.find(friend => (friend.host === serverToRemove.host)) | 43 | let podToRemove = friendsList.find(friend => (friend.host === serverToRemove.host)) |
44 | 44 | ||
45 | return await quitOneFriend(server.url, server.accessToken, podToRemove.id) | 45 | return quitOneFriend(server.url, server.accessToken, podToRemove.id) |
46 | } | 46 | } |
47 | 47 | ||
48 | async function getFriendsListWrapper (podNumber: number) { | 48 | async function getFriendsListWrapper (podNumber: number) { |
49 | const server = servers[podNumber - 1] | 49 | const server = servers[podNumber - 1] |
50 | return await getFriendsList(server.url) | 50 | return getFriendsList(server.url) |
51 | } | 51 | } |
52 | 52 | ||
53 | async function uploadVideoWrapper (podNumber: number) { | 53 | async function uploadVideoWrapper (podNumber: number) { |
@@ -56,11 +56,11 @@ describe('Test advanced friends', function () { | |||
56 | } | 56 | } |
57 | const server = servers[podNumber - 1] | 57 | const server = servers[podNumber - 1] |
58 | 58 | ||
59 | return await uploadVideo(server.url, server.accessToken, videoAttributes) | 59 | return uploadVideo(server.url, server.accessToken, videoAttributes) |
60 | } | 60 | } |
61 | 61 | ||
62 | async function getVideosWrapper (podNumber: number) { | 62 | async function getVideosWrapper (podNumber: number) { |
63 | return await getVideosList(servers[podNumber - 1].url) | 63 | return getVideosList(servers[podNumber - 1].url) |
64 | } | 64 | } |
65 | 65 | ||
66 | // --------------------------------------------------------------- | 66 | // --------------------------------------------------------------- |
diff --git a/server/tests/real-world/real-world.ts b/server/tests/real-world/real-world.ts index e225a1266..da5696f8c 100644 --- a/server/tests/real-world/real-world.ts +++ b/server/tests/real-world/real-world.ts | |||
@@ -80,11 +80,15 @@ start() | |||
80 | async function start () { | 80 | async function start () { |
81 | const servers = await runServers(numberOfPods) | 81 | const servers = await runServers(numberOfPods) |
82 | 82 | ||
83 | process.on('exit', async () => await exitServers(servers, flushAtExit)) | 83 | process.on('exit', async () => { |
84 | await exitServers(servers, flushAtExit) | ||
85 | |||
86 | return | ||
87 | }) | ||
84 | process.on('SIGINT', goodbye) | 88 | process.on('SIGINT', goodbye) |
85 | process.on('SIGTERM', goodbye) | 89 | process.on('SIGTERM', goodbye) |
86 | 90 | ||
87 | console.log('Servers runned') | 91 | console.log('Servers ran') |
88 | initializeRequestsPerServer(servers) | 92 | initializeRequestsPerServer(servers) |
89 | 93 | ||
90 | let checking = false | 94 | let checking = false |
@@ -150,10 +154,8 @@ function getRandomNumServer (servers) { | |||
150 | } | 154 | } |
151 | 155 | ||
152 | async function runServers (numberOfPods: number) { | 156 | async function runServers (numberOfPods: number) { |
153 | let servers = null | 157 | const servers: ServerInfo[] = (await flushAndRunMultipleServers(numberOfPods)) |
154 | 158 | .map(s => Object.assign({ requestsNumber: 0 }, s)) | |
155 | // Run servers | ||
156 | servers = await flushAndRunMultipleServers(numberOfPods) | ||
157 | 159 | ||
158 | // Get the access tokens | 160 | // Get the access tokens |
159 | await setAccessTokensToServers(servers) | 161 | await setAccessTokensToServers(servers) |
diff --git a/server/tests/real-world/tools/upload-directory.ts b/server/tests/real-world/tools/upload-directory.ts index a8ab1669d..fdd56857a 100644 --- a/server/tests/real-world/tools/upload-directory.ts +++ b/server/tests/real-world/tools/upload-directory.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as program from 'commander' | 1 | import * as program from 'commander' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | import { isAbsolute } from 'path' | 3 | import { isAbsolute, join } from 'path' |
4 | import { join } from 'path' | ||
5 | 4 | ||
6 | import { readdirPromise } from '../../../helpers/core-utils' | 5 | import { readdirPromise } from '../../../helpers/core-utils' |
7 | import { execCLI } from '../../utils' | 6 | import { execCLI } from '../../utils' |
diff --git a/server/tests/utils/servers.ts b/server/tests/utils/servers.ts index 3526ffa51..f042a9e53 100644 --- a/server/tests/utils/servers.ts +++ b/server/tests/utils/servers.ts | |||
@@ -33,7 +33,7 @@ interface ServerInfo { | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | async function flushAndRunMultipleServers (totalServers) { | 36 | function flushAndRunMultipleServers (totalServers) { |
37 | let apps = [] | 37 | let apps = [] |
38 | let i = 0 | 38 | let i = 0 |
39 | 39 | ||