aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video.ts18
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 {
29import { VideoPrivacy, VideoResolution } from '../../../shared' 29import { VideoPrivacy, VideoResolution } from '../../../shared'
30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
31import { Video, VideoDetails } from '../../../shared/models/videos' 31import { Video, VideoDetails } from '../../../shared/models/videos'
32import { VideoFilter } from '../../../shared/models/videos/video-query.type'
32import { activityPubCollection } from '../../helpers/activitypub' 33import { activityPubCollection } from '../../helpers/activitypub'
33import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils' 34import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
34import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 35import { 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