diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-24 09:56:25 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:22 +0200 |
commit | 2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063 (patch) | |
tree | 3f03677870548c648070ac138a2b5ca36ee8fbeb | |
parent | b876eaf11a1ed9683664d94767ca684ba5b77753 (diff) | |
download | PeerTube-2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063.tar.gz PeerTube-2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063.tar.zst PeerTube-2fb5b3a55aeebcc77f4b3a0c029bbf0738ef0063.zip |
Relax videos list thumbnail api join
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 2 | ||||
-rw-r--r-- | server/helpers/image-utils.ts | 10 | ||||
-rw-r--r-- | server/helpers/requests.ts | 2 | ||||
-rw-r--r-- | server/lib/avatar.ts | 2 | ||||
-rw-r--r-- | server/lib/thumbnail.ts | 4 | ||||
-rw-r--r-- | server/models/video/video.ts | 7 |
6 files changed, 16 insertions, 11 deletions
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index d818c459c..76b744de8 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -105,7 +105,7 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima | |||
105 | }) | 105 | }) |
106 | 106 | ||
107 | const destination = join(folder, imageName) | 107 | const destination = join(folder, imageName) |
108 | await processImage({ path: pendingImagePath }, destination, size) | 108 | await processImage(pendingImagePath, destination, size) |
109 | } catch (err) { | 109 | } catch (err) { |
110 | logger.error('Cannot generate image from video %s.', fromPath, { err }) | 110 | logger.error('Cannot generate image from video %s.', fromPath, { err }) |
111 | 111 | ||
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index eeaef0f5d..bd81aa3ba 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -4,19 +4,19 @@ import { readFile, remove } from 'fs-extra' | |||
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | 5 | ||
6 | async function processImage ( | 6 | async function processImage ( |
7 | physicalFile: { path: string }, | 7 | path: string, |
8 | destination: string, | 8 | destination: string, |
9 | newSize: { width: number, height: number }, | 9 | newSize: { width: number, height: number }, |
10 | keepOriginal = false | 10 | keepOriginal = false |
11 | ) { | 11 | ) { |
12 | if (physicalFile.path === destination) { | 12 | if (path === destination) { |
13 | throw new Error('Sharp needs an input path different that the output path.') | 13 | throw new Error('Sharp needs an input path different that the output path.') |
14 | } | 14 | } |
15 | 15 | ||
16 | logger.debug('Processing image %s to %s.', physicalFile.path, destination) | 16 | logger.debug('Processing image %s to %s.', path, destination) |
17 | 17 | ||
18 | // Avoid sharp cache | 18 | // Avoid sharp cache |
19 | const buf = await readFile(physicalFile.path) | 19 | const buf = await readFile(path) |
20 | const sharpInstance = sharp(buf) | 20 | const sharpInstance = sharp(buf) |
21 | 21 | ||
22 | await remove(destination) | 22 | await remove(destination) |
@@ -25,7 +25,7 @@ async function processImage ( | |||
25 | .resize(newSize.width, newSize.height) | 25 | .resize(newSize.width, newSize.height) |
26 | .toFile(destination) | 26 | .toFile(destination) |
27 | 27 | ||
28 | if (keepOriginal !== true) await remove(physicalFile.path) | 28 | if (keepOriginal !== true) await remove(path) |
29 | } | 29 | } |
30 | 30 | ||
31 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 8dda6c039..2e30c94a1 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -52,7 +52,7 @@ async function downloadImage (url: string, destDir: string, destName: string, si | |||
52 | const destPath = join(destDir, destName) | 52 | const destPath = join(destDir, destName) |
53 | 53 | ||
54 | try { | 54 | try { |
55 | await processImage({ path: tmpPath }, destPath, size) | 55 | await processImage(tmpPath, destPath, size) |
56 | } catch (err) { | 56 | } catch (err) { |
57 | await remove(tmpPath) | 57 | await remove(tmpPath) |
58 | 58 | ||
diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index dca543d0b..09b4e38ca 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts | |||
@@ -15,7 +15,7 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a | |||
15 | const extension = extname(avatarPhysicalFile.filename) | 15 | const extension = extname(avatarPhysicalFile.filename) |
16 | const avatarName = uuidv4() + extension | 16 | const avatarName = uuidv4() + extension |
17 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) | 17 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) |
18 | await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) | 18 | await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE) |
19 | 19 | ||
20 | return retryTransactionWrapper(() => { | 20 | return retryTransactionWrapper(() => { |
21 | return sequelizeTypescript.transaction(async t => { | 21 | return sequelizeTypescript.transaction(async t => { |
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 8ad82ee80..4ba521b97 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -16,7 +16,7 @@ function createPlaylistMiniatureFromExisting (inputPath: string, playlist: Video | |||
16 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) | 16 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) |
17 | const type = ThumbnailType.MINIATURE | 17 | const type = ThumbnailType.MINIATURE |
18 | 18 | ||
19 | const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height }, keepOriginal) | 19 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) |
20 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 20 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) |
21 | } | 21 | } |
22 | 22 | ||
@@ -37,7 +37,7 @@ function createVideoMiniatureFromUrl (url: string, video: VideoModel, type: Thum | |||
37 | 37 | ||
38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { | 38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { |
39 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 39 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
40 | const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height }) | 40 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }) |
41 | 41 | ||
42 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 42 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) |
43 | } | 43 | } |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 18f18795e..5fb529e8d 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -239,6 +239,11 @@ type AvailableForListIDsOptions = { | |||
239 | { | 239 | { |
240 | model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }), | 240 | model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }), |
241 | required: true | 241 | required: true |
242 | }, | ||
243 | { | ||
244 | attributes: [ 'type', 'filename' ], | ||
245 | model: ThumbnailModel, | ||
246 | required: false | ||
242 | } | 247 | } |
243 | ] | 248 | ] |
244 | } | 249 | } |
@@ -1599,7 +1604,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1599 | ] | 1604 | ] |
1600 | } | 1605 | } |
1601 | 1606 | ||
1602 | const apiScope: (string | ScopeOptions)[] = [ ScopeNames.WITH_THUMBNAILS ] | 1607 | const apiScope: (string | ScopeOptions)[] = [] |
1603 | 1608 | ||
1604 | if (options.user) { | 1609 | if (options.user) { |
1605 | apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] }) | 1610 | apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] }) |