diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/models/i18n/i18n.ts | 9 | ||||
-rw-r--r-- | shared/models/server/job.model.ts | 3 | ||||
-rw-r--r-- | shared/models/server/server-config.model.ts | 4 | ||||
-rw-r--r-- | shared/models/users/user-update.model.ts | 1 | ||||
-rw-r--r-- | shared/models/users/user.model.ts | 1 | ||||
-rw-r--r-- | shared/utils/index.ts | 5 | ||||
-rw-r--r-- | shared/utils/miscs/miscs.ts | 8 | ||||
-rw-r--r-- | shared/utils/miscs/sql.ts | 38 | ||||
-rw-r--r-- | shared/utils/miscs/stubs.ts | 14 | ||||
-rw-r--r-- | shared/utils/requests/activitypub.ts | 43 | ||||
-rw-r--r-- | shared/utils/requests/requests.ts | 4 | ||||
-rw-r--r-- | shared/utils/server/activitypub.ts | 5 | ||||
-rw-r--r-- | shared/utils/server/servers.ts | 2 | ||||
-rw-r--r-- | shared/utils/users/blocklist.ts | 3 | ||||
-rw-r--r-- | shared/utils/users/users.ts | 2 | ||||
-rw-r--r-- | shared/utils/videos/videos.ts | 2 |
16 files changed, 127 insertions, 17 deletions
diff --git a/shared/models/i18n/i18n.ts b/shared/models/i18n/i18n.ts index 5c3249452..d7164b73f 100644 --- a/shared/models/i18n/i18n.ts +++ b/shared/models/i18n/i18n.ts | |||
@@ -8,12 +8,14 @@ export const I18N_LOCALES = { | |||
8 | 'cs-CZ': 'Čeština', | 8 | 'cs-CZ': 'Čeština', |
9 | 'eo': 'Esperanto', | 9 | 'eo': 'Esperanto', |
10 | 'de-DE': 'Deutsch', | 10 | 'de-DE': 'Deutsch', |
11 | 'it-IT': 'Italiano', | ||
11 | 'es-ES': 'Español', | 12 | 'es-ES': 'Español', |
12 | 'oc': 'Occitan', | 13 | 'oc': 'Occitan', |
13 | 'zh-Hant-TW': '繁體中文(台灣)', | 14 | 'zh-Hant-TW': '繁體中文(台灣)', |
14 | 'pt-BR': 'Português (Brasil)', | 15 | 'pt-BR': 'Português (Brasil)', |
15 | 'sv-SE': 'svenska', | 16 | 'sv-SE': 'svenska', |
16 | // 'pl-PL': 'Polski' | 17 | 'pl-PL': 'Polski', |
18 | 'ru-RU': 'русский', | ||
17 | 'zh-Hans-CN': '简体中文(中国)' | 19 | 'zh-Hans-CN': '简体中文(中国)' |
18 | } | 20 | } |
19 | 21 | ||
@@ -26,8 +28,9 @@ const I18N_LOCALE_ALIAS = { | |||
26 | 'de': 'de-DE', | 28 | 'de': 'de-DE', |
27 | 'es': 'es-ES', | 29 | 'es': 'es-ES', |
28 | 'pt': 'pt-BR', | 30 | 'pt': 'pt-BR', |
29 | 'sv': 'sv-SE' | 31 | 'sv': 'sv-SE', |
30 | // 'pl': 'pl-PL' | 32 | 'pl': 'pl-PL', |
33 | 'ru': 'ru-RU' | ||
31 | } | 34 | } |
32 | 35 | ||
33 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) | 36 | export const POSSIBLE_LOCALES = Object.keys(I18N_LOCALES) |
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 4046297c4..85bc9541b 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts | |||
@@ -8,7 +8,8 @@ export type JobType = 'activitypub-http-unicast' | | |||
8 | 'video-file' | | 8 | 'video-file' | |
9 | 'email' | | 9 | 'email' | |
10 | 'video-import' | | 10 | 'video-import' | |
11 | 'videos-views' | 11 | 'videos-views' | |
12 | 'activitypub-refresher' | ||
12 | 13 | ||
13 | export interface Job { | 14 | export interface Job { |
14 | id: number | 15 | id: number |
diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index 91196c1eb..a6d28e05e 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts | |||
@@ -15,6 +15,10 @@ export interface ServerConfig { | |||
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | email: { | ||
19 | enabled: boolean | ||
20 | } | ||
21 | |||
18 | signup: { | 22 | signup: { |
19 | allowed: boolean, | 23 | allowed: boolean, |
20 | allowedForCurrentIP: boolean, | 24 | allowedForCurrentIP: boolean, |
diff --git a/shared/models/users/user-update.model.ts b/shared/models/users/user-update.model.ts index ce866fb18..abde51321 100644 --- a/shared/models/users/user-update.model.ts +++ b/shared/models/users/user-update.model.ts | |||
@@ -2,6 +2,7 @@ import { UserRole } from './user-role' | |||
2 | 2 | ||
3 | export interface UserUpdate { | 3 | export interface UserUpdate { |
4 | email?: string | 4 | email?: string |
5 | emailVerified?: boolean | ||
5 | videoQuota?: number | 6 | videoQuota?: number |
6 | videoQuotaDaily?: number | 7 | videoQuotaDaily?: number |
7 | role?: UserRole | 8 | role?: UserRole |
diff --git a/shared/models/users/user.model.ts b/shared/models/users/user.model.ts index 8147dc48e..82af17516 100644 --- a/shared/models/users/user.model.ts +++ b/shared/models/users/user.model.ts | |||
@@ -7,6 +7,7 @@ export interface User { | |||
7 | id: number | 7 | id: number |
8 | username: string | 8 | username: string |
9 | email: string | 9 | email: string |
10 | emailVerified: boolean | ||
10 | nsfwPolicy: NSFWPolicyType | 11 | nsfwPolicy: NSFWPolicyType |
11 | autoPlayVideo: boolean | 12 | autoPlayVideo: boolean |
12 | role: UserRole | 13 | role: UserRole |
diff --git a/shared/utils/index.ts b/shared/utils/index.ts index 897389824..e08bbfd2a 100644 --- a/shared/utils/index.ts +++ b/shared/utils/index.ts | |||
@@ -2,10 +2,15 @@ export * from './server/activitypub' | |||
2 | export * from './cli/cli' | 2 | export * from './cli/cli' |
3 | export * from './server/clients' | 3 | export * from './server/clients' |
4 | export * from './server/config' | 4 | export * from './server/config' |
5 | export * from './server/jobs' | ||
5 | export * from './users/login' | 6 | export * from './users/login' |
6 | export * from './miscs/miscs' | 7 | export * from './miscs/miscs' |
8 | export * from './miscs/stubs' | ||
9 | export * from './miscs/sql' | ||
7 | export * from './server/follows' | 10 | export * from './server/follows' |
11 | export * from './requests/activitypub' | ||
8 | export * from './requests/requests' | 12 | export * from './requests/requests' |
13 | export * from './requests/check-api-params' | ||
9 | export * from './server/servers' | 14 | export * from './server/servers' |
10 | export * from './videos/services' | 15 | export * from './videos/services' |
11 | export * from './users/users' | 16 | export * from './users/users' |
diff --git a/shared/utils/miscs/miscs.ts b/shared/utils/miscs/miscs.ts index 589daa420..91a93b631 100644 --- a/shared/utils/miscs/miscs.ts +++ b/shared/utils/miscs/miscs.ts | |||
@@ -33,8 +33,8 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | function root () { | 35 | function root () { |
36 | // We are in server/tests/utils/miscs | 36 | // We are in /shared/utils/miscs |
37 | return join(__dirname, '..', '..', '..', '..') | 37 | return join(__dirname, '..', '..', '..') |
38 | } | 38 | } |
39 | 39 | ||
40 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | 40 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { |
@@ -44,7 +44,7 @@ async function testImage (url: string, imageName: string, imagePath: string, ext | |||
44 | 44 | ||
45 | const body = res.body | 45 | const body = res.body |
46 | 46 | ||
47 | const data = await readFile(join(__dirname, '..', '..', 'fixtures', imageName + extension)) | 47 | const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) |
48 | const minLength = body.length - ((20 * body.length) / 100) | 48 | const minLength = body.length - ((20 * body.length) / 100) |
49 | const maxLength = body.length + ((20 * body.length) / 100) | 49 | const maxLength = body.length + ((20 * body.length) / 100) |
50 | 50 | ||
@@ -59,7 +59,7 @@ function buildAbsoluteFixturePath (path: string, customTravisPath = false) { | |||
59 | 59 | ||
60 | if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path) | 60 | if (customTravisPath && process.env.TRAVIS) return join(process.env.HOME, 'fixtures', path) |
61 | 61 | ||
62 | return join(__dirname, '..', '..', 'fixtures', path) | 62 | return join(root(), 'server', 'tests', 'fixtures', path) |
63 | } | 63 | } |
64 | 64 | ||
65 | async function generateHighBitrateVideo () { | 65 | async function generateHighBitrateVideo () { |
diff --git a/shared/utils/miscs/sql.ts b/shared/utils/miscs/sql.ts new file mode 100644 index 000000000..027f78131 --- /dev/null +++ b/shared/utils/miscs/sql.ts | |||
@@ -0,0 +1,38 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | function getSequelize (serverNumber: number) { | ||
4 | const dbname = 'peertube_test' + serverNumber | ||
5 | const username = 'peertube' | ||
6 | const password = 'peertube' | ||
7 | const host = 'localhost' | ||
8 | const port = 5432 | ||
9 | |||
10 | return new Sequelize(dbname, username, password, { | ||
11 | dialect: 'postgres', | ||
12 | host, | ||
13 | port, | ||
14 | operatorsAliases: false, | ||
15 | logging: false | ||
16 | }) | ||
17 | } | ||
18 | |||
19 | function setActorField (serverNumber: number, to: string, field: string, value: string) { | ||
20 | const seq = getSequelize(serverNumber) | ||
21 | |||
22 | const options = { type: Sequelize.QueryTypes.UPDATE } | ||
23 | |||
24 | return seq.query(`UPDATE actor SET "${field}" = '${value}' WHERE url = '${to}'`, options) | ||
25 | } | ||
26 | |||
27 | function setVideoField (serverNumber: number, uuid: string, field: string, value: string) { | ||
28 | const seq = getSequelize(serverNumber) | ||
29 | |||
30 | const options = { type: Sequelize.QueryTypes.UPDATE } | ||
31 | |||
32 | return seq.query(`UPDATE video SET "${field}" = '${value}' WHERE uuid = '${uuid}'`, options) | ||
33 | } | ||
34 | |||
35 | export { | ||
36 | setVideoField, | ||
37 | setActorField | ||
38 | } | ||
diff --git a/shared/utils/miscs/stubs.ts b/shared/utils/miscs/stubs.ts new file mode 100644 index 000000000..d1eb0e3b2 --- /dev/null +++ b/shared/utils/miscs/stubs.ts | |||
@@ -0,0 +1,14 @@ | |||
1 | function buildRequestStub (): any { | ||
2 | return { } | ||
3 | } | ||
4 | |||
5 | function buildResponseStub (): any { | ||
6 | return { | ||
7 | locals: {} | ||
8 | } | ||
9 | } | ||
10 | |||
11 | export { | ||
12 | buildResponseStub, | ||
13 | buildRequestStub | ||
14 | } | ||
diff --git a/shared/utils/requests/activitypub.ts b/shared/utils/requests/activitypub.ts new file mode 100644 index 000000000..e2348ace0 --- /dev/null +++ b/shared/utils/requests/activitypub.ts | |||
@@ -0,0 +1,43 @@ | |||
1 | import { doRequest } from '../../../server/helpers/requests' | ||
2 | import { HTTP_SIGNATURE } from '../../../server/initializers' | ||
3 | import { buildGlobalHeaders } from '../../../server/lib/job-queue/handlers/utils/activitypub-http-utils' | ||
4 | import { activityPubContextify } from '../../../server/helpers/activitypub' | ||
5 | |||
6 | function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { | ||
7 | const options = { | ||
8 | method: 'POST', | ||
9 | uri: url, | ||
10 | json: body, | ||
11 | httpSignature, | ||
12 | headers | ||
13 | } | ||
14 | |||
15 | return doRequest(options) | ||
16 | } | ||
17 | |||
18 | async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) { | ||
19 | const follow = { | ||
20 | type: 'Follow', | ||
21 | id: by.url + '/toto', | ||
22 | actor: by.url, | ||
23 | object: to.url | ||
24 | } | ||
25 | |||
26 | const body = activityPubContextify(follow) | ||
27 | |||
28 | const httpSignature = { | ||
29 | algorithm: HTTP_SIGNATURE.ALGORITHM, | ||
30 | authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, | ||
31 | keyId: by.url, | ||
32 | key: by.privateKey, | ||
33 | headers: HTTP_SIGNATURE.HEADERS_TO_SIGN | ||
34 | } | ||
35 | const headers = buildGlobalHeaders(body) | ||
36 | |||
37 | return makePOSTAPRequest(to.url, body, httpSignature, headers) | ||
38 | } | ||
39 | |||
40 | export { | ||
41 | makePOSTAPRequest, | ||
42 | makeFollowRequest | ||
43 | } | ||
diff --git a/shared/utils/requests/requests.ts b/shared/utils/requests/requests.ts index 5796540f7..77e9f6164 100644 --- a/shared/utils/requests/requests.ts +++ b/shared/utils/requests/requests.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | 2 | import { buildAbsoluteFixturePath, root } from '../miscs/miscs' |
3 | import { isAbsolute, join } from 'path' | 3 | import { isAbsolute, join } from 'path' |
4 | 4 | ||
5 | function makeGetRequest (options: { | 5 | function makeGetRequest (options: { |
@@ -142,7 +142,7 @@ function updateAvatarRequest (options: { | |||
142 | if (isAbsolute(options.fixture)) { | 142 | if (isAbsolute(options.fixture)) { |
143 | filePath = options.fixture | 143 | filePath = options.fixture |
144 | } else { | 144 | } else { |
145 | filePath = join(__dirname, '..', '..', 'fixtures', options.fixture) | 145 | filePath = join(root(), 'server', 'tests', 'fixtures', options.fixture) |
146 | } | 146 | } |
147 | 147 | ||
148 | return makeUploadRequest({ | 148 | return makeUploadRequest({ |
diff --git a/shared/utils/server/activitypub.ts b/shared/utils/server/activitypub.ts index cf3c1c3b3..eccb198ca 100644 --- a/shared/utils/server/activitypub.ts +++ b/shared/utils/server/activitypub.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import * as request from 'supertest' | 1 | import * as request from 'supertest' |
2 | 2 | ||
3 | function makeActivityPubGetRequest (url: string, path: string) { | 3 | function makeActivityPubGetRequest (url: string, path: string, expectedStatus = 200) { |
4 | return request(url) | 4 | return request(url) |
5 | .get(path) | 5 | .get(path) |
6 | .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') | 6 | .set('Accept', 'application/activity+json,text/html;q=0.9,\\*/\\*;q=0.8') |
7 | .expect(200) | 7 | .expect(expectedStatus) |
8 | .expect('Content-Type', /json/) | ||
9 | } | 8 | } |
10 | 9 | ||
11 | // --------------------------------------------------------------------------- | 10 | // --------------------------------------------------------------------------- |
diff --git a/shared/utils/server/servers.ts b/shared/utils/server/servers.ts index f358a21f1..88d2b390c 100644 --- a/shared/utils/server/servers.ts +++ b/shared/utils/server/servers.ts | |||
@@ -115,7 +115,7 @@ function runServer (serverNumber: number, configOverride?: Object, args = []) { | |||
115 | } | 115 | } |
116 | 116 | ||
117 | return new Promise<ServerInfo>(res => { | 117 | return new Promise<ServerInfo>(res => { |
118 | server.app = fork(join(__dirname, '..', '..', '..', '..', 'dist', 'server.js'), args, options) | 118 | server.app = fork(join(root(), 'dist', 'server.js'), args, options) |
119 | server.app.stdout.on('data', function onStdout (data) { | 119 | server.app.stdout.on('data', function onStdout (data) { |
120 | let dontContinue = false | 120 | let dontContinue = false |
121 | 121 | ||
diff --git a/shared/utils/users/blocklist.ts b/shared/utils/users/blocklist.ts index 0ead5e5f6..5feb84179 100644 --- a/shared/utils/users/blocklist.ts +++ b/shared/utils/users/blocklist.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* tslint:disable:no-unused-expression */ |
2 | 2 | ||
3 | import { makeDeleteRequest, makePostBodyRequest } from '../requests/requests' | 3 | import { makeGetRequest, makeDeleteRequest, makePostBodyRequest } from '../requests/requests' |
4 | import { makeGetRequest } from '../requests/requests' | ||
5 | 4 | ||
6 | function getAccountBlocklistByAccount ( | 5 | function getAccountBlocklistByAccount ( |
7 | url: string, | 6 | url: string, |
diff --git a/shared/utils/users/users.ts b/shared/utils/users/users.ts index d5d62a507..554e42c01 100644 --- a/shared/utils/users/users.ts +++ b/shared/utils/users/users.ts | |||
@@ -206,6 +206,7 @@ function updateUser (options: { | |||
206 | userId: number, | 206 | userId: number, |
207 | accessToken: string, | 207 | accessToken: string, |
208 | email?: string, | 208 | email?: string, |
209 | emailVerified?: boolean, | ||
209 | videoQuota?: number, | 210 | videoQuota?: number, |
210 | videoQuotaDaily?: number, | 211 | videoQuotaDaily?: number, |
211 | role?: UserRole | 212 | role?: UserRole |
@@ -214,6 +215,7 @@ function updateUser (options: { | |||
214 | 215 | ||
215 | const toSend = {} | 216 | const toSend = {} |
216 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email | 217 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
218 | if (options.emailVerified !== undefined && options.emailVerified !== null) toSend['emailVerified'] = options.emailVerified | ||
217 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota | 219 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota |
218 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily | 220 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily |
219 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role | 221 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role |
diff --git a/shared/utils/videos/videos.ts b/shared/utils/videos/videos.ts index 1ab3e7c4b..f5fcc6a8a 100644 --- a/shared/utils/videos/videos.ts +++ b/shared/utils/videos/videos.ts | |||
@@ -417,7 +417,7 @@ function rateVideo (url: string, accessToken: string, id: number, rating: string | |||
417 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { | 417 | function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: number) { |
418 | return new Promise<any>((res, rej) => { | 418 | return new Promise<any>((res, rej) => { |
419 | const torrentName = videoUUID + '-' + resolution + '.torrent' | 419 | const torrentName = videoUUID + '-' + resolution + '.torrent' |
420 | const torrentPath = join(__dirname, '..', '..', '..', '..', 'test' + server.serverNumber, 'torrents', torrentName) | 420 | const torrentPath = join(root(), 'test' + server.serverNumber, 'torrents', torrentName) |
421 | readFile(torrentPath, (err, data) => { | 421 | readFile(torrentPath, (err, data) => { |
422 | if (err) return rej(err) | 422 | if (err) return rej(err) |
423 | 423 | ||