diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-17 10:35:27 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-17 10:35:27 +0200 |
commit | 164174a6abac3e391e95d479a98749e20eb86f34 (patch) | |
tree | 9fac6566299af7b86798cd07e181d269808eacbd /server | |
parent | 4b5dc9f1e452723503a3ef07405f80c793d7b5f7 (diff) | |
download | PeerTube-164174a6abac3e391e95d479a98749e20eb86f34.tar.gz PeerTube-164174a6abac3e391e95d479a98749e20eb86f34.tar.zst PeerTube-164174a6abac3e391e95d479a98749e20eb86f34.zip |
Use preview instead of thumbnail for oembed
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/services.ts | 16 | ||||
-rw-r--r-- | server/helpers/ffmpeg-utils.ts | 2 | ||||
-rw-r--r-- | server/initializers/constants.ts | 10 | ||||
-rw-r--r-- | server/models/video/video.ts | 6 | ||||
-rw-r--r-- | server/tests/api/services.ts | 8 |
5 files changed, 26 insertions, 16 deletions
diff --git a/server/controllers/services.ts b/server/controllers/services.ts index 3ce6bd526..4bbe56a8a 100644 --- a/server/controllers/services.ts +++ b/server/controllers/services.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | ||
3 | import { CONFIG, THUMBNAILS_SIZE } from '../initializers' | 3 | import { CONFIG, PREVIEWS_SIZE, EMBED_SIZE } from '../initializers' |
4 | import { oembedValidator } from '../middlewares' | 4 | import { oembedValidator } from '../middlewares' |
5 | import { VideoInstance } from '../models' | 5 | import { VideoInstance } from '../models' |
6 | 6 | ||
@@ -23,17 +23,17 @@ function generateOEmbed (req: express.Request, res: express.Response, next: expr | |||
23 | const maxWidth = parseInt(req.query.maxwidth, 10) | 23 | const maxWidth = parseInt(req.query.maxwidth, 10) |
24 | 24 | ||
25 | const embedUrl = webserverUrl + video.getEmbedPath() | 25 | const embedUrl = webserverUrl + video.getEmbedPath() |
26 | let thumbnailUrl = webserverUrl + video.getThumbnailPath() | 26 | let thumbnailUrl = webserverUrl + video.getPreviewPath() |
27 | let embedWidth = 560 | 27 | let embedWidth = EMBED_SIZE.width |
28 | let embedHeight = 315 | 28 | let embedHeight = EMBED_SIZE.height |
29 | 29 | ||
30 | if (maxHeight < embedHeight) embedHeight = maxHeight | 30 | if (maxHeight < embedHeight) embedHeight = maxHeight |
31 | if (maxWidth < embedWidth) embedWidth = maxWidth | 31 | if (maxWidth < embedWidth) embedWidth = maxWidth |
32 | 32 | ||
33 | // Our thumbnail is too big for the consumer | 33 | // Our thumbnail is too big for the consumer |
34 | if ( | 34 | if ( |
35 | (maxHeight !== undefined && maxHeight < THUMBNAILS_SIZE.height) || | 35 | (maxHeight !== undefined && maxHeight < PREVIEWS_SIZE.height) || |
36 | (maxWidth !== undefined && maxWidth < THUMBNAILS_SIZE.width) | 36 | (maxWidth !== undefined && maxWidth < PREVIEWS_SIZE.width) |
37 | ) { | 37 | ) { |
38 | thumbnailUrl = undefined | 38 | thumbnailUrl = undefined |
39 | } | 39 | } |
@@ -54,8 +54,8 @@ function generateOEmbed (req: express.Request, res: express.Response, next: expr | |||
54 | 54 | ||
55 | if (thumbnailUrl !== undefined) { | 55 | if (thumbnailUrl !== undefined) { |
56 | json.thumbnail_url = thumbnailUrl | 56 | json.thumbnail_url = thumbnailUrl |
57 | json.thumbnail_width = THUMBNAILS_SIZE.width | 57 | json.thumbnail_width = PREVIEWS_SIZE.width |
58 | json.thumbnail_height = THUMBNAILS_SIZE.height | 58 | json.thumbnail_height = PREVIEWS_SIZE.height |
59 | } | 59 | } |
60 | 60 | ||
61 | return res.json(json) | 61 | return res.json(json) |
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts index c35125ec1..913a90905 100644 --- a/server/helpers/ffmpeg-utils.ts +++ b/server/helpers/ffmpeg-utils.ts | |||
@@ -25,7 +25,7 @@ function getDurationFromVideoFile (path: string) { | |||
25 | }) | 25 | }) |
26 | } | 26 | } |
27 | 27 | ||
28 | function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size?: string) { | 28 | function generateImageFromVideoFile (fromPath: string, folder: string, imageName: string, size: string) { |
29 | const options = { | 29 | const options = { |
30 | filename: imageName, | 30 | filename: imageName, |
31 | count: 1, | 31 | count: 1, |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 6218644cf..491fb78f9 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -300,8 +300,13 @@ const THUMBNAILS_SIZE = { | |||
300 | height: 110 | 300 | height: 110 |
301 | } | 301 | } |
302 | const PREVIEWS_SIZE = { | 302 | const PREVIEWS_SIZE = { |
303 | width: 640, | 303 | width: 560, |
304 | height: 480 | 304 | height: 315 |
305 | } | ||
306 | |||
307 | const EMBED_SIZE = { | ||
308 | width: 560, | ||
309 | height: 315 | ||
305 | } | 310 | } |
306 | 311 | ||
307 | // Sub folders of cache directory | 312 | // Sub folders of cache directory |
@@ -343,6 +348,7 @@ export { | |||
343 | CACHE, | 348 | CACHE, |
344 | CONFIG, | 349 | CONFIG, |
345 | CONSTRAINTS_FIELDS, | 350 | CONSTRAINTS_FIELDS, |
351 | EMBED_SIZE, | ||
346 | FRIEND_SCORE, | 352 | FRIEND_SCORE, |
347 | JOB_STATES, | 353 | JOB_STATES, |
348 | JOBS_CONCURRENCY, | 354 | JOBS_CONCURRENCY, |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 0d0048b4a..fb18a485a 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -48,6 +48,7 @@ import { | |||
48 | 48 | ||
49 | VideoMethods | 49 | VideoMethods |
50 | } from './video-interface' | 50 | } from './video-interface' |
51 | import { PREVIEWS_SIZE } from '../../initializers/constants' | ||
51 | 52 | ||
52 | let Video: Sequelize.Model<VideoInstance, VideoAttributes> | 53 | let Video: Sequelize.Model<VideoInstance, VideoAttributes> |
53 | let getOriginalFile: VideoMethods.GetOriginalFile | 54 | let getOriginalFile: VideoMethods.GetOriginalFile |
@@ -373,10 +374,13 @@ isOwned = function (this: VideoInstance) { | |||
373 | } | 374 | } |
374 | 375 | ||
375 | createPreview = function (this: VideoInstance, videoFile: VideoFileInstance) { | 376 | createPreview = function (this: VideoInstance, videoFile: VideoFileInstance) { |
377 | const imageSize = PREVIEWS_SIZE.width + 'x' + PREVIEWS_SIZE.height | ||
378 | |||
376 | return generateImageFromVideoFile( | 379 | return generateImageFromVideoFile( |
377 | this.getVideoFilePath(videoFile), | 380 | this.getVideoFilePath(videoFile), |
378 | CONFIG.STORAGE.PREVIEWS_DIR, | 381 | CONFIG.STORAGE.PREVIEWS_DIR, |
379 | this.getPreviewName() | 382 | this.getPreviewName(), |
383 | imageSize | ||
380 | ) | 384 | ) |
381 | } | 385 | } |
382 | 386 | ||
diff --git a/server/tests/api/services.ts b/server/tests/api/services.ts index b396ea582..76911fdc5 100644 --- a/server/tests/api/services.ts +++ b/server/tests/api/services.ts | |||
@@ -42,16 +42,16 @@ describe('Test services', function () { | |||
42 | const res = await getOEmbed(server.url, oembedUrl) | 42 | const res = await getOEmbed(server.url, oembedUrl) |
43 | const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` + | 43 | const expectedHtml = `<iframe width="560" height="315" src="http://localhost:9001/videos/embed/${server.video.uuid}" ` + |
44 | 'frameborder="0" allowfullscreen></iframe>' | 44 | 'frameborder="0" allowfullscreen></iframe>' |
45 | const expectedThumbnailUrl = 'http://localhost:9001/static/thumbnails/' + server.video.uuid + '.jpg' | 45 | const expectedThumbnailUrl = 'http://localhost:9001/static/previews/' + server.video.uuid + '.jpg' |
46 | 46 | ||
47 | expect(res.body.html).to.equal(expectedHtml) | 47 | expect(res.body.html).to.equal(expectedHtml) |
48 | expect(res.body.title).to.equal(server.video.name) | 48 | expect(res.body.title).to.equal(server.video.name) |
49 | expect(res.body.author_name).to.equal(server.video.author) | 49 | expect(res.body.author_name).to.equal(server.video.author) |
50 | expect(res.body.height).to.equal(315) | ||
51 | expect(res.body.width).to.equal(560) | 50 | expect(res.body.width).to.equal(560) |
51 | expect(res.body.height).to.equal(315) | ||
52 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) | 52 | expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl) |
53 | expect(res.body.thumbnail_width).to.equal(200) | 53 | expect(res.body.thumbnail_width).to.equal(560) |
54 | expect(res.body.thumbnail_height).to.equal(110) | 54 | expect(res.body.thumbnail_height).to.equal(315) |
55 | }) | 55 | }) |
56 | 56 | ||
57 | it('Should have a valid oEmbed response with small max height query', async function () { | 57 | it('Should have a valid oEmbed response with small max height query', async function () { |