aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-abuse.ts18
-rw-r--r--server/models/video/video-blacklist.ts13
2 files changed, 17 insertions, 14 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index d68608ca6..e8c3bd823 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -9,7 +9,7 @@ import {
9 isVideoAbuseStateValid 9 isVideoAbuseStateValid
10} from '../../helpers/custom-validators/video-abuses' 10} from '../../helpers/custom-validators/video-abuses'
11import { AccountModel } from '../account/account' 11import { AccountModel } from '../account/account'
12import { buildBlockedAccountSQL, getSort, throwIfNotValid } from '../utils' 12import { buildBlockedAccountSQL, getSort, throwIfNotValid, searchAttribute } from '../utils'
13import { VideoModel } from './video' 13import { VideoModel } from './video'
14import { VideoAbuseState, VideoDetails } from '../../../shared' 14import { VideoAbuseState, VideoDetails } from '../../../shared'
15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' 15import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
@@ -17,8 +17,8 @@ import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo }
17import * as Bluebird from 'bluebird' 17import * as Bluebird from 'bluebird'
18import { literal, Op } from 'sequelize' 18import { literal, Op } from 'sequelize'
19import { ThumbnailModel } from './thumbnail' 19import { ThumbnailModel } from './thumbnail'
20import { VideoChannelModel } from './video-channel'
21import { VideoBlacklistModel } from './video-blacklist' 20import { VideoBlacklistModel } from './video-blacklist'
21import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
22 22
23export enum ScopeNames { 23export enum ScopeNames {
24 FOR_API = 'FOR_API' 24 FOR_API = 'FOR_API'
@@ -33,12 +33,6 @@ export enum ScopeNames {
33 serverAccountId: number 33 serverAccountId: number
34 userAccountId: any 34 userAccountId: any
35 }) => { 35 }) => {
36 const search = (sourceField, targetField) => sourceField ? ({
37 [targetField]: {
38 [Op.iLike]: `%${sourceField}%`
39 }
40 }) : {}
41
42 let where = { 36 let where = {
43 reporterAccountId: { 37 reporterAccountId: {
44 [Op.notIn]: literal('(' + buildBlockedAccountSQL(options.serverAccountId, options.userAccountId) + ')') 38 [Op.notIn]: literal('(' + buildBlockedAccountSQL(options.serverAccountId, options.userAccountId) + ')')
@@ -148,19 +142,19 @@ export enum ScopeNames {
148 { 142 {
149 model: AccountModel, 143 model: AccountModel,
150 required: true, 144 required: true,
151 where: { ...search(options.searchReporter, 'name') } 145 where: { ...searchAttribute(options.searchReporter, 'name') }
152 }, 146 },
153 { 147 {
154 model: VideoModel, 148 model: VideoModel,
155 required: false, 149 required: false,
156 where: { ...search(options.searchVideo, 'name') }, 150 where: { ...searchAttribute(options.searchVideo, 'name') },
157 include: [ 151 include: [
158 { 152 {
159 model: ThumbnailModel 153 model: ThumbnailModel
160 }, 154 },
161 { 155 {
162 model: VideoChannelModel.scope([ 'WITH_ACTOR', 'WITH_ACCOUNT' ]), 156 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),
163 where: { ...search(options.searchVideoChannel, 'name') } 157 where: { ...searchAttribute(options.searchVideoChannel, 'name') }
164 }, 158 },
165 { 159 {
166 attributes: [ 'id', 'reason', 'unfederated' ], 160 attributes: [ 'id', 'reason', 'unfederated' ],
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 694983cb3..680eba471 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -1,5 +1,5 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { getBlacklistSort, SortType, throwIfNotValid } from '../utils' 2import { getBlacklistSort, SortType, throwIfNotValid, searchAttribute } from '../utils'
3import { VideoModel } from './video' 3import { VideoModel } from './video'
4import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel' 4import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from './video-channel'
5import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' 5import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist'
@@ -54,7 +54,15 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
54 }) 54 })
55 Video: VideoModel 55 Video: VideoModel
56 56
57 static listForApi (start: number, count: number, sort: SortType, type?: VideoBlacklistType) { 57 static listForApi (parameters: {
58 start: number
59 count: number
60 sort: SortType
61 search?: string
62 type?: VideoBlacklistType
63 }) {
64 const { start, count, sort, search, type } = parameters
65
58 function buildBaseQuery (): FindOptions { 66 function buildBaseQuery (): FindOptions {
59 return { 67 return {
60 offset: start, 68 offset: start,
@@ -70,6 +78,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
70 { 78 {
71 model: VideoModel, 79 model: VideoModel,
72 required: true, 80 required: true,
81 where: { ...searchAttribute(search, 'name') },
73 include: [ 82 include: [
74 { 83 {
75 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }), 84 model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, { withAccount: true } as SummaryOptions ] }),