import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
import { ThumbnailType } from '../../../../shared/models/videos/thumbnail.type'
import { ThumbnailModel } from '../../../models/video/thumbnail'
+import { UserModel } from '../../../models/account/user'
const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router()
previewModel,
videoChannel: res.locals.videoChannel,
tags,
- videoImportAttributes
+ videoImportAttributes,
+ user
})
// Create job to import the video
userId: user.id
}
const videoImport = await insertIntoDB({
- video: video,
+ video,
thumbnailModel,
previewModel,
videoChannel: res.locals.videoChannel,
tags,
- videoImportAttributes
+ videoImportAttributes,
+ user
})
// Create job to import the video
previewModel: ThumbnailModel,
videoChannel: VideoChannelModel,
tags: string[],
- videoImportAttributes: Partial<VideoImportModel>
+ videoImportAttributes: Partial<VideoImportModel>,
+ user: UserModel
}): Bluebird<VideoImportModel> {
- let { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes } = parameters
+ const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
return sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t }
if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, 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
if (tags) {
import { orderBy } from 'lodash'
import 'mocha'
import {
- addVideoToBlacklist, cleanupTests,
+ addVideoToBlacklist,
+ cleanupTests,
createUser,
flushAndRunMultipleServers,
- getBlacklistedVideosList,
+ getBlacklistedVideosList, getMyUserInformation,
getMyVideos,
getVideosList,
killallServers,
searchVideo,
ServerInfo,
setAccessTokensToServers,
+ setDefaultVideoChannel,
updateVideo,
updateVideoBlacklist,
uploadVideo,
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
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
describe('When auto blacklist videos', function () {
let userWithoutFlag: string
let userWithFlag: string
+ let channelOfUserWithoutFlag: number
before(async function () {
this.timeout(20000)
})
userWithoutFlag = await userLogin(servers[0], user)
+
+ const res = await getMyUserInformation(servers[0].url, userWithoutFlag)
+ const body: User = res.body
+ channelOfUserWithoutFlag = body.videoChannels[0].id
}
{
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' })
const res = await getBlacklistedVideosList({
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' })
const res = await getBlacklistedVideosList({
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
- expect(res.body.total).to.equal(1)
+ expect(res.body.total).to.equal(3)
})
})