MVideoFormattableDetails,
MVideoForUser,
MVideoFullLight,
- MVideoIdThumbnail,
+ MVideoIdThumbnail, MVideoImmutable,
MVideoThumbnail,
MVideoThumbnailBlacklist,
MVideoWithAllFiles,
import { VideoFile } from '@shared/models/videos/video-file.model'
import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths'
import validator from 'validator'
+import { ModelCache } from '@server/models/model-cache'
export enum ScopeNames {
AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS',
WITH_USER_HISTORY = 'WITH_USER_HISTORY',
WITH_STREAMING_PLAYLISTS = 'WITH_STREAMING_PLAYLISTS',
WITH_USER_ID = 'WITH_USER_ID',
+ WITH_IMMUTABLE_ATTRIBUTES = 'WITH_IMMUTABLE_ATTRIBUTES',
WITH_THUMBNAILS = 'WITH_THUMBNAILS'
}
}
@Scopes(() => ({
+ [ScopeNames.WITH_IMMUTABLE_ATTRIBUTES]: {
+ attributes: [ 'id', 'url', 'uuid', 'remote' ]
+ },
[ScopeNames.FOR_API]: (options: ForAPIOptions) => {
const query: FindOptions = {
include: [
return undefined
}
+ @BeforeDestroy
+ static invalidateCache (instance: VideoModel) {
+ ModelCache.Instance.invalidateCache('video', instance.id)
+ }
+
static listLocal (): Bluebird<MVideoWithAllFiles[]> {
const query = {
where: {
]).findOne(options)
}
+ static loadImmutableAttributes (id: number | string, t?: Transaction): Bluebird<MVideoImmutable> {
+ const fun = () => {
+ const query = {
+ where: buildWhereIdOrUUID(id),
+ transaction: t
+ }
+
+ return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query)
+ }
+
+ return ModelCache.Instance.doCache({
+ cacheType: 'load-video-immutable-id',
+ key: '' + id,
+ deleteKey: 'video',
+ fun
+ })
+ }
+
static loadWithRights (id: number | string, t?: Transaction): Bluebird<MVideoWithRights> {
const where = buildWhereIdOrUUID(id)
const options = {
return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(query)
}
+ static loadByUrlImmutableAttributes (url: string, transaction?: Transaction): Bluebird<MVideoImmutable> {
+ const fun = () => {
+ const query: FindOptions = {
+ where: {
+ url
+ },
+ transaction
+ }
+
+ return VideoModel.scope(ScopeNames.WITH_IMMUTABLE_ATTRIBUTES).findOne(query)
+ }
+
+ return ModelCache.Instance.doCache({
+ cacheType: 'load-video-immutable-url',
+ key: url,
+ deleteKey: 'video',
+ fun
+ })
+ }
+
static loadByUrlAndPopulateAccount (url: string, transaction?: Transaction): Bluebird<MVideoAccountLightBlacklistAllFiles> {
const query: FindOptions = {
where: {