aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-01 08:32:49 +0100
committerChocobozzz <me@florianbigard.com>2022-03-01 08:32:49 +0100
commit242f52253e46ce0ffd7349cb06bcd887bb89cf06 (patch)
tree91ff643ea722881a5e11e4446a3c696ec0f6e3cb
parentf41efa52a412272928ba90e06c9a9a9c471d1ca3 (diff)
downloadPeerTube-242f52253e46ce0ffd7349cb06bcd887bb89cf06.tar.gz
PeerTube-242f52253e46ce0ffd7349cb06bcd887bb89cf06.tar.zst
PeerTube-242f52253e46ce0ffd7349cb06bcd887bb89cf06.zip
Fix getting avatars in videos list
-rw-r--r--server/models/video/sql/video/shared/video-model-builder.ts8
-rw-r--r--server/tests/api/videos/multiple-servers.ts18
2 files changed, 23 insertions, 3 deletions
diff --git a/server/models/video/sql/video/shared/video-model-builder.ts b/server/models/video/sql/video/shared/video-model-builder.ts
index b1b47b721..166ff9d31 100644
--- a/server/models/video/sql/video/shared/video-model-builder.ts
+++ b/server/models/video/sql/video/shared/video-model-builder.ts
@@ -234,15 +234,17 @@ export class VideoModelBuilder {
234 } 234 }
235 235
236 private addActorAvatar (row: SQLRow, actorPrefix: string, actor: ActorModel) { 236 private addActorAvatar (row: SQLRow, actorPrefix: string, actor: ActorModel) {
237 const avatarPrefix = `${actorPrefix}.Avatar` 237 const avatarPrefix = `${actorPrefix}.Avatars`
238 const id = row[`${avatarPrefix}.id`] 238 const id = row[`${avatarPrefix}.id`]
239 if (!id || this.actorImagesDone.has(id)) return 239 const key = `${row.id}${id}`
240
241 if (!id || this.actorImagesDone.has(key)) return
240 242
241 const attributes = this.grab(row, this.tables.getAvatarAttributes(), avatarPrefix) 243 const attributes = this.grab(row, this.tables.getAvatarAttributes(), avatarPrefix)
242 const avatarModel = new ActorImageModel(attributes, this.buildOpts) 244 const avatarModel = new ActorImageModel(attributes, this.buildOpts)
243 actor.Avatars.push(avatarModel) 245 actor.Avatars.push(avatarModel)
244 246
245 this.actorImagesDone.add(id) 247 this.actorImagesDone.add(key)
246 } 248 }
247 249
248 private addThumbnail (row: SQLRow, videoModel: VideoModel) { 250 private addThumbnail (row: SQLRow, videoModel: VideoModel) {
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 5bbc60559..2a49fd360 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -2,6 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { and } from 'sequelize/dist'
5import request from 'supertest' 6import request from 'supertest'
6import { 7import {
7 checkTmpIsEmpty, 8 checkTmpIsEmpty,
@@ -17,6 +18,7 @@ import {
17 cleanupTests, 18 cleanupTests,
18 createMultipleServers, 19 createMultipleServers,
19 doubleFollow, 20 doubleFollow,
21 makeGetRequest,
20 PeerTubeServer, 22 PeerTubeServer,
21 setAccessTokensToServers, 23 setAccessTokensToServers,
22 setDefaultAccountAvatar, 24 setDefaultAccountAvatar,
@@ -138,6 +140,22 @@ describe('Test multiple servers', function () {
138 140
139 await completeVideoCheck(server, video, checkAttributes) 141 await completeVideoCheck(server, video, checkAttributes)
140 publishedAt = video.publishedAt as string 142 publishedAt = video.publishedAt as string
143
144 expect(video.channel.avatars).to.have.lengthOf(2)
145 expect(video.account.avatars).to.have.lengthOf(2)
146
147 for (const image of [ ...video.channel.avatars, ...video.account.avatars ]) {
148 expect(image.createdAt).to.exist
149 expect(image.updatedAt).to.exist
150 expect(image.width).to.be.above(20).and.below(1000)
151 expect(image.path).to.exist
152
153 await makeGetRequest({
154 url: server.url,
155 path: image.path,
156 expectedStatus: HttpStatusCode.OK_200
157 })
158 }
141 } 159 }
142 }) 160 })
143 161