diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/index.ts | 2 | ||||
-rw-r--r-- | server/models/video/video.ts | 18 | ||||
-rw-r--r-- | server/tests/api/videos/multiple-servers.ts | 32 | ||||
-rw-r--r-- | server/tests/utils/videos/videos.ts | 12 |
4 files changed, 59 insertions, 5 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 10b309cd1..690872320 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -388,7 +388,7 @@ async function getVideoDescription (req: express.Request, res: express.Response) | |||
388 | } | 388 | } |
389 | 389 | ||
390 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 390 | async function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
391 | const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort) | 391 | const resultList = await VideoModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.filter) |
392 | 392 | ||
393 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 393 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
394 | } | 394 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 0e5dd0d2f..14eb64102 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -29,6 +29,7 @@ import { | |||
29 | import { VideoPrivacy, VideoResolution } from '../../../shared' | 29 | import { VideoPrivacy, VideoResolution } from '../../../shared' |
30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
31 | import { Video, VideoDetails } from '../../../shared/models/videos' | 31 | import { Video, VideoDetails } from '../../../shared/models/videos' |
32 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | ||
32 | import { activityPubCollection } from '../../helpers/activitypub' | 33 | import { activityPubCollection } from '../../helpers/activitypub' |
33 | import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' | 34 | import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' |
34 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 35 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
@@ -91,7 +92,7 @@ enum ScopeNames { | |||
91 | } | 92 | } |
92 | 93 | ||
93 | @Scopes({ | 94 | @Scopes({ |
94 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number) => ({ | 95 | [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, filter?: VideoFilter) => ({ |
95 | where: { | 96 | where: { |
96 | id: { | 97 | id: { |
97 | [Sequelize.Op.notIn]: Sequelize.literal( | 98 | [Sequelize.Op.notIn]: Sequelize.literal( |
@@ -129,6 +130,7 @@ enum ScopeNames { | |||
129 | attributes: [ 'preferredUsername', 'url', 'serverId' ], | 130 | attributes: [ 'preferredUsername', 'url', 'serverId' ], |
130 | model: ActorModel.unscoped(), | 131 | model: ActorModel.unscoped(), |
131 | required: true, | 132 | required: true, |
133 | where: VideoModel.buildActorWhereWithFilter(filter), | ||
132 | include: [ | 134 | include: [ |
133 | { | 135 | { |
134 | attributes: [ 'host' ], | 136 | attributes: [ 'host' ], |
@@ -639,7 +641,7 @@ export class VideoModel extends Model<VideoModel> { | |||
639 | }) | 641 | }) |
640 | } | 642 | } |
641 | 643 | ||
642 | static async listForApi (start: number, count: number, sort: string) { | 644 | static async listForApi (start: number, count: number, sort: string, filter?: VideoFilter) { |
643 | const query = { | 645 | const query = { |
644 | offset: start, | 646 | offset: start, |
645 | limit: count, | 647 | limit: count, |
@@ -648,7 +650,7 @@ export class VideoModel extends Model<VideoModel> { | |||
648 | 650 | ||
649 | const serverActor = await getServerActor() | 651 | const serverActor = await getServerActor() |
650 | 652 | ||
651 | return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id ] }) | 653 | return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, filter ] }) |
652 | .findAndCountAll(query) | 654 | .findAndCountAll(query) |
653 | .then(({ rows, count }) => { | 655 | .then(({ rows, count }) => { |
654 | return { | 656 | return { |
@@ -790,6 +792,16 @@ export class VideoModel extends Model<VideoModel> { | |||
790 | } | 792 | } |
791 | } | 793 | } |
792 | 794 | ||
795 | private static buildActorWhereWithFilter (filter?: VideoFilter) { | ||
796 | if (filter && filter === 'local') { | ||
797 | return { | ||
798 | serverId: null | ||
799 | } | ||
800 | } | ||
801 | |||
802 | return {} | ||
803 | } | ||
804 | |||
793 | getOriginalFile () { | 805 | getOriginalFile () { |
794 | if (Array.isArray(this.VideoFiles) === false) return undefined | 806 | if (Array.isArray(this.VideoFiles) === false) return undefined |
795 | 807 | ||
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index 3f6b82c50..42a1241f7 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | dateIsValid, | 15 | dateIsValid, |
16 | doubleFollow, | 16 | doubleFollow, |
17 | flushAndRunMultipleServers, | 17 | flushAndRunMultipleServers, |
18 | flushTests, | 18 | flushTests, getLocalVideos, |
19 | getVideo, | 19 | getVideo, |
20 | getVideoChannelsList, | 20 | getVideoChannelsList, |
21 | getVideosList, | 21 | getVideosList, |
@@ -349,6 +349,36 @@ describe('Test multiple servers', function () { | |||
349 | }) | 349 | }) |
350 | }) | 350 | }) |
351 | 351 | ||
352 | describe('It should list local videos', function () { | ||
353 | it('Should list only local videos on server 1', async function () { | ||
354 | const { body } = await getLocalVideos(servers[0].url) | ||
355 | |||
356 | expect(body.total).to.equal(1) | ||
357 | expect(body.data).to.be.an('array') | ||
358 | expect(body.data.length).to.equal(1) | ||
359 | expect(body.data[0].name).to.equal('my super name for server 1') | ||
360 | }) | ||
361 | |||
362 | it('Should list only local videos on server 2', async function () { | ||
363 | const { body } = await getLocalVideos(servers[1].url) | ||
364 | |||
365 | expect(body.total).to.equal(1) | ||
366 | expect(body.data).to.be.an('array') | ||
367 | expect(body.data.length).to.equal(1) | ||
368 | expect(body.data[0].name).to.equal('my super name for server 2') | ||
369 | }) | ||
370 | |||
371 | it('Should list only local videos on server 3', async function () { | ||
372 | const { body } = await getLocalVideos(servers[2].url) | ||
373 | |||
374 | expect(body.total).to.equal(2) | ||
375 | expect(body.data).to.be.an('array') | ||
376 | expect(body.data.length).to.equal(2) | ||
377 | expect(body.data[0].name).to.equal('my super name for server 3') | ||
378 | expect(body.data[1].name).to.equal('my super name for server 3-2') | ||
379 | }) | ||
380 | }) | ||
381 | |||
352 | describe('Should seed the uploaded video', function () { | 382 | describe('Should seed the uploaded video', function () { |
353 | it('Should add the file 1 by asking server 3', async function () { | 383 | it('Should add the file 1 by asking server 3', async function () { |
354 | this.timeout(10000) | 384 | this.timeout(10000) |
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts index ec40c5465..89db16fec 100644 --- a/server/tests/utils/videos/videos.ts +++ b/server/tests/utils/videos/videos.ts | |||
@@ -123,6 +123,17 @@ function getVideosList (url: string) { | |||
123 | .expect('Content-Type', /json/) | 123 | .expect('Content-Type', /json/) |
124 | } | 124 | } |
125 | 125 | ||
126 | function getLocalVideos (url: string) { | ||
127 | const path = '/api/v1/videos' | ||
128 | |||
129 | return request(url) | ||
130 | .get(path) | ||
131 | .query({ sort: 'name', filter: 'local' }) | ||
132 | .set('Accept', 'application/json') | ||
133 | .expect(200) | ||
134 | .expect('Content-Type', /json/) | ||
135 | } | ||
136 | |||
126 | function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) { | 137 | function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) { |
127 | const path = '/api/v1/users/me/videos' | 138 | const path = '/api/v1/users/me/videos' |
128 | 139 | ||
@@ -487,6 +498,7 @@ export { | |||
487 | rateVideo, | 498 | rateVideo, |
488 | viewVideo, | 499 | viewVideo, |
489 | parseTorrentVideo, | 500 | parseTorrentVideo, |
501 | getLocalVideos, | ||
490 | completeVideoCheck, | 502 | completeVideoCheck, |
491 | checkVideoFilesWereRemoved | 503 | checkVideoFilesWereRemoved |
492 | } | 504 | } |