diff options
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r-- | server/models/video/video-share.ts | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index fda2d7cea..3bab3c027 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
@@ -8,6 +7,7 @@ import { ActorModel } from '../activitypub/actor' | |||
8 | import { throwIfNotValid } from '../utils' | 7 | import { throwIfNotValid } from '../utils' |
9 | import { VideoModel } from './video' | 8 | import { VideoModel } from './video' |
10 | import { VideoChannelModel } from './video-channel' | 9 | import { VideoChannelModel } from './video-channel' |
10 | import { Op, Transaction } from 'sequelize' | ||
11 | 11 | ||
12 | enum ScopeNames { | 12 | enum ScopeNames { |
13 | FULL = 'FULL', | 13 | FULL = 'FULL', |
@@ -88,7 +88,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
88 | }) | 88 | }) |
89 | Video: VideoModel | 89 | Video: VideoModel |
90 | 90 | ||
91 | static load (actorId: number, videoId: number, t?: Sequelize.Transaction) { | 91 | static load (actorId: number, videoId: number, t?: Transaction) { |
92 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ | 92 | return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ |
93 | where: { | 93 | where: { |
94 | actorId, | 94 | actorId, |
@@ -98,7 +98,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
98 | }) | 98 | }) |
99 | } | 99 | } |
100 | 100 | ||
101 | static loadByUrl (url: string, t: Sequelize.Transaction) { | 101 | static loadByUrl (url: string, t: Transaction) { |
102 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ | 102 | return VideoShareModel.scope(ScopeNames.FULL).findOne({ |
103 | where: { | 103 | where: { |
104 | url | 104 | url |
@@ -107,7 +107,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
107 | }) | 107 | }) |
108 | } | 108 | } |
109 | 109 | ||
110 | static loadActorsByShare (videoId: number, t: Sequelize.Transaction) { | 110 | static loadActorsByShare (videoId: number, t: Transaction) { |
111 | const query = { | 111 | const query = { |
112 | where: { | 112 | where: { |
113 | videoId | 113 | videoId |
@@ -125,7 +125,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
125 | .then(res => res.map(r => r.Actor)) | 125 | .then(res => res.map(r => r.Actor)) |
126 | } | 126 | } |
127 | 127 | ||
128 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { | 128 | static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<ActorModel[]> { |
129 | const query = { | 129 | const query = { |
130 | attributes: [], | 130 | attributes: [], |
131 | include: [ | 131 | include: [ |
@@ -163,7 +163,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
163 | .then(res => res.map(r => r.Actor)) | 163 | .then(res => res.map(r => r.Actor)) |
164 | } | 164 | } |
165 | 165 | ||
166 | static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { | 166 | static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<ActorModel[]> { |
167 | const query = { | 167 | const query = { |
168 | attributes: [], | 168 | attributes: [], |
169 | include: [ | 169 | include: [ |
@@ -188,7 +188,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
188 | .then(res => res.map(r => r.Actor)) | 188 | .then(res => res.map(r => r.Actor)) |
189 | } | 189 | } |
190 | 190 | ||
191 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) { | 191 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction) { |
192 | const query = { | 192 | const query = { |
193 | offset: start, | 193 | offset: start, |
194 | limit: count, | 194 | limit: count, |
@@ -205,10 +205,21 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
205 | const query = { | 205 | const query = { |
206 | where: { | 206 | where: { |
207 | updatedAt: { | 207 | updatedAt: { |
208 | [Sequelize.Op.lt]: beforeUpdatedAt | 208 | [Op.lt]: beforeUpdatedAt |
209 | }, | 209 | }, |
210 | videoId | 210 | videoId |
211 | } | 211 | }, |
212 | include: [ | ||
213 | { | ||
214 | model: ActorModel.unscoped(), | ||
215 | required: true, | ||
216 | where: { | ||
217 | serverId: { | ||
218 | [ Op.ne ]: null | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | ] | ||
212 | } | 223 | } |
213 | 224 | ||
214 | return VideoShareModel.destroy(query) | 225 | return VideoShareModel.destroy(query) |