aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts16
-rw-r--r--server/controllers/static.ts13
-rw-r--r--server/tests/api/videos/video-blacklist.ts58
3 files changed, 75 insertions, 12 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index bfb690906..dcba0e08f 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -26,6 +26,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
26import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 26import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' 27import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
28import { ThumbnailModel } from '../../../models/video/thumbnail' 28import { ThumbnailModel } from '../../../models/video/thumbnail'
29import { UserModel } from '../../../models/account/user'
29 30
30const auditLogger = auditLoggerFactory('video-imports') 31const auditLogger = auditLoggerFactory('video-imports')
31const videoImportsRouter = express.Router() 32const videoImportsRouter = express.Router()
@@ -107,7 +108,8 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
107 previewModel, 108 previewModel,
108 videoChannel: res.locals.videoChannel, 109 videoChannel: res.locals.videoChannel,
109 tags, 110 tags,
110 videoImportAttributes 111 videoImportAttributes,
112 user
111 }) 113 })
112 114
113 // Create job to import the video 115 // Create job to import the video
@@ -151,12 +153,13 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
151 userId: user.id 153 userId: user.id
152 } 154 }
153 const videoImport = await insertIntoDB({ 155 const videoImport = await insertIntoDB({
154 video: video, 156 video,
155 thumbnailModel, 157 thumbnailModel,
156 previewModel, 158 previewModel,
157 videoChannel: res.locals.videoChannel, 159 videoChannel: res.locals.videoChannel,
158 tags, 160 tags,
159 videoImportAttributes 161 videoImportAttributes,
162 user
160 }) 163 })
161 164
162 // Create job to import the video 165 // Create job to import the video
@@ -227,9 +230,10 @@ function insertIntoDB (parameters: {
227 previewModel: ThumbnailModel, 230 previewModel: ThumbnailModel,
228 videoChannel: VideoChannelModel, 231 videoChannel: VideoChannelModel,
229 tags: string[], 232 tags: string[],
230 videoImportAttributes: Partial<VideoImportModel> 233 videoImportAttributes: Partial<VideoImportModel>,
234 user: UserModel
231}): Bluebird<VideoImportModel> { 235}): Bluebird<VideoImportModel> {
232 let { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes } = parameters 236 const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
233 237
234 return sequelizeTypescript.transaction(async t => { 238 return sequelizeTypescript.transaction(async t => {
235 const sequelizeOptions = { transaction: t } 239 const sequelizeOptions = { transaction: t }
@@ -241,7 +245,7 @@ function insertIntoDB (parameters: {
241 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) 245 if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
242 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) 246 if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
243 247
244 await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) 248 await autoBlacklistVideoIfNeeded(video, user, t)
245 249
246 // Set tags to the video 250 // Set tags to the video
247 if (tags) { 251 if (tags) {
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index d57dba6ce..a6b462443 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -156,6 +156,19 @@ staticRouter.use('/.well-known/change-password',
156 } 156 }
157) 157)
158 158
159staticRouter.use('/.well-known/host-meta',
160 (_, res: express.Response) => {
161 res.type('application/xml')
162
163 const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
164 '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +
165 ` <Link rel="lrdd" type="application/xrd+xml" template="${WEBSERVER.URL}/.well-known/webfinger?resource={uri}"/>\n` +
166 '</XRD>'
167
168 res.send(xml).end()
169 }
170)
171
159// --------------------------------------------------------------------------- 172// ---------------------------------------------------------------------------
160 173
161export { 174export {
diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts
index e907bbdc0..8760a4787 100644
--- a/server/tests/api/videos/video-blacklist.ts
+++ b/server/tests/api/videos/video-blacklist.ts
@@ -4,10 +4,11 @@ import * as chai from 'chai'
4import { orderBy } from 'lodash' 4import { orderBy } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { 6import {
7 addVideoToBlacklist, cleanupTests, 7 addVideoToBlacklist,
8 cleanupTests,
8 createUser, 9 createUser,
9 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
10 getBlacklistedVideosList, 11 getBlacklistedVideosList, getMyUserInformation,
11 getMyVideos, 12 getMyVideos,
12 getVideosList, 13 getVideosList,
13 killallServers, 14 killallServers,
@@ -16,6 +17,7 @@ import {
16 searchVideo, 17 searchVideo,
17 ServerInfo, 18 ServerInfo,
18 setAccessTokensToServers, 19 setAccessTokensToServers,
20 setDefaultVideoChannel,
19 updateVideo, 21 updateVideo,
20 updateVideoBlacklist, 22 updateVideoBlacklist,
21 uploadVideo, 23 uploadVideo,
@@ -25,7 +27,8 @@ import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
25import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
26import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' 28import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
27import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 29import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
28import { UserRole } from '../../../../shared/models/users' 30import { User, UserRole, UserUpdateMe } from '../../../../shared/models/users'
31import { getMagnetURI, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
29 32
30const expect = chai.expect 33const expect = chai.expect
31 34
@@ -351,6 +354,7 @@ describe('Test video blacklist', function () {
351 describe('When auto blacklist videos', function () { 354 describe('When auto blacklist videos', function () {
352 let userWithoutFlag: string 355 let userWithoutFlag: string
353 let userWithFlag: string 356 let userWithFlag: string
357 let channelOfUserWithoutFlag: number
354 358
355 before(async function () { 359 before(async function () {
356 this.timeout(20000) 360 this.timeout(20000)
@@ -380,6 +384,10 @@ describe('Test video blacklist', function () {
380 }) 384 })
381 385
382 userWithoutFlag = await userLogin(servers[0], user) 386 userWithoutFlag = await userLogin(servers[0], user)
387
388 const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
389 const body: User = res.body
390 channelOfUserWithoutFlag = body.videoChannels[0].id
383 } 391 }
384 392
385 { 393 {
@@ -399,7 +407,7 @@ describe('Test video blacklist', function () {
399 await waitJobs(servers) 407 await waitJobs(servers)
400 }) 408 })
401 409
402 it('Should auto blacklist a video', async function () { 410 it('Should auto blacklist a video on upload', async function () {
403 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 411 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
404 412
405 const res = await getBlacklistedVideosList({ 413 const res = await getBlacklistedVideosList({
@@ -412,7 +420,45 @@ describe('Test video blacklist', function () {
412 expect(res.body.data[0].video.name).to.equal('blacklisted') 420 expect(res.body.data[0].video.name).to.equal('blacklisted')
413 }) 421 })
414 422
415 it('Should not auto blacklist a video', async function () { 423 it('Should auto blacklist a video on URL import', async function () {
424 const attributes = {
425 targetUrl: getYoutubeVideoUrl(),
426 name: 'URL import',
427 channelId: channelOfUserWithoutFlag
428 }
429 await importVideo(servers[ 0 ].url, userWithoutFlag, attributes)
430
431 const res = await getBlacklistedVideosList({
432 url: servers[ 0 ].url,
433 token: servers[ 0 ].accessToken,
434 sort: 'createdAt',
435 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
436 })
437
438 expect(res.body.total).to.equal(2)
439 expect(res.body.data[1].video.name).to.equal('URL import')
440 })
441
442 it('Should auto blacklist a video on torrent import', async function () {
443 const attributes = {
444 magnetUri: getMagnetURI(),
445 name: 'Torrent import',
446 channelId: channelOfUserWithoutFlag
447 }
448 await importVideo(servers[ 0 ].url, userWithoutFlag, attributes)
449
450 const res = await getBlacklistedVideosList({
451 url: servers[ 0 ].url,
452 token: servers[ 0 ].accessToken,
453 sort: 'createdAt',
454 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
455 })
456
457 expect(res.body.total).to.equal(3)
458 expect(res.body.data[2].video.name).to.equal('Torrent import')
459 })
460
461 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
416 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 462 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
417 463
418 const res = await getBlacklistedVideosList({ 464 const res = await getBlacklistedVideosList({
@@ -421,7 +467,7 @@ describe('Test video blacklist', function () {
421 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED 467 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
422 }) 468 })
423 469
424 expect(res.body.total).to.equal(1) 470 expect(res.body.total).to.equal(3)
425 }) 471 })
426 }) 472 })
427 473