diff options
author | buoyantair <buoyantair@protonmail.com> | 2018-11-18 21:55:52 +0530 |
---|---|---|
committer | buoyantair <buoyantair@protonmail.com> | 2018-11-18 21:55:52 +0530 |
commit | b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13 (patch) | |
tree | dcdf451ac431ec7953bee58e814f642d1c370d1b /server/models | |
parent | 92e07c3b5d9dbf2febedb1b5b87ec676eb6d1ac8 (diff) | |
parent | 9d0b856e930ee1c676d16a56408a3e4a18f8f978 (diff) | |
download | PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.gz PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.tar.zst PeerTube-b9f234371bfaf0d9cfa81e02fcea92cac1f9ae13.zip |
Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils-to-shared
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/activitypub/actor-follow.ts | 4 | ||||
-rw-r--r-- | server/models/redundancy/video-redundancy.ts | 7 | ||||
-rw-r--r-- | server/models/video/video.ts | 17 |
3 files changed, 24 insertions, 4 deletions
diff --git a/server/models/activitypub/actor-follow.ts b/server/models/activitypub/actor-follow.ts index 3373355ef..0a6935083 100644 --- a/server/models/activitypub/actor-follow.ts +++ b/server/models/activitypub/actor-follow.ts | |||
@@ -509,12 +509,12 @@ export class ActorFollowModel extends Model<ActorFollowModel> { | |||
509 | tasks.push(ActorFollowModel.sequelize.query(query, options)) | 509 | tasks.push(ActorFollowModel.sequelize.query(query, options)) |
510 | } | 510 | } |
511 | 511 | ||
512 | const [ followers, [ { total } ] ] = await Promise.all(tasks) | 512 | const [ followers, [ dataTotal ] ] = await Promise.all(tasks) |
513 | const urls: string[] = followers.map(f => f.url) | 513 | const urls: string[] = followers.map(f => f.url) |
514 | 514 | ||
515 | return { | 515 | return { |
516 | data: urls, | 516 | data: urls, |
517 | total: parseInt(total, 10) | 517 | total: dataTotal ? parseInt(dataTotal.total, 10) : 0 |
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index 35e0cd3b1..9de4356b4 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -117,8 +117,7 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
117 | 117 | ||
118 | @BeforeDestroy | 118 | @BeforeDestroy |
119 | static async removeFile (instance: VideoRedundancyModel) { | 119 | static async removeFile (instance: VideoRedundancyModel) { |
120 | // Not us | 120 | if (!instance.isOwned()) return |
121 | if (!instance.strategy) return | ||
122 | 121 | ||
123 | const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId) | 122 | const videoFile = await VideoFileModel.loadWithVideo(instance.videoFileId) |
124 | 123 | ||
@@ -404,6 +403,10 @@ export class VideoRedundancyModel extends Model<VideoRedundancyModel> { | |||
404 | })) | 403 | })) |
405 | } | 404 | } |
406 | 405 | ||
406 | isOwned () { | ||
407 | return !!this.strategy | ||
408 | } | ||
409 | |||
407 | toActivityPubObject (): CacheFileObject { | 410 | toActivityPubObject (): CacheFileObject { |
408 | return { | 411 | return { |
409 | id: this.url, | 412 | id: this.url, |
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() |