aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-05-03 11:06:19 +0200
committerChocobozzz <me@florianbigard.com>2021-05-03 16:42:15 +0200
commit1fd61899eaea245a5844e33e21f04b2562f16e5e (patch)
tree2a1d51b37b12219cade35e189d62686cd0fec105 /server/models/video/video.ts
parentdfcb6f50a607b6b402b4f8fa3d43792d61c912a5 (diff)
downloadPeerTube-1fd61899eaea245a5844e33e21f04b2562f16e5e.tar.gz
PeerTube-1fd61899eaea245a5844e33e21f04b2562f16e5e.tar.zst
PeerTube-1fd61899eaea245a5844e33e21f04b2562f16e5e.zip
Add ability to filter my videos by live
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts52
1 files changed, 39 insertions, 13 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 422bf6deb..e55a21a6b 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1021,14 +1021,28 @@ export class VideoModel extends Model {
1021 start: number 1021 start: number
1022 count: number 1022 count: number
1023 sort: string 1023 sort: string
1024 isLive?: boolean
1024 search?: string 1025 search?: string
1025 }) { 1026 }) {
1026 const { accountId, start, count, sort, search } = options 1027 const { accountId, start, count, sort, search, isLive } = options
1027 1028
1028 function buildBaseQuery (): FindOptions { 1029 function buildBaseQuery (): FindOptions {
1029 let baseQuery = { 1030 const where: WhereOptions = {}
1031
1032 if (search) {
1033 where.name = {
1034 [Op.iLike]: '%' + search + '%'
1035 }
1036 }
1037
1038 if (isLive) {
1039 where.isLive = isLive
1040 }
1041
1042 const baseQuery = {
1030 offset: start, 1043 offset: start,
1031 limit: count, 1044 limit: count,
1045 where,
1032 order: getVideoSort(sort), 1046 order: getVideoSort(sort),
1033 include: [ 1047 include: [
1034 { 1048 {
@@ -1047,16 +1061,6 @@ export class VideoModel extends Model {
1047 ] 1061 ]
1048 } 1062 }
1049 1063
1050 if (search) {
1051 baseQuery = Object.assign(baseQuery, {
1052 where: {
1053 name: {
1054 [Op.iLike]: '%' + search + '%'
1055 }
1056 }
1057 })
1058 }
1059
1060 return baseQuery 1064 return baseQuery
1061 } 1065 }
1062 1066
@@ -1084,23 +1088,34 @@ export class VideoModel extends Model {
1084 start: number 1088 start: number
1085 count: number 1089 count: number
1086 sort: string 1090 sort: string
1091
1087 nsfw: boolean 1092 nsfw: boolean
1093 filter?: VideoFilter
1094 isLive?: boolean
1095
1088 includeLocalVideos: boolean 1096 includeLocalVideos: boolean
1089 withFiles: boolean 1097 withFiles: boolean
1098
1090 categoryOneOf?: number[] 1099 categoryOneOf?: number[]
1091 licenceOneOf?: number[] 1100 licenceOneOf?: number[]
1092 languageOneOf?: string[] 1101 languageOneOf?: string[]
1093 tagsOneOf?: string[] 1102 tagsOneOf?: string[]
1094 tagsAllOf?: string[] 1103 tagsAllOf?: string[]
1095 filter?: VideoFilter 1104
1096 accountId?: number 1105 accountId?: number
1097 videoChannelId?: number 1106 videoChannelId?: number
1107
1098 followerActorId?: number 1108 followerActorId?: number
1109
1099 videoPlaylistId?: number 1110 videoPlaylistId?: number
1111
1100 trendingDays?: number 1112 trendingDays?: number
1113
1101 user?: MUserAccountId 1114 user?: MUserAccountId
1102 historyOfUser?: MUserId 1115 historyOfUser?: MUserId
1116
1103 countVideos?: boolean 1117 countVideos?: boolean
1118
1104 search?: string 1119 search?: string
1105 }) { 1120 }) {
1106 if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { 1121 if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
@@ -1128,6 +1143,7 @@ export class VideoModel extends Model {
1128 followerActorId, 1143 followerActorId,
1129 serverAccountId: serverActor.Account.id, 1144 serverAccountId: serverActor.Account.id,
1130 nsfw: options.nsfw, 1145 nsfw: options.nsfw,
1146 isLive: options.isLive,
1131 categoryOneOf: options.categoryOneOf, 1147 categoryOneOf: options.categoryOneOf,
1132 licenceOneOf: options.licenceOneOf, 1148 licenceOneOf: options.licenceOneOf,
1133 languageOneOf: options.languageOneOf, 1149 languageOneOf: options.languageOneOf,
@@ -1160,6 +1176,7 @@ export class VideoModel extends Model {
1160 originallyPublishedStartDate?: string 1176 originallyPublishedStartDate?: string
1161 originallyPublishedEndDate?: string 1177 originallyPublishedEndDate?: string
1162 nsfw?: boolean 1178 nsfw?: boolean
1179 isLive?: boolean
1163 categoryOneOf?: number[] 1180 categoryOneOf?: number[]
1164 licenceOneOf?: number[] 1181 licenceOneOf?: number[]
1165 languageOneOf?: string[] 1182 languageOneOf?: string[]
@@ -1171,23 +1188,32 @@ export class VideoModel extends Model {
1171 filter?: VideoFilter 1188 filter?: VideoFilter
1172 }) { 1189 }) {
1173 const serverActor = await getServerActor() 1190 const serverActor = await getServerActor()
1191
1174 const queryOptions = { 1192 const queryOptions = {
1175 followerActorId: serverActor.id, 1193 followerActorId: serverActor.id,
1176 serverAccountId: serverActor.Account.id, 1194 serverAccountId: serverActor.Account.id,
1195
1177 includeLocalVideos: options.includeLocalVideos, 1196 includeLocalVideos: options.includeLocalVideos,
1178 nsfw: options.nsfw, 1197 nsfw: options.nsfw,
1198 isLive: options.isLive,
1199
1179 categoryOneOf: options.categoryOneOf, 1200 categoryOneOf: options.categoryOneOf,
1180 licenceOneOf: options.licenceOneOf, 1201 licenceOneOf: options.licenceOneOf,
1181 languageOneOf: options.languageOneOf, 1202 languageOneOf: options.languageOneOf,
1203
1182 tagsOneOf: options.tagsOneOf, 1204 tagsOneOf: options.tagsOneOf,
1183 tagsAllOf: options.tagsAllOf, 1205 tagsAllOf: options.tagsAllOf,
1206
1184 user: options.user, 1207 user: options.user,
1185 filter: options.filter, 1208 filter: options.filter,
1209
1186 start: options.start, 1210 start: options.start,
1187 count: options.count, 1211 count: options.count,
1188 sort: options.sort, 1212 sort: options.sort,
1213
1189 startDate: options.startDate, 1214 startDate: options.startDate,
1190 endDate: options.endDate, 1215 endDate: options.endDate,
1216
1191 originallyPublishedStartDate: options.originallyPublishedStartDate, 1217 originallyPublishedStartDate: options.originallyPublishedStartDate,
1192 originallyPublishedEndDate: options.originallyPublishedEndDate, 1218 originallyPublishedEndDate: options.originallyPublishedEndDate,
1193 1219