aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-29 14:17:03 +0200
committerChocobozzz <me@florianbigard.com>2021-07-29 14:17:03 +0200
commit9c9a236b541a286e165d67341e4ddd6ea2fabdf1 (patch)
treed7e397a3e160a64162f7ea1943529b2a06fb830a /server/models/video/video.ts
parent56d07460b5fe55cc86501742e759d9711d7eb386 (diff)
downloadPeerTube-9c9a236b541a286e165d67341e4ddd6ea2fabdf1.tar.gz
PeerTube-9c9a236b541a286e165d67341e4ddd6ea2fabdf1.tar.zst
PeerTube-9c9a236b541a286e165d67341e4ddd6ea2fabdf1.zip
Refactor options in models
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts110
1 files changed, 53 insertions, 57 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index d5efe2eac..56a5b0e18 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -31,7 +31,7 @@ import { LiveManager } from '@server/lib/live/live-manager'
31import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' 31import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths'
32import { getServerActor } from '@server/models/application/application' 32import { getServerActor } from '@server/models/application/application'
33import { ModelCache } from '@server/models/model-cache' 33import { ModelCache } from '@server/models/model-cache'
34import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath } from '@shared/core-utils' 34import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils'
35import { VideoFile } from '@shared/models/videos/video-file.model' 35import { VideoFile } from '@shared/models/videos/video-file.model'
36import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' 36import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
37import { VideoObject } from '../../../shared/models/activitypub/objects' 37import { VideoObject } from '../../../shared/models/activitypub/objects'
@@ -1083,41 +1083,44 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1083 : serverActor.id 1083 : serverActor.id
1084 1084
1085 const queryOptions = { 1085 const queryOptions = {
1086 start: options.start, 1086 ...pick(options, [
1087 count: options.count, 1087 'start',
1088 sort: options.sort, 1088 'count',
1089 'sort',
1090 'nsfw',
1091 'isLive',
1092 'categoryOneOf',
1093 'licenceOneOf',
1094 'languageOneOf',
1095 'tagsOneOf',
1096 'tagsAllOf',
1097 'filter',
1098 'withFiles',
1099 'accountId',
1100 'videoChannelId',
1101 'videoPlaylistId',
1102 'includeLocalVideos',
1103 'user',
1104 'historyOfUser',
1105 'search'
1106 ]),
1107
1089 followerActorId, 1108 followerActorId,
1090 serverAccountId: serverActor.Account.id, 1109 serverAccountId: serverActor.Account.id,
1091 nsfw: options.nsfw,
1092 isLive: options.isLive,
1093 categoryOneOf: options.categoryOneOf,
1094 licenceOneOf: options.licenceOneOf,
1095 languageOneOf: options.languageOneOf,
1096 tagsOneOf: options.tagsOneOf,
1097 tagsAllOf: options.tagsAllOf,
1098 filter: options.filter,
1099 withFiles: options.withFiles,
1100 accountId: options.accountId,
1101 videoChannelId: options.videoChannelId,
1102 videoPlaylistId: options.videoPlaylistId,
1103 includeLocalVideos: options.includeLocalVideos,
1104 user: options.user,
1105 historyOfUser: options.historyOfUser,
1106 trendingDays, 1110 trendingDays,
1107 trendingAlgorithm, 1111 trendingAlgorithm
1108 search: options.search
1109 } 1112 }
1110 1113
1111 return VideoModel.getAvailableForApi(queryOptions, options.countVideos) 1114 return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
1112 } 1115 }
1113 1116
1114 static async searchAndPopulateAccountAndServer (options: { 1117 static async searchAndPopulateAccountAndServer (options: {
1118 start: number
1119 count: number
1120 sort: string
1115 includeLocalVideos: boolean 1121 includeLocalVideos: boolean
1116 search?: string 1122 search?: string
1117 host?: string 1123 host?: string
1118 start?: number
1119 count?: number
1120 sort?: string
1121 startDate?: string // ISO 8601 1124 startDate?: string // ISO 8601
1122 endDate?: string // ISO 8601 1125 endDate?: string // ISO 8601
1123 originallyPublishedStartDate?: string 1126 originallyPublishedStartDate?: string
@@ -1138,40 +1141,33 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
1138 const serverActor = await getServerActor() 1141 const serverActor = await getServerActor()
1139 1142
1140 const queryOptions = { 1143 const queryOptions = {
1141 followerActorId: serverActor.id, 1144 ...pick(options, [
1142 serverAccountId: serverActor.Account.id, 1145 'includeLocalVideos',
1143 1146 'nsfw',
1144 includeLocalVideos: options.includeLocalVideos, 1147 'isLive',
1145 nsfw: options.nsfw, 1148 'categoryOneOf',
1146 isLive: options.isLive, 1149 'licenceOneOf',
1147 1150 'languageOneOf',
1148 categoryOneOf: options.categoryOneOf, 1151 'tagsOneOf',
1149 licenceOneOf: options.licenceOneOf, 1152 'tagsAllOf',
1150 languageOneOf: options.languageOneOf, 1153 'user',
1154 'filter',
1155 'host',
1156 'start',
1157 'count',
1158 'sort',
1159 'startDate',
1160 'endDate',
1161 'originallyPublishedStartDate',
1162 'originallyPublishedEndDate',
1163 'durationMin',
1164 'durationMax',
1165 'uuids',
1166 'search'
1167 ]),
1151 1168
1152 tagsOneOf: options.tagsOneOf, 1169 followerActorId: serverActor.id,
1153 tagsAllOf: options.tagsAllOf, 1170 serverAccountId: serverActor.Account.id
1154
1155 user: options.user,
1156 filter: options.filter,
1157 host: options.host,
1158
1159 start: options.start,
1160 count: options.count,
1161 sort: options.sort,
1162
1163 startDate: options.startDate,
1164 endDate: options.endDate,
1165
1166 originallyPublishedStartDate: options.originallyPublishedStartDate,
1167 originallyPublishedEndDate: options.originallyPublishedEndDate,
1168
1169 durationMin: options.durationMin,
1170 durationMax: options.durationMax,
1171
1172 uuids: options.uuids,
1173
1174 search: options.search
1175 } 1171 }
1176 1172
1177 return VideoModel.getAvailableForApi(queryOptions) 1173 return VideoModel.getAvailableForApi(queryOptions)