Video blacklist refractoring
authorChocobozzz <florian.bigard@gmail.com>
Tue, 10 Oct 2017 08:02:18 +0000 (10:02 +0200)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 10 Oct 2017 08:18:16 +0000 (10:18 +0200)
37 files changed:
client/src/app/+admin/admin-routing.module.ts
client/src/app/+admin/admin.component.ts
client/src/app/+admin/admin.module.ts
client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html [deleted file]
client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts [deleted file]
client/src/app/+admin/blacklist/blacklist-list/index.ts [deleted file]
client/src/app/+admin/blacklist/blacklist.component.ts [deleted file]
client/src/app/+admin/blacklist/blacklist.routes.ts [deleted file]
client/src/app/+admin/blacklist/index.ts [deleted file]
client/src/app/+admin/blacklist/shared/blacklist.service.ts [deleted file]
client/src/app/+admin/blacklist/shared/index.ts [deleted file]
client/src/app/+admin/video-blacklist/index.ts [new file with mode: 0644]
client/src/app/+admin/video-blacklist/video-blacklist-list/index.ts [new file with mode: 0644]
client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.html [new file with mode: 0644]
client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.ts [new file with mode: 0644]
client/src/app/+admin/video-blacklist/video-blacklist.component.ts [new file with mode: 0644]
client/src/app/+admin/video-blacklist/video-blacklist.routes.ts [new file with mode: 0644]
client/src/app/app.component.ts
client/src/app/core/menu/menu-admin.component.html
client/src/app/shared/index.ts
client/src/app/shared/shared.module.ts
client/src/app/shared/video-blacklist/index.ts [new file with mode: 0644]
client/src/app/shared/video-blacklist/video-blacklist.service.ts [new file with mode: 0644]
client/src/app/videos/+video-watch/video-watch.component.ts
client/src/app/videos/shared/video.service.ts
server/controllers/api/blacklist.ts [deleted file]
server/controllers/api/index.ts
server/controllers/api/videos/blacklist.ts
server/helpers/custom-validators/videos.ts
server/lib/blacklist.ts [deleted file]
server/lib/index.ts
server/middlewares/validators/blacklist.ts [deleted file]
server/middlewares/validators/index.ts
server/middlewares/validators/video-blacklist.ts [new file with mode: 0644]
server/middlewares/validators/videos.ts
server/tests/api/check-params/video-blacklist.ts
server/tests/utils/video-blacklist.ts

index 0cd3e54c27c98a1361c67660fafbba7e54171deb..c3e4895ac6c88bc12994ef098138c16cecaa2f11 100644 (file)
@@ -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
     ]
   }
 ]
index 93ec216bfd7efd12fcef1e36dc949e317d340a6f..ecd62ee61902aecae8590e015831cb723933ed16 100644 (file)
@@ -3,6 +3,5 @@ import { Component } from '@angular/core'
 @Component({
   template: '<router-outlet></router-outlet>'
 })
-
 export class AdminComponent {
 }
index c2dd607744205081a3a0200bf0e28b1942e40efa..f29c501b030854e9f0bb43a34ad636e90a618a8f 100644 (file)
@@ -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 { }
diff --git a/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.html
deleted file mode 100644 (file)
index 5d4636e..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<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>
diff --git a/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts b/client/src/app/+admin/blacklist/blacklist-list/blacklist-list.component.ts
deleted file mode 100644 (file)
index b308054..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-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)
-      )
-  }
-}
diff --git a/client/src/app/+admin/blacklist/blacklist-list/index.ts b/client/src/app/+admin/blacklist/blacklist-list/index.ts
deleted file mode 100644 (file)
index 45f60a2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './blacklist-list.component'
diff --git a/client/src/app/+admin/blacklist/blacklist.component.ts b/client/src/app/+admin/blacklist/blacklist.component.ts
deleted file mode 100644 (file)
index ce8fe42..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-import { Component } from '@angular/core'
-
-@Component({
-  template: '<router-outlet></router-outlet>'
-})
-
-export class BlacklistComponent {
-}
diff --git a/client/src/app/+admin/blacklist/blacklist.routes.ts b/client/src/app/+admin/blacklist/blacklist.routes.ts
deleted file mode 100644 (file)
index 780347c..0000000
+++ /dev/null
@@ -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'
-          }
-        }
-      }
-    ]
-  }
-]
diff --git a/client/src/app/+admin/blacklist/index.ts b/client/src/app/+admin/blacklist/index.ts
deleted file mode 100644 (file)
index 675dc12..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-export * from './shared'
-export * from './blacklist-list'
-export * from './blacklist.component'
-export * from './blacklist.routes'
diff --git a/client/src/app/+admin/blacklist/shared/blacklist.service.ts b/client/src/app/+admin/blacklist/shared/blacklist.service.ts
deleted file mode 100644 (file)
index ee2bf82..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-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)
-    })
-  }
-}
diff --git a/client/src/app/+admin/blacklist/shared/index.ts b/client/src/app/+admin/blacklist/shared/index.ts
deleted file mode 100644 (file)
index ad22e2d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-export * from './blacklist.service'
diff --git a/client/src/app/+admin/video-blacklist/index.ts b/client/src/app/+admin/video-blacklist/index.ts
new file mode 100644 (file)
index 0000000..a5451e2
--- /dev/null
@@ -0,0 +1,3 @@
+export * from './video-blacklist-list'
+export * from './video-blacklist.component'
+export * from './video-blacklist.routes'
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist-list/index.ts b/client/src/app/+admin/video-blacklist/video-blacklist-list/index.ts
new file mode 100644 (file)
index 0000000..4daf641
--- /dev/null
@@ -0,0 +1 @@
+export * from './video-blacklist-list.component'
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.html b/client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.html
new file mode 100644 (file)
index 0000000..05d1167
--- /dev/null
@@ -0,0 +1,26 @@
+<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>
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.ts b/client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.ts
new file mode 100644 (file)
index 0000000..56024b2
--- /dev/null
@@ -0,0 +1,64 @@
+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)
+      )
+  }
+}
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist.component.ts b/client/src/app/+admin/video-blacklist/video-blacklist.component.ts
new file mode 100644 (file)
index 0000000..24b8c98
--- /dev/null
@@ -0,0 +1,7 @@
+import { Component } from '@angular/core'
+
+@Component({
+  template: '<router-outlet></router-outlet>'
+})
+export class VideoBlacklistComponent {
+}
diff --git a/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts b/client/src/app/+admin/video-blacklist/video-blacklist.routes.ts
new file mode 100644 (file)
index 0000000..682b6f8
--- /dev/null
@@ -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'
+          }
+        }
+      }
+    ]
+  }
+]
index 68719f73d284d236ac8ddb244fdca7a9213fbaa9..7d890e72aa37eaf40b332237c2d28365bf542786 100644 (file)
@@ -11,7 +11,7 @@ import { UserService } from './shared'
 })
 export class AppComponent implements OnInit {
   notificationOptions = {
-    timeOut: 3000,
+    timeOut: 5000,
     lastOnBottom: true,
     clickToClose: true,
     maxLength: 0,
index f512a4e6778309fa2336398587fd59a537f4d6c1..edacdee6d1684d5a6b231029021f2147e8849c8b 100644 (file)
@@ -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>
index 212645c51988360a68335058488a482dd9b123c6..79bf5ef43298cb861f297657c264540551bcaffd 100644 (file)
@@ -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'
index 56da62fc4a3f7bec80863adf3ff5f78c16e0803a..47f651590c9a6c11fe90fba309ef0bb894ee7f39 100644 (file)
@@ -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
   ]
 })
