From e2600d8b261994abbbeb1ff921edaefd267fc122 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Aug 2019 15:04:36 +0200 Subject: Add avatar to prune script --- server/models/video/thumbnail.ts | 10 ++++++++++ server/models/video/video.ts | 23 +++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'server/models') diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index cf2040cbf..f1952dcc1 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts @@ -100,6 +100,16 @@ export class ThumbnailModel extends Model { .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err)) } + static loadByName (filename: string) { + const query = { + where: { + filename + } + } + + return ThumbnailModel.findOne(query) + } + static generateDefaultPreviewName (videoUUID: string) { return videoUUID + '.jpg' } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1321337ff..b59df397d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -119,6 +119,7 @@ import { CONFIG } from '../../initializers/config' import { ThumbnailModel } from './thumbnail' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { createTorrentPromise } from '../../helpers/webtorrent' +import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ @@ -1422,15 +1423,23 @@ export class VideoModel extends Model { return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) } - static loadWithFiles (id: number, t?: Transaction, logging?: boolean) { + static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean) { + const where = buildWhereIdOrUUID(id) + + const query = { + where, + transaction: t, + logging + } + return VideoModel.scope([ ScopeNames.WITH_FILES, ScopeNames.WITH_STREAMING_PLAYLISTS, ScopeNames.WITH_THUMBNAILS - ]).findByPk(id, { transaction: t, logging }) + ]).findOne(query) } - static loadByUUIDWithFile (uuid: string) { + static loadByUUID (uuid: string) { const options = { where: { uuid @@ -1754,7 +1763,7 @@ export class VideoModel extends Model { return maxBy(this.VideoFiles, file => file.resolution) } - getFile (resolution: VideoResolution) { + getFile (resolution: number) { if (Array.isArray(this.VideoFiles) === false) return undefined return this.VideoFiles.find(f => f.resolution === resolution) @@ -1893,6 +1902,12 @@ export class VideoModel extends Model { return `/api/${API_VERSION}/videos/${this.uuid}/description` } + getHLSPlaylist () { + if (!this.VideoStreamingPlaylists) return undefined + + return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) + } + removeFile (videoFile: VideoFileModel, isRedundancy = false) { const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR -- cgit v1.2.3