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 = [
{
...RequestSchedulersRoutes,
...UsersRoutes,
...VideoAbusesRoutes,
- ...BlacklistRoutes
+ ...VideoBlacklistRoutes
]
}
]
@Component({
template: '<router-outlet></router-outlet>'
})
-
export class AdminComponent {
}
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'
UserUpdateComponent,
UserListComponent,
- BlacklistComponent,
- BlacklistListComponent,
+ VideoBlacklistComponent,
+ VideoBlacklistListComponent,
VideoAbusesComponent,
VideoAbuseListComponent
FriendService,
RequestSchedulersService,
UserService,
- AdminGuard,
- BlacklistService
+ AdminGuard
]
})
export class AdminModule { }
+++ /dev/null
-<div class="row">
- <div class="content-padding">
- <h3>Blacklisted videos</h3>
-
- <p-dataTable
- [value]="blacklist" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
- sortField="id" (onLazyLoad)="loadLazy($event)"
- >
- <p-column field="id" header="ID" [sortable]="true"></p-column>
- <p-column field="name" header="Name" [sortable]="true"></p-column>
- <p-column field="description" header="Description"></p-column>
- <p-column field="duration" header="Duration" [sortable]="true"></p-column>
- <p-column field="views" header="Views" [sortable]="true"></p-column>
- <p-column field="likes" header="Likes" [sortable]="true"></p-column>
- <p-column field="dislikes" header="Dislikes" [sortable]="true"></p-column>
- <p-column field="nsfw" header="NSFW"></p-column>
- <p-column field="uuid" header="UUID" [sortable]="true"></p-column>
- <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>
- </p-column>
- </p-dataTable>
- </div>
-</div>
+++ /dev/null
-import { Component, OnInit } from '@angular/core'
-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 { BlacklistedVideo } from '../../../../../../shared'
-
-@Component({
- selector: 'my-blacklist-list',
- templateUrl: './blacklist-list.component.html',
- styleUrls: []
-})
-export class BlacklistListComponent extends RestTable implements OnInit {
- blacklist: BlacklistedVideo[] = []
- totalRecords = 0
- rowsPerPage = 10
- sort: SortMeta = { field: 'id', order: 1 }
- pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
-
- constructor (
- private notificationsService: NotificationsService,
- private confirmService: ConfirmService,
- private blacklistService: BlacklistService
- ) {
- super()
- }
-
- ngOnInit () {
- this.loadData()
- }
-
- removeVideoFromBlacklist (entry: BlacklistedVideo) {
- const confirmMessage = 'Do you really want to remove this video from the blacklist ? It will be available again in the video list.'
-
- this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
- res => {
- if (res === false) return
-
- this.blacklistService.removeVideoFromBlacklist(entry).subscribe(
- status => {
- this.notificationsService.success('Success', `Video ${entry.name} removed from the blacklist.`)
- this.loadData()
- },
-
- err => this.notificationsService.error('Error', err.message)
- )
- }
- )
- }
-
- protected loadData () {
- this.blacklistService.getBlacklist(this.pagination, this.sort)
- .subscribe(
- resultList => {
- this.blacklist = resultList.data
- this.totalRecords = resultList.total
- },
-
- err => this.notificationsService.error('Error', err.message)
- )
- }
-}
+++ /dev/null
-export * from './blacklist-list.component'
+++ /dev/null
-import { Component } from '@angular/core'
-
-@Component({
- template: '<router-outlet></router-outlet>'
-})
-
-export class BlacklistComponent {
-}
+++ /dev/null
-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'
- }
- }
- }
- ]
- }
-]
+++ /dev/null
-export * from './shared'
-export * from './blacklist-list'
-export * from './blacklist.component'
-export * from './blacklist.routes'
+++ /dev/null
-import { Injectable } from '@angular/core'
-import { HttpClient, HttpParams } from '@angular/common/http'
-import { Observable } from 'rxjs/Observable'
-import 'rxjs/add/operator/catch'
-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'
-
-@Injectable()
-export class BlacklistService {
- private static BASE_BLACKLISTS_URL = API_URL + '/api/v1/blacklist/'
-
- constructor (
- private authHttp: HttpClient,
- private restService: RestService,
- private restExtractor: RestExtractor
- ) {}
-
- getBlacklist (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 })
- .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)
- .map(this.restExtractor.extractDataBool)
- .catch(res => this.restExtractor.handleError(res))
- }
-
- private formatBlacklistedVideo (blacklistedVideo: BlacklistedVideo) {
- return Object.assign(blacklistedVideo, {
- createdAt: Utils.dateToHuman(blacklistedVideo.createdAt)
- })
- }
-}
+++ /dev/null
-export * from './blacklist.service'
--- /dev/null
+export * from './video-blacklist-list'
+export * from './video-blacklist.component'
+export * from './video-blacklist.routes'
--- /dev/null
+export * from './video-blacklist-list.component'
--- /dev/null
+<div class="row">
+ <div class="content-padding">
+ <h3>Blacklisted videos</h3>
+
+ <p-dataTable
+ [value]="blacklist" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
+ sortField="id" (onLazyLoad)="loadLazy($event)"
+ >
+ <p-column field="id" header="ID" [sortable]="true"></p-column>
+ <p-column field="name" header="Name" [sortable]="true"></p-column>
+ <p-column field="description" header="Description"></p-column>
+ <p-column field="duration" header="Duration" [sortable]="true"></p-column>
+ <p-column field="views" header="Views" [sortable]="true"></p-column>
+ <p-column field="likes" header="Likes" [sortable]="true"></p-column>
+ <p-column field="dislikes" header="Dislikes" [sortable]="true"></p-column>
+ <p-column field="nsfw" header="NSFW"></p-column>
+ <p-column field="uuid" header="UUID" [sortable]="true"></p-column>
+ <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 from blacklist"></span>
+ </ng-template>
+ </p-column>
+ </p-dataTable>
+ </div>
+</div>
--- /dev/null
+import { Component, OnInit } from '@angular/core'
+import { SortMeta } from 'primeng/components/common/sortmeta'
+
+import { NotificationsService } from 'angular2-notifications'
+
+import { ConfirmService } from '../../../core'
+import { VideoBlacklistService, RestTable, RestPagination } from '../../../shared'
+import { BlacklistedVideo } from '../../../../../../shared'
+
+@Component({
+ selector: 'my-video-blacklist-list',
+ templateUrl: './video-blacklist-list.component.html',
+ styleUrls: []
+})
+export class VideoBlacklistListComponent extends RestTable implements OnInit {
+ blacklist: BlacklistedVideo[] = []
+ totalRecords = 0
+ rowsPerPage = 10
+ sort: SortMeta = { field: 'id', order: 1 }
+ pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
+
+ constructor (
+ private notificationsService: NotificationsService,
+ private confirmService: ConfirmService,
+ private videoBlacklistService: VideoBlacklistService
+ ) {
+ super()
+ }
+
+ ngOnInit () {
+ this.loadData()
+ }
+
+ removeVideoFromBlacklist (entry: BlacklistedVideo) {
+ const confirmMessage = 'Do you really want to remove this video from the blacklist ? It will be available again in the video list.'
+
+ this.confirmService.confirm(confirmMessage, 'Remove').subscribe(
+ res => {
+ if (res === false) return
+
+ this.videoBlacklistService.removeVideoFromBlacklist(entry.videoId).subscribe(
+ status => {
+ this.notificationsService.success('Success', `Video ${entry.name} removed from the blacklist.`)
+ this.loadData()
+ },
+
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+ )
+ }
+
+ protected loadData () {
+ this.videoBlacklistService.listBlacklist(this.pagination, this.sort)
+ .subscribe(
+ resultList => {
+ this.blacklist = resultList.data
+ this.totalRecords = resultList.total
+ },
+
+ err => this.notificationsService.error('Error', err.message)
+ )
+ }
+}
--- /dev/null
+import { Component } from '@angular/core'
+
+@Component({
+ template: '<router-outlet></router-outlet>'
+})
+export class VideoBlacklistComponent {
+}
--- /dev/null
+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'
+ }
+ }
+ }
+ ]
+ }
+]
})
export class AppComponent implements OnInit {
notificationOptions = {
- timeOut: 3000,
+ timeOut: 5000,
lastOnBottom: true,
clickToClose: true,
maxLength: 0,
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>
export * from './search'
export * from './users'
export * from './video-abuse'
+export * from './video-blacklist'
export * from './shared.module'
export * from './utils'
import { SearchComponent, SearchService } from './search'
import { UserService } from './users'
import { VideoAbuseService } from './video-abuse'
+import { VideoBlacklistService } from './video-blacklist'
@NgModule({
imports: [
RestService,
SearchService,
VideoAbuseService,
+ VideoBlacklistService,
UserService
]
})
--- /dev/null
+export * from './video-blacklist.service'
--- /dev/null
+import { Injectable } from '@angular/core'
+import { HttpClient, HttpParams } from '@angular/common/http'
+import { Observable } from 'rxjs/Observable'
+import 'rxjs/add/operator/catch'
+import 'rxjs/add/operator/map'
+
+import { SortMeta } from 'primeng/components/common/sortmeta'
+
+import { RestExtractor, RestPagination, RestService } from '../rest'
+import { Utils } from '../utils'
+import { BlacklistedVideo, ResultList } from '../../../../../shared'
+
+@Injectable()
+export class VideoBlacklistService {
+ private static BASE_VIDEOS_URL = API_URL + '/api/v1/videos/'
+
+ constructor (
+ private authHttp: HttpClient,
+ private restService: RestService,
+ private restExtractor: RestExtractor
+ ) {}
+
+ 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>>(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 (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)
+ })
+ }
+}
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({
private route: ActivatedRoute,
private router: Router,
private videoService: VideoService,
+ private videoBlacklistService: VideoBlacklistService,
private confirmService: ConfirmService,
private metaService: MetaService,
private authService: AuthService,
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)
+ )
}
)
}
.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
+++ /dev/null
-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))
-}
import { requestSchedulerRouter } from './request-schedulers'
import { usersRouter } from './users'
import { videosRouter } from './videos'
-import { blacklistRouter } from './blacklist'
const apiRouter = express.Router()
apiRouter.use('/request-schedulers', requestSchedulerRouter)
apiRouter.use('/users', usersRouter)
apiRouter.use('/videos', videosRouter)
-apiRouter.use('/blacklist', blacklistRouter)
apiRouter.use('/ping', pong)
apiRouter.use('/*', badRequest)
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 {
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)
+ })
+}
import { values } from 'lodash'
import * as validator from 'validator'
+import * as Promise from 'bluebird'
+import * as express from 'express'
import 'express-validator'
import 'multer'
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
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 {
isVideoDislikesValid,
isVideoEventCountValid,
isVideoFileSizeValid,
- isVideoFileResolutionValid
+ isVideoFileResolutionValid,
+ checkVideoExists
}
+++ /dev/null
-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
-}
-
-// ---------------------------------------------------------------------------
export * from './request'
export * from './friends'
export * from './oauth-model'
-export * from './blacklist'
+++ /dev/null
-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
-}
export * from './sort'
export * from './users'
export * from './videos'
-export * from './blacklist'
+export * from './video-blacklist'
--- /dev/null
+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)
+ })
+}
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'
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'),
}
]
-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 {
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)
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()
-}
})
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)
})
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)
})
it('Should fail with an incorrect id', async function () {
- const path = basePath + 'foobar'
+ const path = basePath + 'foobar/blacklist'
await request(server.url)
.delete(path)
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)
})
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
}
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)
}
function getBlacklistedVideosList (url: string, token: string, specialStatus = 200) {
- const path = '/api/v1/blacklist/'
+ const path = '/api/v1/videos/blacklist/'
return request(url)
.get(path)
}
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)