diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video.ts | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1ec8d717e..5964526a9 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' | |||
132 | import { VideoFile } from '@shared/models/videos/video-file.model' | 132 | import { VideoFile } from '@shared/models/videos/video-file.model' |
133 | import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' | 133 | import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
134 | import validator from 'validator' | 134 | import validator from 'validator' |
135 | import { ModelCache } from '@server/models/model-cache' | ||
135 | 136 | ||
136 | export enum ScopeNames { | 137 | export enum ScopeNames { |
137 | AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', | 138 | AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', |
@@ -144,6 +145,7 @@ export enum ScopeNames { | |||
144 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', | 145 | WITH_USER_HISTORY = 'WITH_USER_HISTORY', |
145 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', | 146 | WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS', |
146 | WITH_USER_ID = 'WITH_USER_ID', | 147 | WITH_USER_ID = 'WITH_USER_ID', |
148 | WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES', | ||
147 | WITH_THUMBNAILS = 'WITH_THUMBNAILS' | 149 | WITH_THUMBNAILS = 'WITH_THUMBNAILS' |
148 | } | 150 | } |
149 | 151 | ||
@@ -187,6 +189,9 @@ export type AvailableForListIDsOptions = { | |||
187 | } | 189 | } |
188 | 190 | ||
189 | @Scopes(() => ({ | 191 | @Scopes(() => ({ |
192 | [ScopeNames.WITH_IMMUTABLE_ATTRIBUTES]: { | ||
193 | attributes: [ 'id', 'url', 'uuid', 'remote' ] | ||
194 | }, | ||
190 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { | 195 | [ScopeNames.FOR_API]: (options: ForAPIOptions) => { |
191 | const query: FindOptions = { | 196 | const query: FindOptions = { |
192 | include: [ | 197 | include: [ |
@@ -1074,6 +1079,11 @@ export class VideoModel extends Model<VideoModel> { | |||
1074 | return undefined | 1079 | return undefined |
1075 | } | 1080 | } |
1076 | 1081 | ||
1082 | @BeforeDestroy | ||
1083 | static invalidateCache (instance: VideoModel) { | ||
1084 | ModelCache.Instance.invalidateCache('video', instance.id) | ||
1085 | } | ||
1086 | |||
1077 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { | 1087 | static listLocal (): Bluebird<MVideoWithAllFiles[]> { |
1078 | const query = { | 1088 | const query = { |
1079 | where: { | 1089 | where: { |
@@ -1468,6 +1478,24 @@ export class VideoModel extends Model<VideoModel> { | |||
1468 | ]).findOne(options) | 1478 | ]).findOne(options) |
1469 | } | 1479 | } |
1470 | 1480 | ||
1481 | static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> { | ||
1482 | const fun = () => { | ||
1483 | const query = { | ||
1484 | where: buildWhereIdOrUUID(id), | ||
1485 | transaction: t | ||
1486 | } | ||
1487 | |||
1488 | return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) | ||
1489 | } | ||
1490 | |||
1491 | return ModelCache.Instance.doCache({ | ||
1492 | cacheType: 'load-video-immutable-id', | ||
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 = { |
@@ -1531,6 +1559,26 @@ export class VideoModel extends Model<VideoModel> { | |||
1531 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) | 1559 | return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query) |
1532 | } | 1560 | } |
1533 | 1561 | ||
1562 | static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> { | ||
1563 | const fun = () => { | ||
1564 | const query: FindOptions = { | ||
1565 | where: { | ||
1566 | url | ||
1567 | }, | ||
1568 | transaction | ||
1569 | } | ||
1570 | |||
1571 | return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query) | ||
1572 | } | ||
1573 | |||
1574 | return ModelCache.Instance.doCache({ | ||
1575 | cacheType: 'load-video-immutable-url', | ||
1576 | key: url, | ||
1577 | deleteKey: 'video', | ||
1578 | fun | ||
1579 | }) | ||
1580 | } | ||
1581 | |||
1534 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { | 1582 | static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> { |
1535 | const query: FindOptions = { | 1583 | const query: FindOptions = { |
1536 | where: { | 1584 | where: { |