diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-comment.ts | 14 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 13 | ||||
-rw-r--r-- | server/models/video/video.ts | 20 |
3 files changed, 44 insertions, 3 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index dc7556d44..151c2bc81 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { uniq } from 'lodash' | 1 | import { uniq } from 'lodash' |
2 | import { FindAndCountOptions, FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' | 2 | import { FindAndCountOptions, FindOptions, Op, Order, QueryTypes, ScopeOptions, Sequelize, Transaction, WhereOptions } from 'sequelize' |
3 | import { | 3 | import { |
4 | AllowNull, | 4 | AllowNull, |
5 | BelongsTo, | 5 | BelongsTo, |
@@ -696,6 +696,18 @@ export class VideoCommentModel extends Model { | |||
696 | } | 696 | } |
697 | } | 697 | } |
698 | 698 | ||
699 | static listRemoteCommentUrlsOfLocalVideos () { | ||
700 | const query = `SELECT "videoComment".url FROM "videoComment" ` + | ||
701 | `INNER JOIN account ON account.id = "videoComment"."accountId" ` + | ||
702 | `INNER JOIN actor ON actor.id = "account"."actorId" AND actor."serverId" IS NOT NULL ` + | ||
703 | `INNER JOIN video ON video.id = "videoComment"."videoId" AND video.remote IS FALSE` | ||
704 | |||
705 | return VideoCommentModel.sequelize.query<{ url: string }>(query, { | ||
706 | type: QueryTypes.SELECT, | ||
707 | raw: true | ||
708 | }).then(rows => rows.map(r => r.url)) | ||
709 | } | ||
710 | |||
699 | static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) { | 711 | static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) { |
700 | const query = { | 712 | const query = { |
701 | where: { | 713 | where: { |
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index b7f5f3fa3..5059c1fa6 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { literal, Op, Transaction } from 'sequelize' | 1 | import { literal, Op, QueryTypes, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
@@ -185,6 +185,17 @@ export class VideoShareModel extends Model { | |||
185 | return VideoShareModel.findAndCountAll(query) | 185 | return VideoShareModel.findAndCountAll(query) |
186 | } | 186 | } |
187 | 187 | ||
188 | static listRemoteShareUrlsOfLocalVideos () { | ||
189 | const query = `SELECT "videoShare".url FROM "videoShare" ` + | ||
190 | `INNER JOIN actor ON actor.id = "videoShare"."actorId" AND actor."serverId" IS NOT NULL ` + | ||
191 | `INNER JOIN video ON video.id = "videoShare"."videoId" AND video.remote IS FALSE` | ||
192 | |||
193 | return VideoShareModel.sequelize.query<{ url: string }>(query, { | ||
194 | type: QueryTypes.SELECT, | ||
195 | raw: true | ||
196 | }).then(rows => rows.map(r => r.url)) | ||
197 | } | ||
198 | |||
188 | static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) { | 199 | static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) { |
189 | const query = { | 200 | const query = { |
190 | where: { | 201 | where: { |
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' | |||
34 | import { VideoFile } from '@shared/models/videos/video-file.model' | 34 | import { VideoFile } from '@shared/models/videos/video-file.model' |
35 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 35 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' |
36 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 36 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
37 | import { Video, VideoDetails } from '../../../shared/models/videos' | 37 | import { Video, VideoDetails, VideoRateType } from '../../../shared/models/videos' |
38 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 38 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
39 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' | 39 | import { VideoFilter } from '../../../shared/models/videos/video-query.type' |
40 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 40 | import { 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" ' + |