diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 16:26:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-03 10:08:08 +0100 |
commit | 74d249bc1346c7cfaac7ee49bebbebcf2a01f82a (patch) | |
tree | d47bd163ae57ed8f15b445296634cc04f4f67b6f /server/models/video/video-share.ts | |
parent | 095e2258043fcff8a79ab082d11edfbd8f13a8e2 (diff) | |
download | PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.gz PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.zst PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.zip |
Add ability to cleanup remote AP interactions
Diffstat (limited to 'server/models/video/video-share.ts')
-rw-r--r-- | server/models/video/video-share.ts | 13 |
1 files changed, 12 insertions, 1 deletions
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: { |