diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video.ts | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b0fff6526..2ad9c00dd 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -95,7 +95,33 @@ enum ScopeNames { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | @Scopes({ | 97 | @Scopes({ |
98 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean) => { | 98 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean, accountId?: number) => { |
99 | const accountInclude = { | ||
100 | attributes: [ 'name' ], | ||
101 | model: AccountModel.unscoped(), | ||
102 | required: true, | ||
103 | where: {}, | ||
104 | include: [ | ||
105 | { | ||
106 | attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], | ||
107 | model: ActorModel.unscoped(), | ||
108 | required: true, | ||
109 | where: VideoModel.buildActorWhereWithFilter(filter), | ||
110 | include: [ | ||
111 | { | ||
112 | attributes: [ 'host' ], | ||
113 | model: ServerModel.unscoped(), | ||
114 | required: false | ||
115 | }, | ||
116 | { | ||
117 | model: AvatarModel.unscoped(), | ||
118 | required: false | ||
119 | } | ||
120 | ] | ||
121 | } | ||
122 | ] | ||
123 | } | ||
124 | |||
99 | const query: IFindOptions<VideoModel> = { | 125 | const query: IFindOptions<VideoModel> = { |
100 | where: { | 126 | where: { |
101 | id: { | 127 | id: { |
@@ -125,30 +151,7 @@ enum ScopeNames { | |||
125 | model: VideoChannelModel.unscoped(), | 151 | model: VideoChannelModel.unscoped(), |
126 | required: true, | 152 | required: true, |
127 | include: [ | 153 | include: [ |
128 | { | 154 | accountInclude |
129 | attributes: [ 'name' ], | ||
130 | model: AccountModel.unscoped(), | ||
131 | required: true, | ||
132 | include: [ | ||
133 | { | ||
134 | attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], | ||
135 | model: ActorModel.unscoped(), | ||
136 | required: true, | ||
137 | where: VideoModel.buildActorWhereWithFilter(filter), | ||
138 | include: [ | ||
139 | { | ||
140 | attributes: [ 'host' ], | ||
141 | model: ServerModel.unscoped(), | ||
142 | required: false | ||
143 | }, | ||
144 | { | ||
145 | model: AvatarModel.unscoped(), | ||
146 | required: false | ||
147 | } | ||
148 | ] | ||
149 | } | ||
150 | ] | ||
151 | } | ||
152 | ] | 155 | ] |
153 | } | 156 | } |
154 | ] | 157 | ] |
@@ -166,6 +169,12 @@ enum ScopeNames { | |||
166 | query.where['nsfw'] = false | 169 | query.where['nsfw'] = false |
167 | } | 170 | } |
168 | 171 | ||
172 | if (accountId) { | ||
173 | accountInclude.where = { | ||
174 | id: accountId | ||
175 | } | ||
176 | } | ||
177 | |||
169 | return query | 178 | return query |
170 | }, | 179 | }, |
171 | [ScopeNames.WITH_ACCOUNT_DETAILS]: { | 180 | [ScopeNames.WITH_ACCOUNT_DETAILS]: { |
@@ -688,7 +697,15 @@ export class VideoModel extends Model<VideoModel> { | |||
688 | }) | 697 | }) |
689 | } | 698 | } |
690 | 699 | ||
691 | static async listForApi (start: number, count: number, sort: string, hideNSFW: boolean, filter?: VideoFilter, withFiles = false) { | 700 | static async listForApi ( |
701 | start: number, | ||
702 | count: number, | ||
703 | sort: string, | ||
704 | hideNSFW: boolean, | ||
705 | filter?: VideoFilter, | ||
706 | withFiles = false, | ||
707 | accountId?: number | ||
708 | ) { | ||
692 | const query = { | 709 | const query = { |
693 | offset: start, | 710 | offset: start, |
694 | limit: count, | 711 | limit: count, |
@@ -696,7 +713,7 @@ export class VideoModel extends Model<VideoModel> { | |||
696 | } | 713 | } |
697 | 714 | ||
698 | const serverActor = await getServerActor() | 715 | const serverActor = await getServerActor() |
699 | return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles ] }) | 716 | return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles, accountId ] }) |
700 | .findAndCountAll(query) | 717 | .findAndCountAll(query) |
701 | .then(({ rows, count }) => { | 718 | .then(({ rows, count }) => { |
702 | return { | 719 | return { |
@@ -879,8 +896,6 @@ export class VideoModel extends Model<VideoModel> { | |||
879 | 896 | ||
880 | private static getLanguageLabel (id: string) { | 897 | private static getLanguageLabel (id: string) { |
881 | let languageLabel = VIDEO_LANGUAGES[id] | 898 | let languageLabel = VIDEO_LANGUAGES[id] |
882 | console.log(VIDEO_LANGUAGES) | ||
883 | console.log(id) | ||
884 | if (!languageLabel) languageLabel = 'Unknown' | 899 | if (!languageLabel) languageLabel = 'Unknown' |
885 | 900 | ||
886 | return languageLabel | 901 | return languageLabel |