diff options
author | Chocobozzz <me@florianbigard.com> | 2018-03-13 10:24:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-03-13 10:24:28 +0100 |
commit | 066e94c5382a761180c7d82fa24b31b66dbeaca4 (patch) | |
tree | 36037c2c5aaa6c86c2299ceafe6ec35dd1abbd13 /server/models | |
parent | 66c3b7744c6c7a91b9538eb5a6e0ae07e0a5a6af (diff) | |
download | PeerTube-066e94c5382a761180c7d82fa24b31b66dbeaca4.tar.gz PeerTube-066e94c5382a761180c7d82fa24b31b66dbeaca4.tar.zst PeerTube-066e94c5382a761180c7d82fa24b31b66dbeaca4.zip |
Add "local" videos in menu
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video.ts | 18 |
1 files changed, 15 insertions, 3 deletions
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 | ||