aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-share.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r--server/models/video/video-share.ts19
1 files changed, 9 insertions, 10 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts
index f9ee94589..b7f5f3fa3 100644
--- a/server/models/video/video-share.ts
+++ b/server/models/video/video-share.ts
@@ -1,13 +1,12 @@
1import * as Bluebird from 'bluebird' 1import { literal, Op, Transaction } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 3import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { MActorDefault } from '../../types/models'
6import { MVideoShareActor, MVideoShareFull } from '../../types/models/video'
5import { ActorModel } from '../activitypub/actor' 7import { ActorModel } from '../activitypub/actor'
6import { buildLocalActorIdsIn, throwIfNotValid } from '../utils' 8import { buildLocalActorIdsIn, throwIfNotValid } from '../utils'
7import { VideoModel } from './video' 9import { VideoModel } from './video'
8import { literal, Op, Transaction } from 'sequelize'
9import { MVideoShareActor, MVideoShareFull } from '../../types/models/video'
10import { MActorDefault } from '../../types/models'
11 10
12enum ScopeNames { 11enum ScopeNames {
13 FULL = 'FULL', 12 FULL = 'FULL',
@@ -51,7 +50,7 @@ enum ScopeNames {
51 } 50 }
52 ] 51 ]
53}) 52})
54export class VideoShareModel extends Model<VideoShareModel> { 53export class VideoShareModel extends Model {
55 54
56 @AllowNull(false) 55 @AllowNull(false)
57 @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) 56 @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url'))
@@ -88,7 +87,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
88 }) 87 })
89 Video: VideoModel 88 Video: VideoModel
90 89
91 static load (actorId: number | string, videoId: number | string, t?: Transaction): Bluebird<MVideoShareActor> { 90 static load (actorId: number | string, videoId: number | string, t?: Transaction): Promise<MVideoShareActor> {
92 return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ 91 return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
93 where: { 92 where: {
94 actorId, 93 actorId,
@@ -98,7 +97,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
98 }) 97 })
99 } 98 }
100 99
101 static loadByUrl (url: string, t: Transaction): Bluebird<MVideoShareFull> { 100 static loadByUrl (url: string, t: Transaction): Promise<MVideoShareFull> {
102 return VideoShareModel.scope(ScopeNames.FULL).findOne({ 101 return VideoShareModel.scope(ScopeNames.FULL).findOne({
103 where: { 102 where: {
104 url 103 url
@@ -107,7 +106,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
107 }) 106 })
108 } 107 }
109 108
110 static loadActorsByShare (videoId: number, t: Transaction): Bluebird<MActorDefault[]> { 109 static loadActorsByShare (videoId: number, t: Transaction): Promise<MActorDefault[]> {
111 const query = { 110 const query = {
112 where: { 111 where: {
113 videoId 112 videoId
@@ -125,7 +124,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
125 .then((res: MVideoShareFull[]) => res.map(r => r.Actor)) 124 .then((res: MVideoShareFull[]) => res.map(r => r.Actor))
126 } 125 }
127 126
128 static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<MActorDefault[]> { 127 static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Promise<MActorDefault[]> {
129 const safeOwnerId = parseInt(actorOwnerId + '', 10) 128 const safeOwnerId = parseInt(actorOwnerId + '', 10)
130 129
131 // /!\ On actor model 130 // /!\ On actor model
@@ -150,7 +149,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
150 return ActorModel.findAll(query) 149 return ActorModel.findAll(query)
151 } 150 }
152 151
153 static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<MActorDefault[]> { 152 static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Promise<MActorDefault[]> {
154 const safeChannelId = parseInt(videoChannelId + '', 10) 153 const safeChannelId = parseInt(videoChannelId + '', 10)
155 154
156 // /!\ On actor model 155 // /!\ On actor model