diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-channel.ts | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 0273fab13..9f80e0b8d 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -29,6 +29,7 @@ import { getSort, throwIfNotValid } from '../utils' | |||
29 | import { VideoModel } from './video' | 29 | import { VideoModel } from './video' |
30 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 30 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
31 | import { AvatarModel } from '../avatar/avatar' | 31 | import { AvatarModel } from '../avatar/avatar' |
32 | import { ServerModel } from '../server/server' | ||
32 | 33 | ||
33 | enum ScopeNames { | 34 | enum ScopeNames { |
34 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 35 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
@@ -206,7 +207,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
206 | } | 207 | } |
207 | 208 | ||
208 | static loadByIdAndAccount (id: number, accountId: number) { | 209 | static loadByIdAndAccount (id: number, accountId: number) { |
209 | const options = { | 210 | const query = { |
210 | where: { | 211 | where: { |
211 | id, | 212 | id, |
212 | accountId | 213 | accountId |
@@ -215,7 +216,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
215 | 216 | ||
216 | return VideoChannelModel | 217 | return VideoChannelModel |
217 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) | 218 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) |
218 | .findOne(options) | 219 | .findOne(query) |
219 | } | 220 | } |
220 | 221 | ||
221 | static loadAndPopulateAccount (id: number) { | 222 | static loadAndPopulateAccount (id: number) { |
@@ -225,7 +226,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
225 | } | 226 | } |
226 | 227 | ||
227 | static loadByUUIDAndPopulateAccount (uuid: string) { | 228 | static loadByUUIDAndPopulateAccount (uuid: string) { |
228 | const options = { | 229 | const query = { |
229 | include: [ | 230 | include: [ |
230 | { | 231 | { |
231 | model: ActorModel, | 232 | model: ActorModel, |
@@ -239,36 +240,63 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
239 | 240 | ||
240 | return VideoChannelModel | 241 | return VideoChannelModel |
241 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) | 242 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) |
242 | .findOne(options) | 243 | .findOne(query) |
243 | } | 244 | } |
244 | 245 | ||
245 | static loadAndPopulateAccountAndVideos (id: number) { | 246 | static loadLocalByNameAndPopulateAccount (name: string) { |
246 | const options = { | 247 | const query = { |
247 | include: [ | 248 | include: [ |
248 | VideoModel | 249 | { |
250 | model: ActorModel, | ||
251 | required: true, | ||
252 | where: { | ||
253 | preferredUsername: name, | ||
254 | serverId: null | ||
255 | } | ||
256 | } | ||
249 | ] | 257 | ] |
250 | } | 258 | } |
251 | 259 | ||
252 | return VideoChannelModel | 260 | return VideoChannelModel |
253 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ]) | 261 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) |
254 | .findById(id, options) | 262 | .findOne(query) |
255 | } | 263 | } |
256 | 264 | ||
257 | static loadLocalByName (name: string) { | 265 | static loadByNameAndHostAndPopulateAccount (name: string, host: string) { |
258 | const query = { | 266 | const query = { |
259 | include: [ | 267 | include: [ |
260 | { | 268 | { |
261 | model: ActorModel, | 269 | model: ActorModel, |
262 | required: true, | 270 | required: true, |
263 | where: { | 271 | where: { |
264 | preferredUsername: name, | 272 | preferredUsername: name |
265 | serverId: null | 273 | }, |
266 | } | 274 | include: [ |
275 | { | ||
276 | model: ServerModel, | ||
277 | required: true, | ||
278 | where: { host } | ||
279 | } | ||
280 | ] | ||
267 | } | 281 | } |
268 | ] | 282 | ] |
269 | } | 283 | } |
270 | 284 | ||
271 | return VideoChannelModel.findOne(query) | 285 | return VideoChannelModel |
286 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT ]) | ||
287 | .findOne(query) | ||
288 | } | ||
289 | |||
290 | static loadAndPopulateAccountAndVideos (id: number) { | ||
291 | const options = { | ||
292 | include: [ | ||
293 | VideoModel | ||
294 | ] | ||
295 | } | ||
296 | |||
297 | return VideoChannelModel | ||
298 | .scope([ ScopeNames.WITH_ACTOR, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEOS ]) | ||
299 | .findById(id, options) | ||
272 | } | 300 | } |
273 | 301 | ||
274 | toFormattedJSON (): VideoChannel { | 302 | toFormattedJSON (): VideoChannel { |