aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2019-12-28 01:10:26 +0100
committerRigel Kent <sendmemail@rigelk.eu>2019-12-28 01:10:26 +0100
commitbf64ed4196938ba9002c887cadb01bd2a6e3127a (patch)
tree889b8f89c59cd513edd973785a76ccf6f8c23f3d /server
parent71810d0bcbed0e46ddaa1d4eadd028154786fffb (diff)
downloadPeerTube-bf64ed4196938ba9002c887cadb01bd2a6e3127a.tar.gz
PeerTube-bf64ed4196938ba9002c887cadb01bd2a6e3127a.tar.zst
PeerTube-bf64ed4196938ba9002c887cadb01bd2a6e3127a.zip
Add search bars for a user's videos and playlist library
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/me.ts3
-rw-r--r--server/models/video/video.ts24
2 files changed, 23 insertions, 4 deletions
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index ba976ab03..b1f29f252 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -99,7 +99,8 @@ async function getUserVideos (req: express.Request, res: express.Response) {
99 user.Account.id, 99 user.Account.id,
100 req.query.start as number, 100 req.query.start as number,
101 req.query.count as number, 101 req.query.count as number,
102 req.query.sort as VideoSortField 102 req.query.sort as VideoSortField,
103 req.query.search as string
103 ) 104 )
104 105
105 const additionalAttributes = { 106 const additionalAttributes = {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 164122ee2..1f3c25ecb 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1196,9 +1196,15 @@ export class VideoModel extends Model<VideoModel> {
1196 }) 1196 })
1197 } 1197 }
1198 1198
1199 static listUserVideosForApi (accountId: number, start: number, count: number, sort: string) { 1199 static listUserVideosForApi (
1200 accountId: number,
1201 start: number,
1202 count: number,
1203 sort: string,
1204 search?: string
1205 ) {
1200 function buildBaseQuery (): FindOptions { 1206 function buildBaseQuery (): FindOptions {
1201 return { 1207 let baseQuery = {
1202 offset: start, 1208 offset: start,
1203 limit: count, 1209 limit: count,
1204 order: getVideoSort(sort), 1210 order: getVideoSort(sort),
@@ -1218,12 +1224,24 @@ export class VideoModel extends Model<VideoModel> {
1218 } 1224 }
1219 ] 1225 ]
1220 } 1226 }
1227
1228 if (search) {
1229 baseQuery = Object.assign(baseQuery, {
1230 where: {
1231 name: {
1232 [ Op.iLike ]: '%' + search + '%'
1233 }
1234 }
1235 })
1236 }
1237
1238 return baseQuery
1221 } 1239 }
1222 1240
1223 const countQuery = buildBaseQuery() 1241 const countQuery = buildBaseQuery()
1224 const findQuery = buildBaseQuery() 1242 const findQuery = buildBaseQuery()
1225 1243
1226 const findScopes = [ 1244 const findScopes: (string | ScopeOptions)[] = [
1227 ScopeNames.WITH_SCHEDULED_UPDATE, 1245 ScopeNames.WITH_SCHEDULED_UPDATE,
1228 ScopeNames.WITH_BLACKLISTED, 1246 ScopeNames.WITH_BLACKLISTED,
1229 ScopeNames.WITH_THUMBNAILS 1247 ScopeNames.WITH_THUMBNAILS