]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/video-share.ts
Add ability to filter my videos by live
[github/Chocobozzz/PeerTube.git] / server / models / video / video-share.ts
index b7f5f3fa3c54fa4da41bef2a0bd035a1b7cfdaf3..5059c1fa69cb55893117b7f1b89075d0771b1d7b 100644 (file)
@@ -1,4 +1,4 @@
-import { literal, Op, Transaction } from 'sequelize'
+import { literal, Op, QueryTypes, Transaction } from 'sequelize'
 import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
@@ -185,6 +185,17 @@ export class VideoShareModel extends Model {
     return VideoShareModel.findAndCountAll(query)
   }
 
+  static listRemoteShareUrlsOfLocalVideos () {
+    const query = `SELECT "videoShare".url FROM "videoShare" ` +
+      `INNER JOIN actor ON actor.id = "videoShare"."actorId" AND actor."serverId" IS NOT NULL ` +
+      `INNER JOIN video ON video.id = "videoShare"."videoId" AND video.remote IS FALSE`
+
+    return VideoShareModel.sequelize.query<{ url: string }>(query, {
+      type: QueryTypes.SELECT,
+      raw: true
+    }).then(rows => rows.map(r => r.url))
+  }
+
   static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) {
     const query = {
       where: {