Fix video import if autoblacklist is enabled

pull/1935/head
Chocobozzz 2019-06-07 14:34:11 +02:00
parent e5b432e04e
commit 03371ad9d0
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 63 additions and 13 deletions

View File

@ -26,6 +26,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type' import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import { ThumbnailModel } from '../../../models/video/thumbnail' import { ThumbnailModel } from '../../../models/video/thumbnail'
import { UserModel } from '../../../models/account/user'
const auditLogger = auditLoggerFactory('video-imports') const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router() const videoImportsRouter = express.Router()
@ -107,7 +108,8 @@ async function addTorrentImport (req: express.Request, res: express.Response, to
previewModel, previewModel,
videoChannel: res.locals.videoChannel, videoChannel: res.locals.videoChannel,
tags, tags,
videoImportAttributes videoImportAttributes,
user
}) })
// Create job to import the video // Create job to import the video
@ -151,12 +153,13 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
userId: user.id userId: user.id
} }
const videoImport = await insertIntoDB({ const videoImport = await insertIntoDB({
video: video, video,
thumbnailModel, thumbnailModel,
previewModel, previewModel,
videoChannel: res.locals.videoChannel, videoChannel: res.locals.videoChannel,
tags, tags,
videoImportAttributes videoImportAttributes,
user
}) })
// Create job to import the video // Create job to import the video
@ -227,9 +230,10 @@ function insertIntoDB (parameters: {
previewModel: ThumbnailModel, previewModel: ThumbnailModel,
videoChannel: VideoChannelModel, videoChannel: VideoChannelModel,
tags: string[], tags: string[],
videoImportAttributes: Partial<VideoImportModel> videoImportAttributes: Partial<VideoImportModel>,
user: UserModel
}): Bluebird<VideoImportModel> { }): Bluebird<VideoImportModel> {
let { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes } = parameters const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
return sequelizeTypescript.transaction(async t => { return sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t } const sequelizeOptions = { transaction: t }
@ -241,7 +245,7 @@ function insertIntoDB (parameters: {
if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t) if (previewModel) await videoCreated.addAndSaveThumbnail(previewModel, t)
await autoBlacklistVideoIfNeeded(video, videoChannel.Account.User, t) await autoBlacklistVideoIfNeeded(video, user, t)
// Set tags to the video // Set tags to the video
if (tags) { if (tags) {

View File

@ -158,7 +158,7 @@ staticRouter.use('/.well-known/change-password',
staticRouter.use('/.well-known/host-meta', staticRouter.use('/.well-known/host-meta',
(_, res: express.Response) => { (_, res: express.Response) => {
res.type('application/xml'); res.type('application/xml')
const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + const xml = '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' + '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">\n' +

View File

@ -4,10 +4,11 @@ import * as chai from 'chai'
import { orderBy } from 'lodash' import { orderBy } from 'lodash'
import 'mocha' import 'mocha'
import { import {
addVideoToBlacklist, cleanupTests, addVideoToBlacklist,
cleanupTests,
createUser, createUser,
flushAndRunMultipleServers, flushAndRunMultipleServers,
getBlacklistedVideosList, getBlacklistedVideosList, getMyUserInformation,
getMyVideos, getMyVideos,
getVideosList, getVideosList,
killallServers, killallServers,
@ -16,6 +17,7 @@ import {
searchVideo, searchVideo,
ServerInfo, ServerInfo,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel,
updateVideo, updateVideo,
updateVideoBlacklist, updateVideoBlacklist,
uploadVideo, uploadVideo,
@ -25,7 +27,8 @@ import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { UserRole } from '../../../../shared/models/users' import { User, UserRole, UserUpdateMe } from '../../../../shared/models/users'
import { getMagnetURI, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
const expect = chai.expect const expect = chai.expect
@ -351,6 +354,7 @@ describe('Test video blacklist', function () {
describe('When auto blacklist videos', function () { describe('When auto blacklist videos', function () {
let userWithoutFlag: string let userWithoutFlag: string
let userWithFlag: string let userWithFlag: string
let channelOfUserWithoutFlag: number
before(async function () { before(async function () {
this.timeout(20000) this.timeout(20000)
@ -380,6 +384,10 @@ describe('Test video blacklist', function () {
}) })
userWithoutFlag = await userLogin(servers[0], user) userWithoutFlag = await userLogin(servers[0], user)
const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
const body: User = res.body
channelOfUserWithoutFlag = body.videoChannels[0].id
} }
{ {
@ -399,7 +407,7 @@ describe('Test video blacklist', function () {
await waitJobs(servers) await waitJobs(servers)
}) })
it('Should auto blacklist a video', async function () { it('Should auto blacklist a video on upload', async function () {
await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
const res = await getBlacklistedVideosList({ const res = await getBlacklistedVideosList({
@ -412,7 +420,45 @@ describe('Test video blacklist', function () {
expect(res.body.data[0].video.name).to.equal('blacklisted') expect(res.body.data[0].video.name).to.equal('blacklisted')
}) })
it('Should not auto blacklist a video', async function () { it('Should auto blacklist a video on URL import', async function () {
const attributes = {
targetUrl: getYoutubeVideoUrl(),
name: 'URL import',
channelId: channelOfUserWithoutFlag
}
await importVideo(servers[ 0 ].url, userWithoutFlag, attributes)
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
sort: 'createdAt',
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(2)
expect(res.body.data[1].video.name).to.equal('URL import')
})
it('Should auto blacklist a video on torrent import', async function () {
const attributes = {
magnetUri: getMagnetURI(),
name: 'Torrent import',
channelId: channelOfUserWithoutFlag
}
await importVideo(servers[ 0 ].url, userWithoutFlag, attributes)
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
sort: 'createdAt',
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(3)
expect(res.body.data[2].video.name).to.equal('Torrent import')
})
it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
const res = await getBlacklistedVideosList({ const res = await getBlacklistedVideosList({
@ -421,7 +467,7 @@ describe('Test video blacklist', function () {
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
}) })
expect(res.body.total).to.equal(1) expect(res.body.total).to.equal(3)
}) })
}) })