aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video.ts24
1 files changed, 17 insertions, 7 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index a7923b477..2e66f9aa7 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -95,7 +95,7 @@ enum ScopeNames {
95} 95}
96 96
97@Scopes({ 97@Scopes({
98 [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, filter?: VideoFilter, withFiles?: boolean) => { 98 [ScopeNames.AVAILABLE_FOR_LIST]: (actorId: number, hideNSFW: boolean, filter?: VideoFilter, withFiles?: boolean) => {
99 const query: IFindOptions<VideoModel> = { 99 const query: IFindOptions<VideoModel> = {
100 where: { 100 where: {
101 id: { 101 id: {
@@ -161,6 +161,11 @@ enum ScopeNames {
161 }) 161 })
162 } 162 }
163 163
164 // Hide nsfw videos?
165 if (hideNSFW === true) {
166 query.where['nsfw'] = false
167 }
168
164 return query 169 return query
165 }, 170 },
166 [ScopeNames.WITH_ACCOUNT_DETAILS]: { 171 [ScopeNames.WITH_ACCOUNT_DETAILS]: {
@@ -640,7 +645,7 @@ export class VideoModel extends Model<VideoModel> {
640 }) 645 })
641 } 646 }
642 647
643 static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { 648 static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, hideNSFW: boolean, withFiles = false) {
644 const query: IFindOptions<VideoModel> = { 649 const query: IFindOptions<VideoModel> = {
645 offset: start, 650 offset: start,
646 limit: count, 651 limit: count,
@@ -669,6 +674,12 @@ export class VideoModel extends Model<VideoModel> {
669 }) 674 })
670 } 675 }
671 676
677 if (hideNSFW === true) {
678 query.where = {
679 nsfw: false
680 }
681 }
682
672 return VideoModel.findAndCountAll(query).then(({ rows, count }) => { 683 return VideoModel.findAndCountAll(query).then(({ rows, count }) => {
673 return { 684 return {
674 data: rows, 685 data: rows,
@@ -677,7 +688,7 @@ export class VideoModel extends Model<VideoModel> {
677 }) 688 })
678 } 689 }
679 690
680 static async listForApi (start: number, count: number, sort: string, filter?: VideoFilter, withFiles = false) { 691 static async listForApi (start: number, count: number, sort: string, hideNSFW: boolean, filter?: VideoFilter, withFiles = false) {
681 const query = { 692 const query = {
682 offset: start, 693 offset: start,
683 limit: count, 694 limit: count,
@@ -685,8 +696,7 @@ export class VideoModel extends Model<VideoModel> {
685 } 696 }
686 697
687 const serverActor = await getServerActor() 698 const serverActor = await getServerActor()
688 699 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW, filter, withFiles ] })
689 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, filter, withFiles ] })
690 .findAndCountAll(query) 700 .findAndCountAll(query)
691 .then(({ rows, count }) => { 701 .then(({ rows, count }) => {
692 return { 702 return {
@@ -696,7 +706,7 @@ export class VideoModel extends Model<VideoModel> {
696 }) 706 })
697 } 707 }
698 708
699 static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string) { 709 static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string, hideNSFW: boolean) {
700 const query: IFindOptions<VideoModel> = { 710 const query: IFindOptions<VideoModel> = {
701 offset: start, 711 offset: start,
702 limit: count, 712 limit: count,
@@ -724,7 +734,7 @@ export class VideoModel extends Model<VideoModel> {
724 734
725 const serverActor = await getServerActor() 735 const serverActor = await getServerActor()
726 736
727 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id ] }) 737 return VideoModel.scope({ method: [ ScopeNames.AVAILABLE_FOR_LIST, serverActor.id, hideNSFW ] })
728 .findAndCountAll(query) 738 .findAndCountAll(query)
729 .then(({ rows, count }) => { 739 .then(({ rows, count }) => {
730 return { 740 return {