Video blacklist refractoring
This commit is contained in:
parent
769d332177
commit
35bf0c83c8
|
@ -9,7 +9,7 @@ import { RequestSchedulersRoutes } from './request-schedulers'
|
|||
import { UsersRoutes } from './users'
|
||||
import { VideoAbusesRoutes } from './video-abuses'
|
||||
import { AdminGuard } from './admin-guard.service'
|
||||
import { BlacklistRoutes } from './blacklist'
|
||||
import { VideoBlacklistRoutes } from './video-blacklist'
|
||||
|
||||
const adminRoutes: Routes = [
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ const adminRoutes: Routes = [
|
|||
...RequestSchedulersRoutes,
|
||||
...UsersRoutes,
|
||||
...VideoAbusesRoutes,
|
||||
...BlacklistRoutes
|
||||
...VideoBlacklistRoutes
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -3,6 +3,5 @@ import { Component } from '@angular/core'
|
|||
@Component({
|
||||
template: '<router-outlet></router-outlet>'
|
||||
})
|
||||
|
||||
export class AdminComponent {
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { FriendsComponent, FriendAddComponent, FriendListComponent, FriendServic
|
|||
import { RequestSchedulersComponent, RequestSchedulersStatsComponent, RequestSchedulersService } from './request-schedulers'
|
||||
import { UsersComponent, UserAddComponent, UserUpdateComponent, UserListComponent, UserService } from './users'
|
||||
import { VideoAbusesComponent, VideoAbuseListComponent } from './video-abuses'
|
||||
import { BlacklistComponent, BlacklistListComponent, BlacklistService } from './blacklist'
|
||||
import { VideoBlacklistComponent, VideoBlacklistListComponent } from './video-blacklist'
|
||||
import { SharedModule } from '../shared'
|
||||
import { AdminGuard } from './admin-guard.service'
|
||||
|
||||
|
@ -31,8 +31,8 @@ import { AdminGuard } from './admin-guard.service'
|
|||
UserUpdateComponent,
|
||||
UserListComponent,
|
||||
|
||||
BlacklistComponent,
|
||||
BlacklistListComponent,
|
||||
VideoBlacklistComponent,
|
||||
VideoBlacklistListComponent,
|
||||
|
||||
VideoAbusesComponent,
|
||||
VideoAbuseListComponent
|
||||
|
@ -46,8 +46,7 @@ import { AdminGuard } from './admin-guard.service'
|
|||
FriendService,
|
||||
RequestSchedulersService,
|
||||
UserService,
|
||||
AdminGuard,
|
||||
BlacklistService
|
||||
AdminGuard
|
||||
]
|
||||
})
|
||||
export class AdminModule { }
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export * from './blacklist-list.component'
|
|
@ -1,27 +0,0 @@
|
|||
import { Routes } from '@angular/router'
|
||||
|
||||
import { BlacklistComponent } from './blacklist.component'
|
||||
import { BlacklistListComponent } from './blacklist-list'
|
||||
|
||||
export const BlacklistRoutes: Routes = [
|
||||
{
|
||||
path: 'blacklist',
|
||||
component: BlacklistComponent,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirectTo: 'list',
|
||||
pathMatch: 'full'
|
||||
},
|
||||
{
|
||||
path: 'list',
|
||||
component: BlacklistListComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Blacklisted videos'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,4 +0,0 @@
|
|||
export * from './shared'
|
||||
export * from './blacklist-list'
|
||||
export * from './blacklist.component'
|
||||
export * from './blacklist.routes'
|
|
@ -1 +0,0 @@
|
|||
export * from './blacklist.service'
|
|
@ -0,0 +1,3 @@
|
|||
export * from './video-blacklist-list'
|
||||
export * from './video-blacklist.component'
|
||||
export * from './video-blacklist.routes'
|
|
@ -0,0 +1 @@
|
|||
export * from './video-blacklist-list.component'
|
|
@ -18,8 +18,8 @@
|
|||
<p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
|
||||
<p-column header="Delete" styleClass="action-cell">
|
||||
<ng-template pTemplate="body" let-entry="rowData">
|
||||
<span (click)="removeVideoFromBlacklist(entry)" class="glyphicon glyphicon-remove glyphicon-black" title="Remove this video"></span>
|
||||
</ng-template>
|
||||
<span (click)="removeVideoFromBlacklist(entry)" class="glyphicon glyphicon-remove glyphicon-black" title="Remove this video from blacklist"></span>
|
||||
</ng-template>
|
||||
</p-column>
|
||||
</p-dataTable>
|
||||
</div>
|
|
@ -4,16 +4,15 @@ import { SortMeta } from 'primeng/components/common/sortmeta'
|
|||
import { NotificationsService } from 'angular2-notifications'
|
||||
|
||||
import { ConfirmService } from '../../../core'
|
||||
import { RestTable, RestPagination } from '../../../shared'
|
||||
import { BlacklistService } from '../shared'
|
||||
import { VideoBlacklistService, RestTable, RestPagination } from '../../../shared'
|
||||
import { BlacklistedVideo } from '../../../../../../shared'
|
||||
|
||||
@Component({
|
||||
selector: 'my-blacklist-list',
|
||||
templateUrl: './blacklist-list.component.html',
|
||||
selector: 'my-video-blacklist-list',
|
||||
templateUrl: './video-blacklist-list.component.html',
|
||||
styleUrls: []
|
||||
})
|
||||
export class BlacklistListComponent extends RestTable implements OnInit {
|
||||
export class VideoBlacklistListComponent extends RestTable implements OnInit {
|
||||
blacklist: BlacklistedVideo[] = []
|
||||
totalRecords = 0
|
||||
rowsPerPage = 10
|
||||
|
@ -23,7 +22,7 @@ export class BlacklistListComponent extends RestTable implements OnInit {
|
|||
constructor (
|
||||
private notificationsService: NotificationsService,
|
||||
private confirmService: ConfirmService,
|
||||
private blacklistService: BlacklistService
|
||||
private videoBlacklistService: VideoBlacklistService
|
||||
) {
|
||||
super()
|
||||
}
|
||||
|
@ -39,7 +38,7 @@ export class BlacklistListComponent extends RestTable implements OnInit {
|
|||
res => {
|
||||
if (res === false) return
|
||||
|
||||
this.blacklistService.removeVideoFromBlacklist(entry).subscribe(
|
||||
this.videoBlacklistService.removeVideoFromBlacklist(entry.videoId).subscribe(
|
||||
status => {
|
||||
this.notificationsService.success('Success', `Video ${entry.name} removed from the blacklist.`)
|
||||
this.loadData()
|
||||
|
@ -52,7 +51,7 @@ export class BlacklistListComponent extends RestTable implements OnInit {
|
|||
}
|
||||
|
||||
protected loadData () {
|
||||
this.blacklistService.getBlacklist(this.pagination, this.sort)
|
||||
this.videoBlacklistService.listBlacklist(this.pagination, this.sort)
|
||||
.subscribe(
|
||||
resultList => {
|
||||
this.blacklist = resultList.data
|
|
@ -3,6 +3,5 @@ import { Component } from '@angular/core'
|
|||
@Component({
|
||||
template: '<router-outlet></router-outlet>'
|
||||
})
|
||||
|
||||
export class BlacklistComponent {
|
||||
export class VideoBlacklistComponent {
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import { Routes } from '@angular/router'
|
||||
|
||||
import { VideoBlacklistComponent } from './video-blacklist.component'
|
||||
import { VideoBlacklistListComponent } from './video-blacklist-list'
|
||||
|
||||
export const VideoBlacklistRoutes: Routes = [
|
||||
{
|
||||
path: 'video-blacklist',
|
||||
component: VideoBlacklistComponent,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirectTo: 'list',
|
||||
pathMatch: 'full'
|
||||
},
|
||||
{
|
||||
path: 'list',
|
||||
component: VideoBlacklistListComponent,
|
||||
data: {
|
||||
meta: {
|
||||
title: 'Blacklisted videos'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -11,7 +11,7 @@ import { UserService } from './shared'
|
|||
})
|
||||
export class AppComponent implements OnInit {
|
||||
notificationOptions = {
|
||||
timeOut: 3000,
|
||||
timeOut: 5000,
|
||||
lastOnBottom: true,
|
||||
clickToClose: true,
|
||||
maxLength: 0,
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
Video abuses
|
||||
</a>
|
||||
|
||||
<a routerLink="/admin/blacklist/list" routerLinkActive="active">
|
||||
<a routerLink="/admin/video-blacklist/list" routerLinkActive="active">
|
||||
<span class="hidden-xs glyphicon glyphicon-eye-close"></span>
|
||||
Video blacklist
|
||||
</a>
|
||||
|
|
|
@ -4,5 +4,6 @@ export * from './rest'
|
|||
export * from './search'
|
||||
export * from './users'
|
||||
export * from './video-abuse'
|
||||
export * from './video-blacklist'
|
||||
export * from './shared.module'
|
||||
export * from './utils'
|
||||
|
|
|
@ -18,6 +18,7 @@ import { RestExtractor, RestService } from './rest'
|
|||
import { SearchComponent, SearchService } from './search'
|
||||
import { UserService } from './users'
|
||||
import { VideoAbuseService } from './video-abuse'
|
||||
import { VideoBlacklistService } from './video-blacklist'
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@ -67,6 +68,7 @@ import { VideoAbuseService } from './video-abuse'
|
|||
RestService,
|
||||
SearchService,
|
||||
VideoAbuseService,
|
||||
VideoBlacklistService,
|
||||
UserService
|
||||
]
|
||||
})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from './video-blacklist.service'
|
|
@ -6,13 +6,13 @@ import 'rxjs/add/operator/map'
|
|||
|
||||
import { SortMeta } from 'primeng/components/common/sortmeta'
|
||||
|
||||
import { RestExtractor, RestPagination, RestService } from '../../../shared'
|
||||
import { Utils } from '../../../shared'
|
||||
import { BlacklistedVideo, ResultList } from '../../../../../../shared'
|
||||
import { RestExtractor, RestPagination, RestService } from '../rest'
|
||||
import { Utils } from '../utils'
|
||||
import { BlacklistedVideo, ResultList } from '../../../../../shared'
|
||||
|
||||
@Injectable()
|
||||
export class BlacklistService {
|
||||
private static BASE_BLACKLISTS_URL = API_URL + '/api/v1/blacklist/'
|
||||
export class VideoBlacklistService {
|
||||
private static BASE_VIDEOS_URL = API_URL + '/api/v1/videos/'
|
||||
|
||||
constructor (
|
||||
private authHttp: HttpClient,
|
||||
|
@ -20,22 +20,28 @@ export class BlacklistService {
|
|||
private restExtractor: RestExtractor
|
||||
) {}
|
||||
|
||||
getBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> {
|
||||
listBlacklist (pagination: RestPagination, sort: SortMeta): Observable<ResultList<BlacklistedVideo>> {
|
||||
let params = new HttpParams()
|
||||
params = this.restService.addRestGetParams(params, pagination, sort)
|
||||
|
||||
return this.authHttp.get<ResultList<BlacklistedVideo>>(BlacklistService.BASE_BLACKLISTS_URL, { params })
|
||||
return this.authHttp.get<ResultList<BlacklistedVideo>>(VideoBlacklistService.BASE_VIDEOS_URL + 'blacklist', { params })
|
||||
.map(res => this.restExtractor.convertResultListDateToHuman(res))
|
||||
.map(res => this.restExtractor.applyToResultListData(res, this.formatBlacklistedVideo.bind(this)))
|
||||
.catch(res => this.restExtractor.handleError(res))
|
||||
}
|
||||
|
||||
removeVideoFromBlacklist (entry: BlacklistedVideo) {
|
||||
return this.authHttp.delete(BlacklistService.BASE_BLACKLISTS_URL + entry.id)
|
||||
removeVideoFromBlacklist (videoId: number) {
|
||||
return this.authHttp.delete(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist')
|
||||
.map(this.restExtractor.extractDataBool)
|
||||
.catch(res => this.restExtractor.handleError(res))
|
||||
}
|
||||
|
||||
blacklistVideo (videoId: number) {
|
||||
return this.authHttp.post(VideoBlacklistService.BASE_VIDEOS_URL + videoId + '/blacklist', {})
|
||||
.map(this.restExtractor.extractDataBool)
|
||||
.catch(res => this.restExtractor.handleError(res))
|
||||
}
|
||||
|
||||
private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
|
||||
return Object.assign(blacklistedVideo, {
|
||||
createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
|
|
@ -14,7 +14,7 @@ import { VideoMagnetComponent } from './video-magnet.component'
|
|||
import { VideoShareComponent } from './video-share.component'
|
||||
import { VideoReportComponent } from './video-report.component'
|
||||
import { Video, VideoService } from '../shared'
|
||||
import { WebTorrentService } from './webtorrent.service'
|
||||
import { VideoBlacklistService } from '../../shared'
|
||||
import { UserVideoRateType, VideoRateType } from '../../../../../shared'
|
||||
|
||||
@Component({
|
||||
|
@ -45,6 +45,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
|||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private videoService: VideoService,
|
||||
private videoBlacklistService: VideoBlacklistService,
|
||||
private confirmService: ConfirmService,
|
||||
private metaService: MetaService,
|
||||
private authService: AuthService,
|
||||
|
@ -137,15 +138,15 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
|
|||
res => {
|
||||
if (res === false) return
|
||||
|
||||
this.videoService.blacklistVideo(this.video.id)
|
||||
.subscribe(
|
||||
status => {
|
||||
this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`)
|
||||
this.router.navigate(['/videos/list'])
|
||||
},
|
||||
this.videoBlacklistService.blacklistVideo(this.video.id)
|
||||
.subscribe(
|
||||
status => {
|
||||
this.notificationsService.success('Success', `Video ${this.video.name} had been blacklisted.`)
|
||||
this.router.navigate(['/videos/list'])
|
||||
},
|
||||
|
||||
error => this.notificationsService.error('Error', error.text)
|
||||
)
|
||||
error => this.notificationsService.error('Error', error.text)
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -122,12 +122,6 @@ export class VideoService {
|
|||
.catch(res => this.restExtractor.handleError(res))
|
||||
}
|
||||
|
||||
blacklistVideo (id: number) {
|
||||
return this.authHttp.post(VideoService.BASE_VIDEO_URL + id + '/blacklist', {})
|
||||
.map(this.restExtractor.extractDataBool)
|
||||
.catch(res => this.restExtractor.handleError(res))
|
||||
}
|
||||
|
||||
private videoPaginationToRestPagination (videoPagination: VideoPagination) {
|
||||
const start: number = (videoPagination.currentPage - 1) * videoPagination.itemsPerPage
|
||||
const count: number = videoPagination.itemsPerPage
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
import * as express from 'express'
|
||||
|
||||
import { database } from '../../initializers'
|
||||
import { getFormattedObjects } from '../../helpers'
|
||||
import { BlacklistedVideo } from '../../../shared'
|
||||
import { BlacklistedVideoInstance } from '../../models'
|
||||
|
||||
import {
|
||||
removeVideoFromBlacklist
|
||||
} from '../../lib'
|
||||
import {
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination,
|
||||
blacklistRemoveValidator
|
||||
} from '../../middlewares'
|
||||
|
||||
const blacklistRouter = express.Router()
|
||||
|
||||
blacklistRouter.get('/',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination,
|
||||
listBlacklist
|
||||
)
|
||||
|
||||
blacklistRouter.delete('/:id',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
blacklistRemoveValidator,
|
||||
removeVideoFromBlacklistController
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
blacklistRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
database.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
|
||||
.then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)))
|
||||
.catch(err => next(err))
|
||||
}
|
||||
|
||||
function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
const entry = res.locals.blacklistEntryToRemove as BlacklistedVideoInstance
|
||||
|
||||
removeVideoFromBlacklist(entry)
|
||||
.then(() => res.sendStatus(204))
|
||||
.catch(err => next(err))
|
||||
}
|
|
@ -9,7 +9,6 @@ import { remoteRouter } from './remote'
|
|||
import { requestSchedulerRouter } from './request-schedulers'
|
||||
import { usersRouter } from './users'
|
||||
import { videosRouter } from './videos'
|
||||
import { blacklistRouter } from './blacklist'
|
||||
|
||||
const apiRouter = express.Router()
|
||||
|
||||
|
@ -20,7 +19,6 @@ apiRouter.use('/remote', remoteRouter)
|
|||
apiRouter.use('/request-schedulers', requestSchedulerRouter)
|
||||
apiRouter.use('/users', usersRouter)
|
||||
apiRouter.use('/videos', videosRouter)
|
||||
apiRouter.use('/blacklist', blacklistRouter)
|
||||
apiRouter.use('/ping', pong)
|
||||
apiRouter.use('/*', badRequest)
|
||||
|
||||
|
|
|
@ -1,22 +1,46 @@
|
|||
import * as express from 'express'
|
||||
|
||||
import { database as db } from '../../../initializers/database'
|
||||
import { logger } from '../../../helpers'
|
||||
import { database as db } from '../../../initializers'
|
||||
import { logger, getFormattedObjects } from '../../../helpers'
|
||||
import {
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
videosBlacklistValidator
|
||||
videosBlacklistAddValidator,
|
||||
videosBlacklistRemoveValidator,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination
|
||||
} from '../../../middlewares'
|
||||
import { BlacklistedVideoInstance } from '../../../models'
|
||||
import { BlacklistedVideo } from '../../../../shared'
|
||||
|
||||
const blacklistRouter = express.Router()
|
||||
|
||||
blacklistRouter.post('/:id/blacklist',
|
||||
blacklistRouter.post('/:videoId/blacklist',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
videosBlacklistValidator,
|
||||
videosBlacklistAddValidator,
|
||||
addVideoToBlacklist
|
||||
)
|
||||
|
||||
blacklistRouter.get('/blacklist',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination,
|
||||
listBlacklist
|
||||
)
|
||||
|
||||
blacklistRouter.delete('/:videoId/blacklist',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
videosBlacklistRemoveValidator,
|
||||
removeVideoFromBlacklistController
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -39,3 +63,23 @@ function addVideoToBlacklist (req: express.Request, res: express.Response, next:
|
|||
return next(err)
|
||||
})
|
||||
}
|
||||
|
||||
function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
db.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
|
||||
.then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)))
|
||||
.catch(err => next(err))
|
||||
}
|
||||
|
||||
function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
const blacklistedVideo = res.locals.blacklistedVideo as BlacklistedVideoInstance
|
||||
|
||||
blacklistedVideo.destroy()
|
||||
.then(() => {
|
||||
logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
|
||||
res.sendStatus(204)
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, err)
|
||||
next(err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { values } from 'lodash'
|
||||
import * as validator from 'validator'
|
||||
import * as Promise from 'bluebird'
|
||||
import * as express from 'express'
|
||||
import 'express-validator'
|
||||
import 'multer'
|
||||
|
||||
|
@ -8,10 +10,13 @@ import {
|
|||
VIDEO_CATEGORIES,
|
||||
VIDEO_LICENCES,
|
||||
VIDEO_LANGUAGES,
|
||||
VIDEO_RATE_TYPES
|
||||
VIDEO_RATE_TYPES,
|
||||
database as db
|
||||
} from '../../initializers'
|
||||
import { isUserUsernameValid } from './users'
|
||||
import { isArray, exists } from './misc'
|
||||
import { VideoInstance } from '../../models'
|
||||
import { logger } from '../../helpers'
|
||||
import { VideoRateType } from '../../../shared'
|
||||
|
||||
const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
|
||||
|
@ -138,6 +143,30 @@ function isVideoFileInfoHashValid (value: string) {
|
|||
return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
|
||||
}
|
||||
|
||||
function checkVideoExists (id: string, res: express.Response, callback: () => void) {
|
||||
let promise: Promise<VideoInstance>
|
||||
if (validator.isInt(id)) {
|
||||
promise = db.Video.loadAndPopulateAuthorAndPodAndTags(+id)
|
||||
} else { // UUID
|
||||
promise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(id)
|
||||
}
|
||||
|
||||
promise.then(video => {
|
||||
if (!video) {
|
||||
return res.status(404)
|
||||
.json({ error: 'Video not found' })
|
||||
.end()
|
||||
}
|
||||
|
||||
res.locals.video = video
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -166,5 +195,6 @@ export {
|
|||
isVideoDislikesValid,
|
||||
isVideoEventCountValid,
|
||||
isVideoFileSizeValid,
|
||||
isVideoFileResolutionValid
|
||||
isVideoFileResolutionValid,
|
||||
checkVideoExists
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
import { logger } from '../helpers'
|
||||
import { BlacklistedVideoInstance } from '../models'
|
||||
|
||||
function removeVideoFromBlacklist (entry: BlacklistedVideoInstance) {
|
||||
return entry.destroy()
|
||||
.then(() => {
|
||||
logger.info('Video removed from the blacklist')
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Some error while removing video from the blacklist.', err)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
removeVideoFromBlacklist
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
|
@ -3,4 +3,3 @@ export * from './jobs'
|
|||
export * from './request'
|
||||
export * from './friends'
|
||||
export * from './oauth-model'
|
||||
export * from './blacklist'
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import { param } from 'express-validator/check'
|
||||
import * as express from 'express'
|
||||
|
||||
import { database as db } from '../../initializers/database'
|
||||
import { checkErrors } from './utils'
|
||||
import { logger } from '../../helpers'
|
||||
|
||||
const blacklistRemoveValidator = [
|
||||
param('id').isNumeric().not().isEmpty().withMessage('Should have a valid id'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, () => {
|
||||
db.BlacklistedVideo.loadById(req.params.id)
|
||||
.then(entry => {
|
||||
if (!entry) return res.status(404).send('Blacklisted video not found')
|
||||
|
||||
res.locals.blacklistEntryToRemove = entry
|
||||
|
||||
next()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in blacklistRemove request validator', { error: err })
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
blacklistRemoveValidator
|
||||
}
|
|
@ -4,4 +4,4 @@ export * from './pods'
|
|||
export * from './sort'
|
||||
export * from './users'
|
||||
export * from './videos'
|
||||
export * from './blacklist'
|
||||
export * from './video-blacklist'
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
import { param } from 'express-validator/check'
|
||||
import * as express from 'express'
|
||||
|
||||
import { database as db } from '../../initializers/database'
|
||||
import { checkErrors } from './utils'
|
||||
import { logger, isVideoIdOrUUIDValid, checkVideoExists } from '../../helpers'
|
||||
|
||||
const videosBlacklistRemoveValidator = [
|
||||
param('videoId').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking blacklistRemove parameters.', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, () => {
|
||||
checkVideoExists(req.params.videoId, res, () => {
|
||||
checkVideoIsBlacklisted(req, res, next)
|
||||
})
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
const videosBlacklistAddValidator = [
|
||||
param('videoId').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, () => {
|
||||
checkVideoExists(req.params.videoId, res, () => {
|
||||
checkVideoIsBlacklistable(req, res, next)
|
||||
})
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
videosBlacklistAddValidator,
|
||||
videosBlacklistRemoveValidator
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function checkVideoIsBlacklistable (req: express.Request, res: express.Response, callback: () => void) {
|
||||
if (res.locals.video.isOwned() === true) {
|
||||
return res.status(403)
|
||||
.json({ error: 'Cannot blacklist a local video' })
|
||||
.end()
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
function checkVideoIsBlacklisted (req: express.Request, res: express.Response, callback: () => void) {
|
||||
db.BlacklistedVideo.loadByVideoId(res.locals.video.id)
|
||||
.then(blacklistedVideo => {
|
||||
if (!blacklistedVideo) return res.status(404).send('Blacklisted video not found')
|
||||
|
||||
res.locals.blacklistedVideo = blacklistedVideo
|
||||
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in blacklistRemove request validator', { error: err })
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
import { body, param, query } from 'express-validator/check'
|
||||
import * as express from 'express'
|
||||
import * as Promise from 'bluebird'
|
||||
import * as validator from 'validator'
|
||||
|
||||
import { database as db } from '../../initializers/database'
|
||||
import { checkErrors } from './utils'
|
||||
|
@ -20,9 +18,9 @@ import {
|
|||
isVideoIdOrUUIDValid,
|
||||
isVideoAbuseReasonValid,
|
||||
isVideoRatingTypeValid,
|
||||
getDurationFromVideoFile
|
||||
getDurationFromVideoFile,
|
||||
checkVideoExists
|
||||
} from '../../helpers'
|
||||
import { VideoInstance } from '../../models'
|
||||
|
||||
const videosAddValidator = [
|
||||
body('videofile').custom((value, { req }) => isVideoFile(req.files)).withMessage('Should have a valid file'),
|
||||
|
@ -186,20 +184,6 @@ const videoRateValidator = [
|
|||
}
|
||||
]
|
||||
|
||||
const videosBlacklistValidator = [
|
||||
param('id').custom(isVideoIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
|
||||
|
||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||
logger.debug('Checking videosBlacklist parameters', { parameters: req.params })
|
||||
|
||||
checkErrors(req, res, () => {
|
||||
checkVideoExists(req.params.id, res, () => {
|
||||
checkVideoIsBlacklistable(req, res, next)
|
||||
})
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -211,37 +195,11 @@ export {
|
|||
|
||||
videoAbuseReportValidator,
|
||||
|
||||
videoRateValidator,
|
||||
|
||||
videosBlacklistValidator
|
||||
videoRateValidator
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function checkVideoExists (id: string, res: express.Response, callback: () => void) {
|
||||
let promise: Promise<VideoInstance>
|
||||
if (validator.isInt(id)) {
|
||||
promise = db.Video.loadAndPopulateAuthorAndPodAndTags(+id)
|
||||
} else { // UUID
|
||||
promise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(id)
|
||||
}
|
||||
|
||||
promise.then(video => {
|
||||
if (!video) {
|
||||
return res.status(404)
|
||||
.json({ error: 'Video not found' })
|
||||
.end()
|
||||
}
|
||||
|
||||
res.locals.video = video
|
||||
callback()
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Error in video request validator.', err)
|
||||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
function checkUserCanDeleteVideo (userId: number, res: express.Response, callback: () => void) {
|
||||
// Retrieve the user who did the request
|
||||
db.User.loadById(userId)
|
||||
|
@ -269,13 +227,3 @@ function checkUserCanDeleteVideo (userId: number, res: express.Response, callbac
|
|||
return res.sendStatus(500)
|
||||
})
|
||||
}
|
||||
|
||||
function checkVideoIsBlacklistable (req: express.Request, res: express.Response, callback: () => void) {
|
||||
if (res.locals.video.isOwned() === true) {
|
||||
return res.status(403)
|
||||
.json({ error: 'Cannot blacklist a local video' })
|
||||
.end()
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
|
|
@ -81,10 +81,10 @@ describe('Test video blacklist API validators', function () {
|
|||
})
|
||||
|
||||
describe('When removing a video in blacklist', function () {
|
||||
const basePath = '/api/v1/blacklist/'
|
||||
const basePath = '/api/v1/videos/'
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
const path = basePath + server.video.id
|
||||
const path = basePath + server.video.id + '/blacklist'
|
||||
|
||||
await request(server.url)
|
||||
.delete(path)
|
||||
|
@ -94,7 +94,7 @@ describe('Test video blacklist API validators', function () {
|
|||
})
|
||||
|
||||
it('Should fail with a non admin user', async function () {
|
||||
const path = basePath + server.video.id
|
||||
const path = basePath + server.video.id + '/blacklist'
|
||||
|
||||
await request(server.url)
|
||||
.delete(path)
|
||||
|
@ -104,7 +104,7 @@ describe('Test video blacklist API validators', function () {
|
|||
})
|
||||
|
||||
it('Should fail with an incorrect id', async function () {
|
||||
const path = basePath + 'foobar'
|
||||
const path = basePath + 'foobar/blacklist'
|
||||
|
||||
await request(server.url)
|
||||
.delete(path)
|
||||
|
@ -115,7 +115,7 @@ describe('Test video blacklist API validators', function () {
|
|||
|
||||
it('Should fail with a not blacklisted video', async function () {
|
||||
// The video was not added to the blacklist so it should fail
|
||||
const path = basePath + server.video.id
|
||||
const path = basePath + server.video.id + '/blacklist'
|
||||
|
||||
await request(server.url)
|
||||
.delete(path)
|
||||
|
@ -126,7 +126,7 @@ describe('Test video blacklist API validators', function () {
|
|||
})
|
||||
|
||||
describe('When listing videos in blacklist', function () {
|
||||
const basePath = '/api/v1/blacklist/'
|
||||
const basePath = '/api/v1/videos/blacklist/'
|
||||
|
||||
it('Should fail with a non authenticated user', async function () {
|
||||
const path = basePath
|
||||
|
|
|
@ -11,7 +11,7 @@ function addVideoToBlacklist (url: string, token: string, videoId: number, speci
|
|||
}
|
||||
|
||||
function removeVideoFromBlacklist (url: string, token: string, videoId: number, specialStatus = 204) {
|
||||
const path = '/api/v1/blacklist/' + videoId
|
||||
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
||||
|
||||
return request(url)
|
||||
.delete(path)
|
||||
|
@ -21,7 +21,7 @@ function removeVideoFromBlacklist (url: string, token: string, videoId: number,
|
|||
}
|
||||
|
||||
function getBlacklistedVideosList (url: string, token: string, specialStatus = 200) {
|
||||
const path = '/api/v1/blacklist/'
|
||||
const path = '/api/v1/videos/blacklist/'
|
||||
|
||||
return request(url)
|
||||
.get(path)
|
||||
|
@ -33,7 +33,7 @@ function getBlacklistedVideosList (url: string, token: string, specialStatus = 2
|
|||
}
|
||||
|
||||
function getSortedBlacklistedVideosList (url: string, token: string, sort: string, specialStatus = 200) {
|
||||
const path = '/api/v1/blacklist/'
|
||||
const path = '/api/v1/videos/blacklist/'
|
||||
|
||||
return request(url)
|
||||
.get(path)
|
||||
|
|
Loading…
Reference in New Issue