diff options
author | Andrés Maldonado <amaldona@etu.utc.fr> | 2018-11-27 18:57:02 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-12 11:14:37 +0100 |
commit | 31d065cc50e17a9abf263ed8c606cb272cd4933d (patch) | |
tree | 5e4516cb48dd36490e817bd9e59c41f3cad0d968 /server | |
parent | 7f8f8bdb4a1fb695a114874c4679605ac8911e2d (diff) | |
download | PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.tar.gz PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.tar.zst PeerTube-31d065cc50e17a9abf263ed8c606cb272cd4933d.zip |
Add search by original publication date
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video.ts | 11 | ||||
-rw-r--r-- | server/tests/api/check-params/search.ts | 6 | ||||
-rw-r--r-- | server/tests/api/search/search-videos.ts | 66 |
3 files changed, 82 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 215e26d7d..fe81fab1a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1174,6 +1174,8 @@ export class VideoModel extends Model<VideoModel> { | |||
1174 | sort?: string | 1174 | sort?: string |
1175 | startDate?: string // ISO 8601 | 1175 | startDate?: string // ISO 8601 |
1176 | endDate?: string // ISO 8601 | 1176 | endDate?: string // ISO 8601 |
1177 | originallyPublishedStartDate?: string | ||
1178 | originallyPublishedEndDate?: string | ||
1177 | nsfw?: boolean | 1179 | nsfw?: boolean |
1178 | categoryOneOf?: number[] | 1180 | categoryOneOf?: number[] |
1179 | licenceOneOf?: number[] | 1181 | licenceOneOf?: number[] |
@@ -1196,6 +1198,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1196 | whereAnd.push({ publishedAt: publishedAtRange }) | 1198 | whereAnd.push({ publishedAt: publishedAtRange }) |
1197 | } | 1199 | } |
1198 | 1200 | ||
1201 | if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) { | ||
1202 | const originallyPublishedAtRange = {} | ||
1203 | |||
1204 | if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Sequelize.Op.gte ] = options.originallyPublishedStartDate | ||
1205 | if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Sequelize.Op.lte ] = options.originallyPublishedEndDate | ||
1206 | |||
1207 | whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange }) | ||
1208 | } | ||
1209 | |||
1199 | if (options.durationMin || options.durationMax) { | 1210 | if (options.durationMin || options.durationMax) { |
1200 | const durationRange = {} | 1211 | const durationRange = {} |
1201 | 1212 | ||
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index aa81965f3..7b7e07784 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts | |||
@@ -113,6 +113,12 @@ describe('Test videos API validator', function () { | |||
113 | 113 | ||
114 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) | 114 | const customQuery2 = immutableAssign(query, { endDate: 'hello' }) |
115 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) | 115 | await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) |
116 | |||
117 | const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) | ||
118 | await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) | ||
119 | |||
120 | const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) | ||
121 | await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) | ||
116 | }) | 122 | }) |
117 | }) | 123 | }) |
118 | 124 | ||
diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index 50da837da..fa4078b99 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts | |||
@@ -60,7 +60,10 @@ describe('Test a videos search', function () { | |||
60 | const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] }) | 60 | const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] }) |
61 | await uploadVideo(server.url, server.accessToken, attributes6) | 61 | await uploadVideo(server.url, server.accessToken, attributes6) |
62 | 62 | ||
63 | const attributes7 = immutableAssign(attributes1, { name: attributes1.name + ' - 7' }) | 63 | const attributes7 = immutableAssign(attributes1, { |
64 | name: attributes1.name + ' - 7', | ||
65 | originallyPublishedAt: '2019-02-12T09:58:08.286Z' | ||
66 | }) | ||
64 | await uploadVideo(server.url, server.accessToken, attributes7) | 67 | await uploadVideo(server.url, server.accessToken, attributes7) |
65 | 68 | ||
66 | const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) | 69 | const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) |
@@ -343,6 +346,67 @@ describe('Test a videos search', function () { | |||
343 | expect(videos[0].name).to.equal('1111 2222 3333') | 346 | expect(videos[0].name).to.equal('1111 2222 3333') |
344 | }) | 347 | }) |
345 | 348 | ||
349 | it('Should search on originally published date', async function () { | ||
350 | const baseQuery = { | ||
351 | search: '1111 2222 3333', | ||
352 | languageOneOf: [ 'pl', 'fr' ], | ||
353 | durationMax: 4, | ||
354 | nsfw: 'false' as 'false', | ||
355 | licenceOneOf: [ 1, 4 ] | ||
356 | } | ||
357 | |||
358 | { | ||
359 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' }) | ||
360 | const res = await advancedVideosSearch(server.url, query) | ||
361 | |||
362 | expect(res.body.total).to.equal(1) | ||
363 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | ||
364 | } | ||
365 | |||
366 | { | ||
367 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' }) | ||
368 | const res = await advancedVideosSearch(server.url, query) | ||
369 | |||
370 | expect(res.body.total).to.equal(1) | ||
371 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | ||
372 | } | ||
373 | |||
374 | { | ||
375 | const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' }) | ||
376 | const res = await advancedVideosSearch(server.url, query) | ||
377 | |||
378 | expect(res.body.total).to.equal(0) | ||
379 | } | ||
380 | |||
381 | { | ||
382 | const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' }) | ||
383 | const res = await advancedVideosSearch(server.url, query) | ||
384 | |||
385 | expect(res.body.total).to.equal(0) | ||
386 | } | ||
387 | |||
388 | { | ||
389 | const query = immutableAssign(baseQuery, { | ||
390 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | ||
391 | originallyPublishedEndDate: '2019-01-10T09:58:08.286Z' | ||
392 | }) | ||
393 | const res = await advancedVideosSearch(server.url, query) | ||
394 | |||
395 | expect(res.body.total).to.equal(0) | ||
396 | } | ||
397 | |||
398 | { | ||
399 | const query = immutableAssign(baseQuery, { | ||
400 | originallyPublishedStartDate: '2019-01-11T09:58:08.286Z', | ||
401 | originallyPublishedEndDate: '2019-04-11T09:58:08.286Z' | ||
402 | }) | ||
403 | const res = await advancedVideosSearch(server.url, query) | ||
404 | |||
405 | expect(res.body.total).to.equal(1) | ||
406 | expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7') | ||
407 | } | ||
408 | }) | ||
409 | |||
346 | after(async function () { | 410 | after(async function () { |
347 | killallServers([ server ]) | 411 | killallServers([ server ]) |
348 | 412 | ||