aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-26 16:26:27 +0100
committerChocobozzz <me@florianbigard.com>2021-03-03 10:08:08 +0100
commit74d249bc1346c7cfaac7ee49bebbebcf2a01f82a (patch)
treed47bd163ae57ed8f15b445296634cc04f4f67b6f /server/models/video/video.ts
parent095e2258043fcff8a79ab082d11edfbd8f13a8e2 (diff)
downloadPeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.gz
PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.zst
PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.zip
Add ability to cleanup remote AP interactions
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 8894843e0..b4c7da655 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -34,7 +34,7 @@ import { ModelCache } from '@server/models/model-cache'
34import { VideoFile } from '@shared/models/videos/video-file.model' 34import { VideoFile } from '@shared/models/videos/video-file.model'
35import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' 35import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared'
36import { VideoObject } from '../../../shared/models/activitypub/objects' 36import { VideoObject } from '../../../shared/models/activitypub/objects'
37import { Video, VideoDetails } from '../../../shared/models/videos' 37import { Video, VideoDetails, VideoRateType } from '../../../shared/models/videos'
38import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 38import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
39import { VideoFilter } from '../../../shared/models/videos/video-query.type' 39import { VideoFilter } from '../../../shared/models/videos/video-query.type'
40import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' 40import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
@@ -1509,6 +1509,24 @@ export class VideoModel extends Model {
1509 }) 1509 })
1510 } 1510 }
1511 1511
1512 static updateRatesOf (videoId: number, type: VideoRateType, t: Transaction) {
1513 const field = type === 'like'
1514 ? 'likes'
1515 : 'dislikes'
1516
1517 const rawQuery = `UPDATE "video" SET "${field}" = ` +
1518 '(' +
1519 'SELECT COUNT(id) FROM "accountVideoRate" WHERE "accountVideoRate"."videoId" = "video"."id" AND type = :rateType' +
1520 ') ' +
1521 'WHERE "video"."id" = :videoId'
1522
1523 return AccountVideoRateModel.sequelize.query(rawQuery, {
1524 transaction: t,
1525 replacements: { videoId, rateType: type },
1526 type: QueryTypes.UPDATE
1527 })
1528 }
1529
1512 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) { 1530 static checkVideoHasInstanceFollow (videoId: number, followerActorId: number) {
1513 // Instances only share videos 1531 // Instances only share videos
1514 const query = 'SELECT 1 FROM "videoShare" ' + 1532 const query = 'SELECT 1 FROM "videoShare" ' +