aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-03 11:10:31 +0200
committerChocobozzz <me@florianbigard.com>2018-08-06 11:19:16 +0200
commit5d08a6a74e83f2e4dfe2f3ba7f5a39371e1bc89e (patch)
treedd992ea798c620b8bdb5bf5fd9b8f1b97d4410f2 /server
parent7e5f9f001d5de22c54748f935edc0c069028bb0e (diff)
downloadPeerTube-5d08a6a74e83f2e4dfe2f3ba7f5a39371e1bc89e.tar.gz
PeerTube-5d08a6a74e83f2e4dfe2f3ba7f5a39371e1bc89e.tar.zst
PeerTube-5d08a6a74e83f2e4dfe2f3ba7f5a39371e1bc89e.zip
Add import http enabled configuration
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/config.ts14
-rw-r--r--server/controllers/api/users.ts1
-rw-r--r--server/controllers/api/videos/import.ts4
-rw-r--r--server/helpers/audit-logger.ts6
-rw-r--r--server/initializers/checker.ts1
-rw-r--r--server/initializers/constants.ts7
-rw-r--r--server/middlewares/validators/config.ts1
-rw-r--r--server/middlewares/validators/video-imports.ts9
-rw-r--r--server/tests/api/check-params/config.ts7
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/video-imports.ts246
-rw-r--r--server/tests/api/server/config.ts9
-rw-r--r--server/tests/client.ts7
13 files changed, 306 insertions, 7 deletions
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 411b13539..acbeab70b 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -65,6 +65,13 @@ async function getConfig (req: express.Request, res: express.Response, next: exp
65 transcoding: { 65 transcoding: {
66 enabledResolutions 66 enabledResolutions
67 }, 67 },
68 import: {
69 video: {
70 http: {
71 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
72 }
73 }
74 },
68 avatar: { 75 avatar: {
69 file: { 76 file: {
70 size: { 77 size: {
@@ -225,6 +232,13 @@ function customConfig (): CustomConfig {
225 '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ], 232 '720p': CONFIG.TRANSCODING.RESOLUTIONS[ '720p' ],
226 '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ] 233 '1080p': CONFIG.TRANSCODING.RESOLUTIONS[ '1080p' ]
227 } 234 }
235 },
236 import: {
237 videos: {
238 http: {
239 enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
240 }
241 }
228 } 242 }
229 } 243 }
230} 244}
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 6e5f9913e..879ba3f91 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -68,7 +68,6 @@ usersRouter.get('/me/video-quota-used',
68 asyncMiddleware(getUserVideoQuotaUsed) 68 asyncMiddleware(getUserVideoQuotaUsed)
69) 69)
70 70
71
72usersRouter.get('/me/videos/imports', 71usersRouter.get('/me/videos/imports',
73 authenticate, 72 authenticate,
74 paginationValidator, 73 paginationValidator,
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 33ac83cb9..ee11b0741 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -77,7 +77,7 @@ async function addVideoImport (req: express.Request, res: express.Response) {
77 video.url = getVideoActivityPubUrl(video) 77 video.url = getVideoActivityPubUrl(video)
78 78
79 // Process thumbnail file? 79 // Process thumbnail file?
80 const thumbnailField = req.files['thumbnailfile'] 80 const thumbnailField = req.files ? req.files['thumbnailfile'] : undefined
81 let downloadThumbnail = true 81 let downloadThumbnail = true
82 if (thumbnailField) { 82 if (thumbnailField) {
83 const thumbnailPhysicalFile = thumbnailField[ 0 ] 83 const thumbnailPhysicalFile = thumbnailField[ 0 ]
@@ -86,7 +86,7 @@ async function addVideoImport (req: express.Request, res: express.Response) {
86 } 86 }
87 87
88 // Process preview file? 88 // Process preview file?
89 const previewField = req.files['previewfile'] 89 const previewField = req.files ? req.files['previewfile'] : undefined
90 let downloadPreview = true 90 let downloadPreview = true
91 if (previewField) { 91 if (previewField) {
92 const previewPhysicalFile = previewField[0] 92 const previewPhysicalFile = previewField[0]
diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts
index 031b1bfbd..db20df20f 100644
--- a/server/helpers/audit-logger.ts
+++ b/server/helpers/audit-logger.ts
@@ -246,11 +246,9 @@ class CustomConfigAuditView extends EntityAuditView {
246 const resolutionsDict = infos.transcoding.resolutions 246 const resolutionsDict = infos.transcoding.resolutions
247 const resolutionsArray = [] 247 const resolutionsArray = []
248 Object.entries(resolutionsDict).forEach(([resolution, isEnabled]) => { 248 Object.entries(resolutionsDict).forEach(([resolution, isEnabled]) => {
249 if (isEnabled) { 249 if (isEnabled) resolutionsArray.push(resolution)
250 resolutionsArray.push(resolution)
251 }
252 }) 250 })
253 infos.transcoding.resolutions = resolutionsArray 251 Object.assign({}, infos, { transcoding: { resolutions: resolutionsArray } })
254 super(customConfigKeysToKeep, 'config', infos) 252 super(customConfigKeysToKeep, 'config', infos)
255 } 253 }
256} 254}
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts
index f1c2e80a9..608123607 100644
--- a/server/initializers/checker.ts
+++ b/server/initializers/checker.ts
@@ -51,6 +51,7 @@ function checkMissedConfig () {
51 'cache.previews.size', 'admin.email', 51 'cache.previews.size', 'admin.email',
52 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', 52 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
53 'transcoding.enabled', 'transcoding.threads', 53 'transcoding.enabled', 'transcoding.threads',
54 'import.videos.http.enabled',
54 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', 55 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
55 'instance.default_nsfw_policy', 'instance.robots', 56 'instance.default_nsfw_policy', 'instance.robots',
56 'services.twitter.username', 'services.twitter.whitelisted' 57 'services.twitter.username', 'services.twitter.whitelisted'
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 5bfeb3746..069d9b2e8 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -206,6 +206,13 @@ const CONFIG = {
206 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') } 206 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
207 } 207 }
208 }, 208 },
209 IMPORT: {
210 VIDEOS: {
211 HTTP: {
212 get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
213 }
214 }
215 },
209 CACHE: { 216 CACHE: {
210 PREVIEWS: { 217 PREVIEWS: {
211 get SIZE () { return config.get<number>('cache.previews.size') } 218 get SIZE () { return config.get<number>('cache.previews.size') }
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index f58c0676c..9d303eee2 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -24,6 +24,7 @@ const customConfigUpdateValidator = [
24 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'), 24 body('transcoding.resolutions.480p').isBoolean().withMessage('Should have a valid transcoding 480p resolution enabled boolean'),
25 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'), 25 body('transcoding.resolutions.720p').isBoolean().withMessage('Should have a valid transcoding 720p resolution enabled boolean'),
26 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'), 26 body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
27 body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'),
27 28
28 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 29 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
29 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) 30 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
diff --git a/server/middlewares/validators/video-imports.ts b/server/middlewares/validators/video-imports.ts
index e0a552976..d806edfa3 100644
--- a/server/middlewares/validators/video-imports.ts
+++ b/server/middlewares/validators/video-imports.ts
@@ -7,6 +7,7 @@ import { getCommonVideoAttributes } from './videos'
7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../helpers/utils' 8import { cleanUpReqFiles } from '../../helpers/utils'
9import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos' 9import { isVideoChannelOfAccountExist, isVideoNameValid } from '../../helpers/custom-validators/videos'
10import { CONFIG } from '../../initializers/constants'
10 11
11const videoImportAddValidator = getCommonVideoAttributes().concat([ 12const videoImportAddValidator = getCommonVideoAttributes().concat([
12 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'), 13 body('targetUrl').custom(isVideoImportTargetUrlValid).withMessage('Should have a valid video import target URL'),
@@ -23,6 +24,14 @@ const videoImportAddValidator = getCommonVideoAttributes().concat([
23 const user = res.locals.oauth.token.User 24 const user = res.locals.oauth.token.User
24 25
25 if (areValidationErrors(req, res)) return cleanUpReqFiles(req) 26 if (areValidationErrors(req, res)) return cleanUpReqFiles(req)
27
28 if (CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) {
29 cleanUpReqFiles(req)
30 return res.status(409)
31 .json({ error: 'Import is not enabled on this instance.' })
32 .end()
33 }
34
26 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 35 if (!await isVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
27 36
28 return next() 37 return next()
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 03855237f..2742e26de 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -60,6 +60,13 @@ describe('Test config API validators', function () {
60 '720p': false, 60 '720p': false,
61 '1080p': false 61 '1080p': false
62 } 62 }
63 },
64 import: {
65 videos: {
66 http: {
67 enabled: false
68 }
69 }
63 } 70 }
64 } 71 }
65 72
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 820dde889..03fdd5c4e 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -10,4 +10,5 @@ import './video-captions'
10import './video-channels' 10import './video-channels'
11import './video-comments' 11import './video-comments'
12import './videos' 12import './videos'
13import './video-imports'
13import './search' 14import './search'
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
new file mode 100644
index 000000000..7f58efb74
--- /dev/null
+++ b/server/tests/api/check-params/video-imports.ts
@@ -0,0 +1,246 @@
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
5import { join } from 'path'
6import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
7import {
8 createUser,
9 flushTests,
10 getMyUserInformation,
11 immutableAssign,
12 killallServers,
13 makeGetRequest,
14 makePostBodyRequest,
15 makeUploadRequest,
16 runServer,
17 ServerInfo,
18 setAccessTokensToServers,
19 userLogin
20} from '../../utils'
21import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
22
23describe('Test video imports API validator', function () {
24 const path = '/api/v1/videos/imports'
25 let server: ServerInfo
26 let userAccessToken = ''
27 let accountName: string
28 let channelId: number
29 let channelUUID: string
30
31 // ---------------------------------------------------------------
32
33 before(async function () {
34 this.timeout(30000)
35
36 await flushTests()
37
38 server = await runServer(1)
39
40 await setAccessTokensToServers([ server ])
41
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser(server.url, server.accessToken, username, password)
45 userAccessToken = await userLogin(server, { username, password })
46
47 {
48 const res = await getMyUserInformation(server.url, server.accessToken)
49 channelId = res.body.videoChannels[ 0 ].id
50 channelUUID = res.body.videoChannels[ 0 ].uuid
51 accountName = res.body.account.name + '@' + res.body.account.host
52 }
53 })
54
55 describe('When listing my video imports', function () {
56 const myPath = '/api/v1/users/me/videos/imports'
57
58 it('Should fail with a bad start pagination', async function () {
59 await checkBadStartPagination(server.url, myPath, server.accessToken)
60 })
61
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myPath, server.accessToken)
64 })
65
66 it('Should fail with an incorrect sort', async function () {
67 await checkBadSortPagination(server.url, myPath, server.accessToken)
68 })
69
70 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
72 })
73 })
74
75 describe('When adding a video import', function () {
76 let baseCorrectParams
77
78 before(function () {
79 baseCorrectParams = {
80 targetUrl: 'https://youtu.be/msX3jv1XdvM',
81 name: 'my super name',
82 category: 5,
83 licence: 1,
84 language: 'pt',
85 nsfw: false,
86 commentsEnabled: true,
87 waitTranscoding: true,
88 description: 'my super description',
89 support: 'my super support text',
90 tags: [ 'tag1', 'tag2' ],
91 privacy: VideoPrivacy.PUBLIC,
92 channelId: channelId
93 }
94 })
95
96 it('Should fail with nothing', async function () {
97 const fields = {}
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 })
100
101 it('Should fail with a long name', async function () {
102 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
103
104 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
105 })
106
107 it('Should fail with a bad category', async function () {
108 const fields = immutableAssign(baseCorrectParams, { category: 125 })
109
110 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 })
112
113 it('Should fail with a bad licence', async function () {
114 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
115
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 })
118
119 it('Should fail with a bad language', async function () {
120 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
121
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 })
124
125 it('Should fail with a long description', async function () {
126 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
127
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 })
130
131 it('Should fail with a long support text', async function () {
132 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
133
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 })
136
137 it('Should fail without a channel', async function () {
138 const fields = omit(baseCorrectParams, 'channelId')
139
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 })
142
143 it('Should fail with a bad channel', async function () {
144 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
145
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 })
148
149 it('Should fail with another user channel', async function () {
150 const user = {
151 username: 'fake',
152 password: 'fake_password'
153 }
154 await createUser(server.url, server.accessToken, user.username, user.password)
155
156 const accessTokenUser = await userLogin(server, user)
157 const res = await getMyUserInformation(server.url, accessTokenUser)
158 const customChannelId = res.body.videoChannels[0].id
159
160 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
161
162 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
163 })
164
165 it('Should fail with too many tags', async function () {
166 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
167
168 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
169 })
170
171 it('Should fail with a tag length too low', async function () {
172 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
173
174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
175 })
176
177 it('Should fail with a tag length too big', async function () {
178 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
179
180 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 })
182
183 it('Should fail with an incorrect thumbnail file', async function () {
184 const fields = baseCorrectParams
185 const attaches = {
186 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
187 }
188
189 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
190 })
191
192 it('Should fail with a big thumbnail file', async function () {
193 const fields = baseCorrectParams
194 const attaches = {
195 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
196 }
197
198 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
199 })
200
201 it('Should fail with an incorrect preview file', async function () {
202 const fields = baseCorrectParams
203 const attaches = {
204 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
205 }
206
207 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
208 })
209
210 it('Should fail with a big preview file', async function () {
211 const fields = baseCorrectParams
212 const attaches = {
213 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
214 }
215
216 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
217 })
218
219 it('Should succeed with the correct parameters', async function () {
220 this.timeout(10000)
221
222 const fields = baseCorrectParams
223
224 {
225 await makePostBodyRequest({
226 url: server.url,
227 path,
228 token: server.accessToken,
229 fields,
230 statusCodeExpected: 200
231 })
232 }
233 })
234
235 it('Should forbid importing')
236 })
237
238 after(async function () {
239 killallServers([ server ])
240
241 // Keep the logs if the test failed
242 if (this['ok']) {
243 await flushTests()
244 }
245 })
246})
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index 1782a8623..b65061a5d 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -44,6 +44,7 @@ function checkInitialConfig (data: CustomConfig) {
44 expect(data.transcoding.resolutions['480p']).to.be.true 44 expect(data.transcoding.resolutions['480p']).to.be.true
45 expect(data.transcoding.resolutions['720p']).to.be.true 45 expect(data.transcoding.resolutions['720p']).to.be.true
46 expect(data.transcoding.resolutions['1080p']).to.be.true 46 expect(data.transcoding.resolutions['1080p']).to.be.true
47 expect(data.import.videos.http.enabled).to.be.true
47} 48}
48 49
49function checkUpdatedConfig (data: CustomConfig) { 50function checkUpdatedConfig (data: CustomConfig) {
@@ -70,6 +71,7 @@ function checkUpdatedConfig (data: CustomConfig) {
70 expect(data.transcoding.resolutions['480p']).to.be.true 71 expect(data.transcoding.resolutions['480p']).to.be.true
71 expect(data.transcoding.resolutions['720p']).to.be.false 72 expect(data.transcoding.resolutions['720p']).to.be.false
72 expect(data.transcoding.resolutions['1080p']).to.be.false 73 expect(data.transcoding.resolutions['1080p']).to.be.false
74 expect(data.import.videos.http.enabled).to.be.false
73} 75}
74 76
75describe('Test config', function () { 77describe('Test config', function () {
@@ -160,6 +162,13 @@ describe('Test config', function () {
160 '720p': false, 162 '720p': false,
161 '1080p': false 163 '1080p': false
162 } 164 }
165 },
166 import: {
167 videos: {
168 http: {
169 enabled: false
170 }
171 }
163 } 172 }
164 } 173 }
165 await updateCustomConfig(server.url, server.accessToken, newCustomConfig) 174 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
diff --git a/server/tests/client.ts b/server/tests/client.ts
index bcbac86e9..129b40cdf 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -164,6 +164,13 @@ describe('Test a client controllers', function () {
164 '720p': false, 164 '720p': false,
165 '1080p': false 165 '1080p': false
166 } 166 }
167 },
168 import: {
169 videos: {
170 http: {
171 enabled: false
172 }
173 }
167 } 174 }
168 } 175 }
169 await updateCustomConfig(server.url, server.accessToken, newCustomConfig) 176 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)