aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-04-17 10:47:22 +0200
committerRigel Kent <par@rigelk.eu>2020-05-01 16:41:02 +0200
commit86521a67b2edb06a139b095e489c205457eaba8f (patch)
tree3a0106ab146c3d8436ce502a43d38838800c4595 /server/models/video
parent9b4241e33bf46c4f0468565ce41ca7f810b2dbfa (diff)
downloadPeerTube-86521a67b2edb06a139b095e489c205457eaba8f.tar.gz
PeerTube-86521a67b2edb06a139b095e489c205457eaba8f.tar.zst
PeerTube-86521a67b2edb06a139b095e489c205457eaba8f.zip
Add video channel and video thumbnail, rework video appearance in row
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-abuse.ts54
-rw-r--r--server/models/video/video.ts2
2 files changed, 43 insertions, 13 deletions
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts
index ea9856213..ea943ffdf 100644
--- a/server/models/video/video-abuse.ts
+++ b/server/models/video/video-abuse.ts
@@ -1,4 +1,6 @@
1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 1import {
2 AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt, DefaultScope
3} from 'sequelize-typescript'
2import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' 4import { VideoAbuseObject } from '../../../shared/models/activitypub/objects'
3import { VideoAbuse } from '../../../shared/models/videos' 5import { VideoAbuse } from '../../../shared/models/videos'
4import { 6import {
@@ -14,7 +16,40 @@ import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/const
14import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models' 16import { MUserAccountId, MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
15import * as Bluebird from 'bluebird' 17import * as Bluebird from 'bluebird'
16import { literal, Op } from 'sequelize' 18import { literal, Op } from 'sequelize'
19import { ThumbnailModel } from './thumbnail'
20import { VideoChannelModel } from './video-channel'
21import { ActorModel } from '../activitypub/actor'
22import { VideoBlacklistModel } from './video-blacklist'
17 23
24@DefaultScope(() => ({
25 include: [
26 {
27 model: AccountModel,
28 required: true
29 },
30 {
31 model: VideoModel,
32 required: false,
33 include: [
34 {
35 model: ThumbnailModel
36 },
37 {
38 model: VideoChannelModel.unscoped(),
39 include: [
40 {
41 model: ActorModel
42 }
43 ]
44 },
45 {
46 attributes: [ 'id', 'reason', 'unfederated' ],
47 model: VideoBlacklistModel
48 }
49 ]
50 }
51 ]
52}))
18@Table({ 53@Table({
19 tableName: 'videoAbuse', 54 tableName: 'videoAbuse',
20 indexes: [ 55 indexes: [
@@ -114,16 +149,8 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
114 [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')') 149 [Op.notIn]: literal('(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')')
115 } 150 }
116 }, 151 },
117 include: [ 152 col: 'VideoAbuseModel.id',
118 { 153 distinct: true
119 model: AccountModel,
120 required: true
121 },
122 {
123 model: VideoModel,
124 required: false
125 }
126 ]
127 } 154 }
128 155
129 return VideoAbuseModel.findAndCountAll(query) 156 return VideoAbuseModel.findAndCountAll(query)
@@ -151,7 +178,10 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
151 uuid: video.uuid, 178 uuid: video.uuid,
152 name: video.name, 179 name: video.name,
153 nsfw: video.nsfw, 180 nsfw: video.nsfw,
154 deleted: !this.Video 181 deleted: !this.Video,
182 blacklisted: this.Video && this.Video.isBlacklisted(),
183 thumbnailPath: this.Video?.getMiniatureStaticPath(),
184 channel: this.Video?.VideoChannel.toFormattedSummaryJSON() || this.deletedVideo?.channel
155 }, 185 },
156 createdAt: this.createdAt 186 createdAt: this.createdAt
157 } 187 }
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 2636ebd8e..f32216e90 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -810,7 +810,7 @@ export class VideoModel extends Model<VideoModel> {
810 if (instance.VideoAbuses.length === 0) return undefined 810 if (instance.VideoAbuses.length === 0) return undefined
811 } 811 }
812 812
813 const details = instance.toFormattedJSON() 813 const details = instance.toFormattedDetailsJSON()
814 814
815 for (const abuse of instance.VideoAbuses) { 815 for (const abuse of instance.VideoAbuses) {
816 tasks.push((_ => { 816 tasks.push((_ => {