diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-01 16:54:24 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-01 16:54:24 +0200 |
commit | 65af03a241aa83ab7ba71278b6c99acd26428b8a (patch) | |
tree | 0cc04c31cdf631d11a915ae40389e8fa141f136b /server/models/video | |
parent | a21e25ff641854c8b01664cb18655aa420620af6 (diff) | |
download | PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.tar.gz PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.tar.zst PeerTube-65af03a241aa83ab7ba71278b6c99acd26428b8a.zip |
Automatically update playlist thumbnails
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/thumbnail.ts | 6 | ||||
-rw-r--r-- | server/models/video/video-playlist-element.ts | 18 | ||||
-rw-r--r-- | server/models/video/video-playlist.ts | 5 |
3 files changed, 27 insertions, 2 deletions
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 8faf0adba..b767a6874 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -44,6 +44,10 @@ export class ThumbnailModel extends Model<ThumbnailModel> { | |||
44 | @Column | 44 | @Column |
45 | fileUrl: string | 45 | fileUrl: string |
46 | 46 | ||
47 | @AllowNull(true) | ||
48 | @Column | ||
49 | automaticallyGenerated: boolean | ||
50 | |||
47 | @ForeignKey(() => VideoModel) | 51 | @ForeignKey(() => VideoModel) |
48 | @Column | 52 | @Column |
49 | videoId: number | 53 | videoId: number |
@@ -88,7 +92,7 @@ export class ThumbnailModel extends Model<ThumbnailModel> { | |||
88 | } | 92 | } |
89 | 93 | ||
90 | @AfterDestroy | 94 | @AfterDestroy |
91 | static removeFilesAndSendDelete (instance: ThumbnailModel) { | 95 | static removeFiles (instance: ThumbnailModel) { |
92 | logger.info('Removing %s file %s.', ThumbnailModel.types[instance.type].label, instance.filename) | 96 | logger.info('Removing %s file %s.', ThumbnailModel.types[instance.type].label, instance.filename) |
93 | 97 | ||
94 | // Don't block the transaction | 98 | // Don't block the transaction |
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index bed6f8eaf..dd7653533 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -218,6 +218,24 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel> | |||
218 | }) | 218 | }) |
219 | } | 219 | } |
220 | 220 | ||
221 | static loadFirstElementWithVideoThumbnail (videoPlaylistId: number) { | ||
222 | const query = { | ||
223 | order: getSort('position'), | ||
224 | where: { | ||
225 | videoPlaylistId | ||
226 | }, | ||
227 | include: [ | ||
228 | { | ||
229 | model: VideoModel.scope(VideoScopeNames.WITH_THUMBNAILS), | ||
230 | required: true | ||
231 | } | ||
232 | ] | ||
233 | } | ||
234 | |||
235 | return VideoPlaylistElementModel | ||
236 | .findOne(query) | ||
237 | } | ||
238 | |||
221 | static getNextPositionOf (videoPlaylistId: number, transaction?: Transaction) { | 239 | static getNextPositionOf (videoPlaylistId: number, transaction?: Transaction) { |
222 | const query: AggregateOptions<number> = { | 240 | const query: AggregateOptions<number> = { |
223 | where: { | 241 | where: { |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 61ff78bd2..c8e97c491 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -265,7 +265,6 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
265 | VideoPlaylistElements: VideoPlaylistElementModel[] | 265 | VideoPlaylistElements: VideoPlaylistElementModel[] |
266 | 266 | ||
267 | @HasOne(() => ThumbnailModel, { | 267 | @HasOne(() => ThumbnailModel, { |
268 | |||
269 | foreignKey: { | 268 | foreignKey: { |
270 | name: 'videoPlaylistId', | 269 | name: 'videoPlaylistId', |
271 | allowNull: true | 270 | allowNull: true |
@@ -434,6 +433,10 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> { | |||
434 | return !!this.Thumbnail | 433 | return !!this.Thumbnail |
435 | } | 434 | } |
436 | 435 | ||
436 | hasGeneratedThumbnail () { | ||
437 | return this.hasThumbnail() && this.Thumbnail.automaticallyGenerated === true | ||
438 | } | ||
439 | |||
437 | generateThumbnailName () { | 440 | generateThumbnailName () { |
438 | const extension = '.jpg' | 441 | const extension = '.jpg' |
439 | 442 | ||