aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/initializers/constants.ts4
-rw-r--r--server/models/video/video-query-builder.ts6
-rw-r--r--server/tests/api/videos/single-server.ts49
3 files changed, 50 insertions, 9 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index e801e282a..bc6c58b06 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -59,9 +59,9 @@ const SORTABLE_COLUMNS = {
59 FOLLOWERS: [ 'createdAt', 'state', 'score' ], 59 FOLLOWERS: [ 'createdAt', 'state', 'score' ],
60 FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ], 60 FOLLOWING: [ 'createdAt', 'redundancyAllowed', 'state' ],
61 61
62 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'trending' ], 62 VIDEOS: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending' ],
63 63
64 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'views', 'likes', 'match' ], 64 VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
65 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ], 65 VIDEO_CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
66 66
67 ACCOUNTS_BLOCKLIST: [ 'createdAt' ], 67 ACCOUNTS_BLOCKLIST: [ 'createdAt' ],
diff --git a/server/models/video/video-query-builder.ts b/server/models/video/video-query-builder.ts
index 8f0a814de..455f9f30f 100644
--- a/server/models/video/video-query-builder.ts
+++ b/server/models/video/video-query-builder.ts
@@ -321,6 +321,10 @@ function buildListQuery (model: typeof Model, options: BuildVideosQueryOptions)
321 if (options.isCount !== true) { 321 if (options.isCount !== true) {
322 322
323 if (exists(options.sort)) { 323 if (exists(options.sort)) {
324 if (options.sort === '-originallyPublishedAt' || options.sort === 'originallyPublishedAt') {
325 attributes.push('COALESCE("video"."originallyPublishedAt", "video"."publishedAt") AS "publishedAtForOrder"')
326 }
327
324 order = buildOrder(model, options.sort) 328 order = buildOrder(model, options.sort)
325 suffix += `${order} ` 329 suffix += `${order} `
326 } 330 }
@@ -365,6 +369,8 @@ function buildOrder (model: typeof Model, value: string) {
365 369
366 if (field.toLowerCase() === 'match') { // Search 370 if (field.toLowerCase() === 'match') { // Search
367 firstSort = '"similarity"' 371 firstSort = '"similarity"'
372 } else if (field === 'originallyPublishedAt') {
373 firstSort = '"publishedAtForOrder"'
368 } else if (field.includes('.')) { 374 } else if (field.includes('.')) {
369 firstSort = field 375 firstSort = field
370 } else { 376 } else {
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index 596fff996..0ae405950 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -34,6 +34,7 @@ const expect = chai.expect
34describe('Test a single server', function () { 34describe('Test a single server', function () {
35 let server: ServerInfo = null 35 let server: ServerInfo = null
36 let videoId = -1 36 let videoId = -1
37 let videoId2 = -1
37 let videoUUID = '' 38 let videoUUID = ''
38 let videosListBase: any[] = null 39 let videosListBase: any[] = null
39 40
@@ -237,12 +238,11 @@ describe('Test a single server', function () {
237 it('Should upload 6 videos', async function () { 238 it('Should upload 6 videos', async function () {
238 this.timeout(25000) 239 this.timeout(25000)
239 240
240 const videos = [ 241 const videos = new Set([
241 'video_short.mp4', 'video_short.ogv', 'video_short.webm', 242 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
242 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' 243 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
243 ] 244 ])
244 245
245 const tasks: Promise<any>[] = []
246 for (const video of videos) { 246 for (const video of videos) {
247 const videoAttributes = { 247 const videoAttributes = {
248 name: video + ' name', 248 name: video + ' name',
@@ -255,11 +255,8 @@ describe('Test a single server', function () {
255 fixture: video 255 fixture: video
256 } 256 }
257 257
258 const p = uploadVideo(server.url, server.accessToken, videoAttributes) 258 await uploadVideo(server.url, server.accessToken, videoAttributes)
259 tasks.push(p)
260 } 259 }
261
262 await Promise.all(tasks)
263 }) 260 })
264 261
265 it('Should have the correct durations', async function () { 262 it('Should have the correct durations', async function () {
@@ -345,6 +342,7 @@ describe('Test a single server', function () {
345 expect(videos[5].name).to.equal('video_short1.webm name') 342 expect(videos[5].name).to.equal('video_short1.webm name')
346 343
347 videoId = videos[3].uuid 344 videoId = videos[3].uuid
345 videoId2 = videos[5].uuid
348 }) 346 })
349 347
350 it('Should list and sort by trending in descending order', async function () { 348 it('Should list and sort by trending in descending order', async function () {
@@ -433,6 +431,43 @@ describe('Test a single server', function () {
433 expect(video.dislikes).to.equal(1) 431 expect(video.dislikes).to.equal(1)
434 }) 432 })
435 433
434 it('Should sort by originallyPublishedAt', async function () {
435 {
436
437 {
438 const now = new Date()
439 const attributes = { originallyPublishedAt: now.toISOString() }
440 await updateVideo(server.url, server.accessToken, videoId, attributes)
441
442 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
443 const names = res.body.data.map(v => v.name)
444
445 expect(names[0]).to.equal('my super video updated')
446 expect(names[1]).to.equal('video_short2.webm name')
447 expect(names[2]).to.equal('video_short1.webm name')
448 expect(names[3]).to.equal('video_short.webm name')
449 expect(names[4]).to.equal('video_short.ogv name')
450 expect(names[5]).to.equal('video_short.mp4 name')
451 }
452
453 {
454 const now = new Date()
455 const attributes = { originallyPublishedAt: now.toISOString() }
456 await updateVideo(server.url, server.accessToken, videoId2, attributes)
457
458 const res = await getVideosListSort(server.url, '-originallyPublishedAt')
459 const names = res.body.data.map(v => v.name)
460
461 expect(names[0]).to.equal('video_short1.webm name')
462 expect(names[1]).to.equal('my super video updated')
463 expect(names[2]).to.equal('video_short2.webm name')
464 expect(names[3]).to.equal('video_short.webm name')
465 expect(names[4]).to.equal('video_short.ogv name')
466 expect(names[5]).to.equal('video_short.mp4 name')
467 }
468 }
469 })
470
436 after(async function () { 471 after(async function () {
437 await cleanupTests([ server ]) 472 await cleanupTests([ server ])
438 }) 473 })