aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts30
1 files changed, 29 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 1ec8d717e..9e02d163f 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -120,7 +120,7 @@ import {
120 MVideoFormattableDetails, 120 MVideoFormattableDetails,
121 MVideoForUser, 121 MVideoForUser,
122 MVideoFullLight, 122 MVideoFullLight,
123 MVideoIdThumbnail, 123 MVideoIdThumbnail, MVideoImmutable,
124 MVideoThumbnail, 124 MVideoThumbnail,
125 MVideoThumbnailBlacklist, 125 MVideoThumbnailBlacklist,
126 MVideoWithAllFiles, 126 MVideoWithAllFiles,
@@ -132,6 +132,7 @@ import { MThumbnail } from '../../typings/models/video/thumbnail'
132import { VideoFile } from '@shared/models/videos/video-file.model' 132import { VideoFile } from '@shared/models/videos/video-file.model'
133import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' 133import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
134import validator from 'validator' 134import validator from 'validator'
135import { ModelCache } from '@server/models/model-cache'
135 136
136export enum ScopeNames { 137export enum ScopeNames {
137 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', 138 AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
@@ -1074,6 +1075,11 @@ export class VideoModel extends Model<VideoModel> {
1074 return undefined 1075 return undefined
1075 } 1076 }
1076 1077
1078 @BeforeDestroy
1079 static invalidateCache (instance: VideoModel) {
1080 ModelCache.Instance.invalidateCache('video', instance.id)
1081 }
1082
1077 static listLocal (): Bluebird<MVideoWithAllFiles[]> { 1083 static listLocal (): Bluebird<MVideoWithAllFiles[]> {
1078 const query = { 1084 const query = {
1079 where: { 1085 where: {
@@ -1468,6 +1474,28 @@ export class VideoModel extends Model<VideoModel> {
1468 ]).findOne(options) 1474 ]).findOne(options)
1469 } 1475 }
1470 1476
1477 static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> {
1478 const fun = () => {
1479 const where = buildWhereIdOrUUID(id)
1480 const options = {
1481 attributes: [
1482 'id', 'url', 'uuid'
1483 ],
1484 where,
1485 transaction: t
1486 }
1487
1488 return VideoModel.unscoped().findOne(options)
1489 }
1490
1491 return ModelCache.Instance.doCache({
1492 cacheType: 'video-immutable',
1493 key: '' + id,
1494 deleteKey: 'video',
1495 fun
1496 })
1497 }
1498
1471 static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> { 1499 static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> {
1472 const where = buildWhereIdOrUUID(id) 1500 const where = buildWhereIdOrUUID(id)
1473 const options = { 1501 const options = {