aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/thumbnail.ts10
-rw-r--r--server/models/video/video.ts23
2 files changed, 29 insertions, 4 deletions
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<ThumbnailModel> {
100 .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err)) 100 .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err))
101 } 101 }
102 102
103 static loadByName (filename: string) {
104 const query = {
105 where: {
106 filename
107 }
108 }
109
110 return ThumbnailModel.findOne(query)
111 }
112
103 static generateDefaultPreviewName (videoUUID: string) { 113 static generateDefaultPreviewName (videoUUID: string) {
104 return videoUUID + '.jpg' 114 return videoUUID + '.jpg'
105 } 115 }
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'
119import { ThumbnailModel } from './thumbnail' 119import { ThumbnailModel } from './thumbnail'
120import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 120import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
121import { createTorrentPromise } from '../../helpers/webtorrent' 121import { createTorrentPromise } from '../../helpers/webtorrent'
122import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type'
122 123
123// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 124// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
124const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ 125const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [
@@ -1422,15 +1423,23 @@ export class VideoModel extends Model<VideoModel> {
1422 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options) 1423 return VideoModel.scope(ScopeNames.WITH_THUMBNAILS).findOne(options)
1423 } 1424 }
1424 1425
1425 static loadWithFiles (id: number, t?: Transaction, logging?: boolean) { 1426 static loadWithFiles (id: number | string, t?: Transaction, logging?: boolean) {
1427 const where = buildWhereIdOrUUID(id)
1428
1429 const query = {
1430 where,
1431 transaction: t,
1432 logging
1433 }
1434
1426 return VideoModel.scope([ 1435 return VideoModel.scope([
1427 ScopeNames.WITH_FILES, 1436 ScopeNames.WITH_FILES,
1428 ScopeNames.WITH_STREAMING_PLAYLISTS, 1437 ScopeNames.WITH_STREAMING_PLAYLISTS,
1429 ScopeNames.WITH_THUMBNAILS 1438 ScopeNames.WITH_THUMBNAILS
1430 ]).findByPk(id, { transaction: t, logging }) 1439 ]).findOne(query)
1431 } 1440 }
1432 1441
1433 static loadByUUIDWithFile (uuid: string) { 1442 static loadByUUID (uuid: string) {
1434 const options = { 1443 const options = {
1435 where: { 1444 where: {
1436 uuid 1445 uuid
@@ -1754,7 +1763,7 @@ export class VideoModel extends Model<VideoModel> {
1754 return maxBy(this.VideoFiles, file => file.resolution) 1763 return maxBy(this.VideoFiles, file => file.resolution)
1755 } 1764 }
1756 1765
1757 getFile (resolution: VideoResolution) { 1766 getFile (resolution: number) {
1758 if (Array.isArray(this.VideoFiles) === false) return undefined 1767 if (Array.isArray(this.VideoFiles) === false) return undefined
1759 1768
1760 return this.VideoFiles.find(f => f.resolution === resolution) 1769 return this.VideoFiles.find(f => f.resolution === resolution)
@@ -1893,6 +1902,12 @@ export class VideoModel extends Model<VideoModel> {
1893 return `/api/${API_VERSION}/videos/${this.uuid}/description` 1902 return `/api/${API_VERSION}/videos/${this.uuid}/description`
1894 } 1903 }
1895 1904
1905 getHLSPlaylist () {
1906 if (!this.VideoStreamingPlaylists) return undefined
1907
1908 return this.VideoStreamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
1909 }
1910
1896 removeFile (videoFile: VideoFileModel, isRedundancy = false) { 1911 removeFile (videoFile: VideoFileModel, isRedundancy = false) {
1897 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR 1912 const baseDir = isRedundancy ? CONFIG.STORAGE.REDUNDANCY_DIR : CONFIG.STORAGE.VIDEOS_DIR
1898 1913