From bf64ed4196938ba9002c887cadb01bd2a6e3127a Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sat, 28 Dec 2019 01:10:26 +0100 Subject: Add search bars for a user's videos and playlist library --- server/controllers/api/users/me.ts | 3 ++- server/models/video/video.ts | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'server') 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) { user.Account.id, req.query.start as number, req.query.count as number, - req.query.sort as VideoSortField + req.query.sort as VideoSortField, + req.query.search as string ) 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 { }) } - static listUserVideosForApi (accountId: number, start: number, count: number, sort: string) { + static listUserVideosForApi ( + accountId: number, + start: number, + count: number, + sort: string, + search?: string + ) { function buildBaseQuery (): FindOptions { - return { + let baseQuery = { offset: start, limit: count, order: getVideoSort(sort), @@ -1218,12 +1224,24 @@ export class VideoModel extends Model { } ] } + + if (search) { + baseQuery = Object.assign(baseQuery, { + where: { + name: { + [ Op.iLike ]: '%' + search + '%' + } + } + }) + } + + return baseQuery } const countQuery = buildBaseQuery() const findQuery = buildBaseQuery() - const findScopes = [ + const findScopes: (string | ScopeOptions)[] = [ ScopeNames.WITH_SCHEDULED_UPDATE, ScopeNames.WITH_BLACKLISTED, ScopeNames.WITH_THUMBNAILS -- cgit v1.2.3