]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video.ts
Add search bars for a user's videos and playlist library
[github/Chocobozzz/PeerTube.git] / server / models / video / video.ts
index e58146ccf5821bc4eb39a62ef7e1c4a4ddfd0867..1f3c25ecbc88966404e150b39243119d6a394e6c 100644 (file)
@@ -316,7 +316,7 @@ export type AvailableForListIDsOptions = {
     return query
   },
   [ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => {
-    const whereAnd = options.baseWhere ? options.baseWhere : []
+    const whereAnd = options.baseWhere ? [].concat(options.baseWhere) : []
 
     const query: FindOptions = {
       raw: true,
@@ -1196,9 +1196,15 @@ export class VideoModel extends Model<VideoModel> {
     })
   }
 
-  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<VideoModel> {
           }
         ]
       }
+
+      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
@@ -1371,7 +1389,7 @@ export class VideoModel extends Model<VideoModel> {
             'UNION ALL ' +
             'SELECT "video"."id" FROM "video" LEFT JOIN "videoTag" ON "videoTag"."videoId" = "video"."id" ' +
             'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
-            'WHERE "tag"."name" = ' + escapedSearch +
+            'WHERE lower("tag"."name") = lower(' + escapedSearch + ')' +
             ')'
           )
         }