diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-09 15:04:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-09 15:04:36 +0200 |
commit | e2600d8b261994abbbeb1ff921edaefd267fc122 (patch) | |
tree | fb19495cb4ba502324a2318c83cd4936b956fc1c /server/models | |
parent | 5bb2eb5660c87700bc70fe82219c1a84e7c7b177 (diff) | |
download | PeerTube-e2600d8b261994abbbeb1ff921edaefd267fc122.tar.gz PeerTube-e2600d8b261994abbbeb1ff921edaefd267fc122.tar.zst PeerTube-e2600d8b261994abbbeb1ff921edaefd267fc122.zip |
Add avatar to prune script
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/thumbnail.ts | 10 | ||||
-rw-r--r-- | server/models/video/video.ts | 23 |
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' | |||
119 | import { ThumbnailModel } from './thumbnail' | 119 | import { ThumbnailModel } from './thumbnail' |
120 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 120 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
121 | import { createTorrentPromise } from '../../helpers/webtorrent' | 121 | import { createTorrentPromise } from '../../helpers/webtorrent' |
122 | import { 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 |
124 | const indexes: (ModelIndexesOptions & { where?: WhereOptions })[] = [ | 125 | const 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 | ||