diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-17 10:07:00 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:25:52 +0200 |
commit | e8bafea35bc930cb8ac5b2d521a188642a1adffe (patch) | |
tree | 7537f957ed7307b464e3c90b71b813d992acaade /server/lib/activitypub/playlist.ts | |
parent | 94565d52bb2883e09f16d1363170ac9c0dccb7a1 (diff) | |
download | PeerTube-e8bafea35bc930cb8ac5b2d521a188642a1adffe.tar.gz PeerTube-e8bafea35bc930cb8ac5b2d521a188642a1adffe.tar.zst PeerTube-e8bafea35bc930cb8ac5b2d521a188642a1adffe.zip |
Create a dedicated table to track video thumbnails
Diffstat (limited to 'server/lib/activitypub/playlist.ts')
-rw-r--r-- | server/lib/activitypub/playlist.ts | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index f312409bc..341e469f3 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' | 1 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' |
2 | import { crawlCollectionPage } from './crawl' | 2 | import { crawlCollectionPage } from './crawl' |
3 | import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY, THUMBNAILS_SIZE } from '../../initializers/constants' | 3 | import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' |
4 | import { AccountModel } from '../../models/account/account' | 4 | import { AccountModel } from '../../models/account/account' |
5 | import { isArray } from '../../helpers/custom-validators/misc' | 5 | import { isArray } from '../../helpers/custom-validators/misc' |
6 | import { getOrCreateActorAndServerAndModel } from './actor' | 6 | import { getOrCreateActorAndServerAndModel } from './actor' |
7 | import { logger } from '../../helpers/logger' | 7 | import { logger } from '../../helpers/logger' |
8 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 8 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
9 | import { doRequest, downloadImage } from '../../helpers/requests' | 9 | import { doRequest } from '../../helpers/requests' |
10 | import { checkUrlsSameHost } from '../../helpers/activitypub' | 10 | import { checkUrlsSameHost } from '../../helpers/activitypub' |
11 | import * as Bluebird from 'bluebird' | 11 | import * as Bluebird from 'bluebird' |
12 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' | 12 | import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' |
@@ -16,9 +16,8 @@ import { VideoPlaylistElementModel } from '../../models/video/video-playlist-ele | |||
16 | import { VideoModel } from '../../models/video/video' | 16 | import { VideoModel } from '../../models/video/video' |
17 | import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' | 17 | import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' |
18 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 18 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
19 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | ||
20 | import { CONFIG } from '../../initializers/config' | ||
21 | import { sequelizeTypescript } from '../../initializers/database' | 19 | import { sequelizeTypescript } from '../../initializers/database' |
20 | import { createPlaylistThumbnailFromUrl } from '../thumbnail' | ||
22 | 21 | ||
23 | function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { | 22 | function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { |
24 | const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED | 23 | const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED |
@@ -97,16 +96,20 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc | |||
97 | return Promise.resolve() | 96 | return Promise.resolve() |
98 | }) | 97 | }) |
99 | 98 | ||
100 | // Empty playlists generally do not have a miniature, so skip this | 99 | const refreshedPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(playlist.id, null) |
101 | if (accItems.length !== 0) { | 100 | |
101 | if (playlistObject.icon) { | ||
102 | try { | 102 | try { |
103 | await generateThumbnailFromUrl(playlist, playlistObject.icon) | 103 | const thumbnailModel = await createPlaylistThumbnailFromUrl(playlistObject.icon.url, refreshedPlaylist) |
104 | thumbnailModel.videoPlaylistId = refreshedPlaylist.id | ||
105 | |||
106 | refreshedPlaylist.setThumbnail(await thumbnailModel.save()) | ||
104 | } catch (err) { | 107 | } catch (err) { |
105 | logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) | 108 | logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) |
106 | } | 109 | } |
107 | } | 110 | } |
108 | 111 | ||
109 | return resetVideoPlaylistElements(accItems, playlist) | 112 | return resetVideoPlaylistElements(accItems, refreshedPlaylist) |
110 | } | 113 | } |
111 | 114 | ||
112 | async function refreshVideoPlaylistIfNeeded (videoPlaylist: VideoPlaylistModel): Promise<VideoPlaylistModel> { | 115 | async function refreshVideoPlaylistIfNeeded (videoPlaylist: VideoPlaylistModel): Promise<VideoPlaylistModel> { |
@@ -191,12 +194,6 @@ async function resetVideoPlaylistElements (elementUrls: string[], playlist: Vide | |||
191 | return undefined | 194 | return undefined |
192 | } | 195 | } |
193 | 196 | ||
194 | function generateThumbnailFromUrl (playlist: VideoPlaylistModel, icon: ActivityIconObject) { | ||
195 | const thumbnailName = playlist.getThumbnailName() | ||
196 | |||
197 | return downloadImage(icon.url, CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName, THUMBNAILS_SIZE) | ||
198 | } | ||
199 | |||
200 | async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> { | 197 | async function fetchRemoteVideoPlaylist (playlistUrl: string): Promise<{ statusCode: number, playlistObject: PlaylistObject }> { |
201 | const options = { | 198 | const options = { |
202 | uri: playlistUrl, | 199 | uri: playlistUrl, |