]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/services.ts
Fix problem with SMTP in default docker-compose setup
[github/Chocobozzz/PeerTube.git] / server / controllers / services.ts
CommitLineData
d8755eed 1import * as express from 'express'
a2431b7d 2import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers'
3fd3ab2d 3import { asyncMiddleware, oembedValidator } from '../middlewares'
e8cb4409 4import { accountsNameWithHostGetValidator } from '../middlewares/validators'
3fd3ab2d 5import { VideoModel } from '../models/video/video'
d8755eed
C
6
7const servicesRouter = express.Router()
8
a2431b7d
C
9servicesRouter.use('/oembed',
10 asyncMiddleware(oembedValidator),
11 generateOEmbed
12)
ad9e39fb 13servicesRouter.use('/redirect/accounts/:accountName',
e8cb4409
C
14 asyncMiddleware(accountsNameWithHostGetValidator),
15 redirectToAccountUrl
16)
d8755eed
C
17
18// ---------------------------------------------------------------------------
19
20export {
21 servicesRouter
22}
23
24// ---------------------------------------------------------------------------
25
26function generateOEmbed (req: express.Request, res: express.Response, next: express.NextFunction) {
3fd3ab2d 27 const video = res.locals.video as VideoModel
d8755eed
C
28 const webserverUrl = CONFIG.WEBSERVER.URL
29 const maxHeight = parseInt(req.query.maxheight, 10)
30 const maxWidth = parseInt(req.query.maxwidth, 10)
31
40e87e9e
C
32 const embedUrl = webserverUrl + video.getEmbedStaticPath()
33 let thumbnailUrl = webserverUrl + video.getPreviewStaticPath()
164174a6
C
34 let embedWidth = EMBED_SIZE.width
35 let embedHeight = EMBED_SIZE.height
d8755eed
C
36
37 if (maxHeight < embedHeight) embedHeight = maxHeight
38 if (maxWidth < embedWidth) embedWidth = maxWidth
39
40 // Our thumbnail is too big for the consumer
41 if (
164174a6
C
42 (maxHeight !== undefined && maxHeight < PREVIEWS_SIZE.height) ||
43 (maxWidth !== undefined && maxWidth < PREVIEWS_SIZE.width)
d8755eed
C
44 ) {
45 thumbnailUrl = undefined
46 }
47
6ccdf3a2
C
48 const html = `<iframe width="${embedWidth}" height="${embedHeight}" sandbox="allow-same-origin allow-scripts" ` +
49 `src="${embedUrl}" frameborder="0" allowfullscreen></iframe>`
d8755eed
C
50
51 const json: any = {
52 type: 'video',
53 version: '1.0',
54 html,
55 width: embedWidth,
56 height: embedHeight,
57 title: video.name,
38fa2065 58 author_name: video.VideoChannel.Account.name,
49799b16 59 author_url: video.VideoChannel.Account.Actor.url,
d8755eed
C
60 provider_name: 'PeerTube',
61 provider_url: webserverUrl
62 }
63
64 if (thumbnailUrl !== undefined) {
65 json.thumbnail_url = thumbnailUrl
164174a6
C
66 json.thumbnail_width = PREVIEWS_SIZE.width
67 json.thumbnail_height = PREVIEWS_SIZE.height
d8755eed
C
68 }
69
70 return res.json(json)
71}
e8cb4409
C
72
73function redirectToAccountUrl (req: express.Request, res: express.Response, next: express.NextFunction) {
74 return res.redirect(res.locals.account.Actor.url)
75}