diff --git a/client/src/app/shared/video-blacklist/index.ts b/client/src/app/shared/video-blacklist/index.ts
new file mode 100644 (file)
index 0000000..bfb0264
--- /dev/null
@@ -0,0 +1 @@
+export * from './video-blacklist.service'
diff --git a/client/src/app/shared/video-blacklist/video-blacklist.service.ts b/client/src/app/shared/video-blacklist/video-blacklist.service.ts
new file mode 100644 (file)
index 0000000..17373d5
--- /dev/null
@@ -0,0 +1,50 @@
+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)
+    })
+  }
+}
index 874dd599775344e9e2e2e1c3a912941cfe89467a..bd98e877ca0e468434e514699b7d204425bbea6a 100644 (file)
@@ -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)
+                                  )
       }
     )
   }
index 037c20416010c828eddda7a9b82de2a59855ebe9..fe7f9108d3b6281c95dc753db15c863129348359 100644 (file)
@@ -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
diff --git a/server/controllers/api/blacklist.ts b/server/controllers/api/blacklist.ts
deleted file mode 100644 (file)
index 9b2d801..0000000
+++ /dev/null
@@ -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))
-}
index fdc8879151bc8023f03038ec39a93180b34a9a13..a9205b33c6581a9dabfb089bde2a270b9dd23b2a 100644 (file)
@@ -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)
 
index d8f2068ec547c4469f31561f0e3bfd20ebd1a8a0..66311598ecf4996437aebf065bef9e2c5238fd35 100644 (file)
@@ -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)
+    })
+}
index a31aca0197d33c7ad21fbec6541ca67ad3253495..05d1dc60744eac1457d496f2afa3383f7584e278 100644 (file)
@@ -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
 }
diff --git a/server/lib/blacklist.ts b/server/lib/blacklist.ts
deleted file mode 100644 (file)
index dcf8aa0..0000000
+++ /dev/null
@@ -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
-}
-
-// ---------------------------------------------------------------------------
index df781f29f748eb7fd5aaf81507c4156c89105cb2..8628da4dded5c4e18d1fd05f189b8dbb6cfc064e 100644 (file)
@@ -3,4 +3,3 @@ export * from './jobs'
 export * from './request'
 export * from './friends'
 export * from './oauth-model'
-export * from './blacklist'
diff --git a/server/middlewares/validators/blacklist.ts b/server/middlewares/validators/blacklist.ts
deleted file mode 100644 (file)
index fe8fa40..0000000
+++ /dev/null
@@ -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
-}
index a6198e22c801c06e427336c5dd187fa1f9a1e0ce..418fa5f1daf2437662e8a0ec47f5ee9f8a3c5693 100644 (file)
@@ -4,4 +4,4 @@ export * from './pods'
 export * from './sort'
 export * from './users'
 export * from './videos'
-export * from './blacklist'
+export * from './video-blacklist'
diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts
new file mode 100644 (file)
index 0000000..30c6d4b
--- /dev/null
@@ -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)
+    })
+}
index 5f213f974d7cb38ca1d50959991983e237b3d6d3..deed075245209f6e2258c0681bddf8a2879e8651 100644 (file)
@@ -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()
-}
index 80e6f8011dcdff26a5d3109a5dca57979d0e696b..eb16b3af08fb90e2e640200cbac60b637a5675f9 100644 (file)
@@ -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
index 5729d13d86c6e6cca6b31e9794dcdfdeccfa11bf..3a499f46a75302c10da442be13caf39b10751181 100644 (file)
@@ -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)