aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-11-16 15:02:48 +0100
committerChocobozzz <me@florianbigard.com>2018-11-16 15:49:16 +0100
commit8d4273463fb19d503b1aa0a32dc289f292ed614e (patch)
treef422773ecba3405bb5808bed8e25b62ac6b7ea08 /server/models/video
parent5776f78e3b3f3a371ec30c7fcb11e7ca17f2f65e (diff)
downloadPeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.tar.gz
PeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.tar.zst
PeerTube-8d4273463fb19d503b1aa0a32dc289f292ed614e.zip
Check follow constraints when getting a video
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 6c183933b..1e68b380c 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1253,6 +1253,23 @@ export class VideoModel extends Model<VideoModel> {
1253 }) 1253 })
1254 } 1254 }
1255 1255
1256 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) {
1257 // Instances only share videos
1258 const query = 'SELECT 1 FROM "videoShare" ' +
1259 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
1260 'WHERE "actorFollow"."actorId" = $followerActorId AND "videoShare"."videoId" = $videoId ' +
1261 'LIMIT 1'
1262
1263 const options = {
1264 type: Sequelize.QueryTypes.SELECT,
1265 bind: { followerActorId, videoId },
1266 raw: true
1267 }
1268
1269 return VideoModel.sequelize.query(query, options)
1270 .then(results => results.length === 1)
1271 }
1272
1256 // threshold corresponds to how many video the field should have to be returned 1273 // threshold corresponds to how many video the field should have to be returned
1257 static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { 1274 static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) {
1258 const serverActor = await getServerActor() 1275 const serverActor = await getServerActor()