aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/abuse.ts1
-rw-r--r--server/models/video/video-abuse.ts121
2 files changed, 96 insertions, 26 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts
index 4ae899b7e..f37d90896 100644
--- a/server/controllers/api/videos/abuse.ts
+++ b/server/controllers/api/videos/abuse.ts
@@ -69,6 +69,7 @@ async function listVideoAbuses (req: express.Request, res: express.Response) {
69 start: req.query.start, 69 start: req.query.start,
70 count: req.query.count, 70 count: req.query.count,
71 sort: req.query.sort, 71 sort: req.query.sort,
72 search: req.query.search,
72 serverAccountId: serverActor.Account.id, 73 serverAccountId: serverActor.Account.id,
73 user 74 user
74 }) 75 })
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index ea943ffdf..5ead02eca 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,5 +1,5 @@
1import { 1import {
2 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt, DefaultScope 2 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt, Scopes
3} from 'sequelize-typescript' 3} from 'sequelize-typescript'
4import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' 4import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
5import { VideoAbuse } from '../../../shared/models/videos' 5import { VideoAbuse } from '../../../shared/models/videos'
@@ -21,34 +21,99 @@ import { VideoChannelModel } from './video-channel'
21import { ActorModel } from '../activitypub/actor' 21import { ActorModel } from '../activitypub/actor'
22import { VideoBlacklistModel } from './video-blacklist' 22import { VideoBlacklistModel } from './video-blacklist'
23 23
24@DefaultScope(() => ({ 24export enum ScopeNames {
25 include: [ 25 FOR_API = 'FOR_API'
26 { 26}
27 model: AccountModel, 27
28 required: true 28@Scopes(() => ({
29 }, 29 [ScopeNames.FOR_API]: (options: {
30 { 30 search?: string
31 model: VideoModel, 31 searchReporter?: string
32 required: false, 32 searchVideo?: string
33 searchVideoChannel?: string
34 serverAccountId: number
35 userAccountId: any
36 }) => {
37 const search = (sourceField, targetField) => sourceField ? ({
38 [targetField]: {
39 [Op.iLike]: `%${sourceField}%`
40 }
41 }) : {}
42
43 let where = {
44 reporterAccountId: {
45 [Op.notIn]: literal('(' + buildBlockedAccountSQL(options.serverAccountId, options.userAccountId) + ')')
46 }
47 }
48
49 if (options.search) {
50 where = Object.assign(where, {
51 [Op.or]: [
52 {
53 [Op.and]: [
54 { videoId: { [Op.not]: null } },
55 { '$Video.name$': { [Op.iLike]: `%${options.search}%` } }
56 ]
57 },
58 {
59 [Op.and]: [
60 { videoId: { [Op.not]: null } },
61 { '$Video.VideoChannel.name$': { [Op.iLike]: `%${options.search}%` } }
62 ]
63 },
64 {
65 [Op.and]: [
66 { deletedVideo: { [Op.not]: null } },
67 { deletedVideo: { name: { [Op.iLike]: `%${options.search}%` } } }
68 ]
69 },
70 {
71 [Op.and]: [
72 { deletedVideo: { [Op.not]: null } },
73 { deletedVideo: { channel: { displayName: { [Op.iLike]: `%${options.search}%` } } } }
74 ]
75 },
76 { '$Account.name$': { [Op.iLike]: `%${options.search}%` } }
77 ]
78 })
79 }
80
81 console.log(where)
82
83 return {
33 include: [ 84 include: [
34 { 85 {
35 model: ThumbnailModel 86 model: AccountModel,
87 required: true,
88 where: { ...search(options.searchReporter, 'name') }
36 }, 89 },
37 { 90 {
38 model: VideoChannelModel.unscoped(), 91 model: VideoModel,
92 required: false,
93 where: { ...search(options.searchVideo, 'name') },
39 include: [ 94 include: [
40 { 95 {
41 model: ActorModel 96 model: ThumbnailModel
97 },
98 {
99 model: VideoChannelModel.unscoped(),
100 where: { ...search(options.searchVideoChannel, 'name') },
101 include: [
102 {
103 model: ActorModel
104 }
105 ]
106 },
107 {
108 attributes: [ 'id', 'reason', 'unfederated' ],
109 model: VideoBlacklistModel
42 } 110 }
43 ] 111 ]
44 },
45 {
46 attributes: [ 'id', 'reason', 'unfederated' ],
47 model: VideoBlacklistModel
48 } 112 }
49 ] 113 ],
114 where
50 } 115 }
51 ] 116 }
52})) 117}))
53@Table({ 118@Table({
54 tableName: 'videoAbuse', 119 tableName: 'videoAbuse',
@@ -134,26 +199,30 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
134 start: number 199 start: number
135 count: number 200 count: number
136 sort: string 201 sort: string
202 search?: string
137 serverAccountId: number 203 serverAccountId: number
138 user?: MUserAccountId 204 user?: MUserAccountId
139 }) { 205 }) {
140 const { start, count, sort, user, serverAccountId } = parameters 206 const { start, count, sort, search, user, serverAccountId } = parameters
141 const userAccountId = user ? user.Account.id : undefined 207 const userAccountId = user ? user.Account.id : undefined
142 208
143 const query = { 209 const query = {
144 offset: start, 210 offset: start,
145 limit: count, 211 limit: count,
146 order: getSort(sort), 212 order: getSort(sort),
147 where: {
148 reporterAccountId: {
149 [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')')
150 }
151 },
152 col: 'VideoAbuseModel.id', 213 col: 'VideoAbuseModel.id',
153 distinct: true 214 distinct: true
154 } 215 }
155 216
156 return VideoAbuseModel.findAndCountAll(query) 217 const filters = {
218 search,
219 serverAccountId,
220 userAccountId
221 }
222
223 return VideoAbuseModel
224 .scope({ method: [ ScopeNames.FOR_API, filters ] })
225 .findAndCountAll(query)
157 .then(({ rows, count }) => { 226 .then(({ rows, count }) => {
158 return { total: count, data: rows } 227 return { total: count, data: rows }
159 }) 228 })