diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-10 11:09:30 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-10 11:56:08 +0100 |
commit | 8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa (patch) | |
tree | 4e7d3711cccb095d4356c59554bdfd4e16502832 /server/models/video/video-file.ts | |
parent | a8749f7c3b137f433e6944bb99fd721a6f0cfc1e (diff) | |
download | PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.tar.gz PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.tar.zst PeerTube-8c4bbd946d2247c2e239cbbf8773d2d31c1a57aa.zip |
Refactor model utils
Diffstat (limited to 'server/models/video/video-file.ts')
-rw-r--r-- | server/models/video/video-file.ts | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 9b42955ef..07bc13de1 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -21,6 +21,7 @@ import { | |||
21 | import validator from 'validator' | 21 | import validator from 'validator' |
22 | import { logger } from '@server/helpers/logger' | 22 | import { logger } from '@server/helpers/logger' |
23 | import { extractVideo } from '@server/helpers/video' | 23 | import { extractVideo } from '@server/helpers/video' |
24 | import { CONFIG } from '@server/initializers/config' | ||
24 | import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url' | 25 | import { buildRemoteVideoBaseUrl } from '@server/lib/activitypub/url' |
25 | import { | 26 | import { |
26 | getHLSPrivateFileUrl, | 27 | getHLSPrivateFileUrl, |
@@ -50,11 +51,9 @@ import { | |||
50 | } from '../../initializers/constants' | 51 | } from '../../initializers/constants' |
51 | import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../types/models/video/video-file' | 52 | import { MVideoFile, MVideoFileStreamingPlaylistVideo, MVideoFileVideo } from '../../types/models/video/video-file' |
52 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 53 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
53 | import { doesExist } from '../shared' | 54 | import { doesExist, parseAggregateResult, throwIfNotValid } from '../shared' |
54 | import { parseAggregateResult, throwIfNotValid } from '../utils' | ||
55 | import { VideoModel } from './video' | 55 | import { VideoModel } from './video' |
56 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 56 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
57 | import { CONFIG } from '@server/initializers/config' | ||
58 | 57 | ||
59 | export enum ScopeNames { | 58 | export enum ScopeNames { |
60 | WITH_VIDEO = 'WITH_VIDEO', | 59 | WITH_VIDEO = 'WITH_VIDEO', |
@@ -266,7 +265,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
266 | static doesInfohashExist (infoHash: string) { | 265 | static doesInfohashExist (infoHash: string) { |
267 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' | 266 | const query = 'SELECT 1 FROM "videoFile" WHERE "infoHash" = $infoHash LIMIT 1' |
268 | 267 | ||
269 | return doesExist(query, { infoHash }) | 268 | return doesExist(this.sequelize, query, { infoHash }) |
270 | } | 269 | } |
271 | 270 | ||
272 | static async doesVideoExistForVideoFile (id: number, videoIdOrUUID: number | string) { | 271 | static async doesVideoExistForVideoFile (id: number, videoIdOrUUID: number | string) { |
@@ -282,14 +281,14 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
282 | 'LEFT JOIN "video" "hlsVideo" ON "hlsVideo"."id" = "videoStreamingPlaylist"."videoId" AND "hlsVideo"."remote" IS FALSE ' + | 281 | 'LEFT JOIN "video" "hlsVideo" ON "hlsVideo"."id" = "videoStreamingPlaylist"."videoId" AND "hlsVideo"."remote" IS FALSE ' + |
283 | 'WHERE "torrentFilename" = $filename AND ("hlsVideo"."id" IS NOT NULL OR "webtorrent"."id" IS NOT NULL) LIMIT 1' | 282 | 'WHERE "torrentFilename" = $filename AND ("hlsVideo"."id" IS NOT NULL OR "webtorrent"."id" IS NOT NULL) LIMIT 1' |
284 | 283 | ||
285 | return doesExist(query, { filename }) | 284 | return doesExist(this.sequelize, query, { filename }) |
286 | } | 285 | } |
287 | 286 | ||
288 | static async doesOwnedWebTorrentVideoFileExist (filename: string) { | 287 | static async doesOwnedWebTorrentVideoFileExist (filename: string) { |
289 | const query = 'SELECT 1 FROM "videoFile" INNER JOIN "video" ON "video"."id" = "videoFile"."videoId" AND "video"."remote" IS FALSE ' + | 288 | const query = 'SELECT 1 FROM "videoFile" INNER JOIN "video" ON "video"."id" = "videoFile"."videoId" AND "video"."remote" IS FALSE ' + |
290 | `WHERE "filename" = $filename AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` | 289 | `WHERE "filename" = $filename AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` |
291 | 290 | ||
292 | return doesExist(query, { filename }) | 291 | return doesExist(this.sequelize, query, { filename }) |
293 | } | 292 | } |
294 | 293 | ||
295 | static loadByFilename (filename: string) { | 294 | static loadByFilename (filename: string) { |