-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(embed): create the endpoint to generate oembed metadata
- Loading branch information
1 parent
e7be592
commit 9521940
Showing
14 changed files
with
152 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
apps/core/src/resources/snippets/handlers/generate-oembed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { snippetService } from '@sharingan/domain'; | ||
import { generateOembedMetadata } from '@sharingan/embed'; | ||
import { Request, Response } from 'express'; | ||
|
||
import { env } from '../../../configs/env'; | ||
import { logger } from '../../../configs/logger'; | ||
|
||
export const generateOembed = async (req: Request, res: Response) => { | ||
const { id } = req.params; | ||
|
||
try { | ||
const snippet = await snippetService.findById(id); | ||
|
||
const embedMetadata = generateOembedMetadata({ | ||
snippet: { | ||
id: snippet.id, | ||
name: snippet.name, | ||
}, | ||
snippetRendererURL: env.SNIPPET_RENDERER_URL, | ||
webAppURL: env.WEB_APP_URL, | ||
}); | ||
|
||
return res.json(embedMetadata); | ||
} catch (e) { | ||
logger.error(e); | ||
|
||
return res.status(404).json({ error: 'Not found' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Router } from 'express'; | ||
|
||
import { generateOembed } from './handlers/generate-oembed'; | ||
|
||
const snippetRoute = (): Router => { | ||
const router = Router(); | ||
|
||
router.get('/oembed/:id', generateOembed); | ||
|
||
return router; | ||
}; | ||
|
||
export { snippetRoute }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ | |
"eslint-plugin-typescript-sort-keys": "^2.1.0", | ||
"husky": "^8.0.1", | ||
"prettier": "^2.7.1", | ||
"turbo": "^1.3.1" | ||
"turbo": "^1.5.4" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { generateOembedMetadata } from './src/oembed/index'; | ||
export { renderSnippetToHtml } from './src/renderer/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
"author": "Eric Cabrel TIOGO <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsup", | ||
"build:watch": "tsup --watch", | ||
"build:cdn": "tsup", | ||
"build:cdn:watch": "tsup --watch", | ||
"build:lib": "tsc", | ||
"build": "yarn build:lib && yarn build:cdn", | ||
"clean": "rm -rf .turbo dist build", | ||
"dev": "nodemon --watch \"*.ts\" --exec \"ts-node\" ./src/server/index.ts", | ||
"lint": "eslint src", | ||
|
@@ -23,6 +25,7 @@ | |
"serve": "^14.0.1", | ||
"shiki": "^0.11.1", | ||
"ts-node": "^10.9.1", | ||
"tsup": "^6.2.2" | ||
"tsup": "^6.2.2", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
type Args = { | ||
snippet: { | ||
id: string; | ||
name: string; | ||
}; | ||
snippetRendererURL: string; | ||
webAppURL: string; | ||
}; | ||
|
||
type Result = { | ||
height: number; | ||
html: string; | ||
provider_name: string; | ||
provider_url: string; | ||
thumbnail_height: string; | ||
thumbnail_url: string; | ||
thumbnail_width: string; | ||
title: string; | ||
type: string; | ||
version: string; | ||
width: number; | ||
}; | ||
|
||
export const generateOembedMetadata = ({ snippet, snippetRendererURL, webAppURL }: Args): Result => { | ||
const embedUrl = `${snippetRendererURL}/snippets/${snippet.id}`; | ||
|
||
return { | ||
height: 500, | ||
html: `<iframe width="750" height="500" src="${embedUrl}" style="width:750px; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>`, | ||
provider_name: 'Sharingan', | ||
provider_url: webAppURL, | ||
thumbnail_height: '720', | ||
thumbnail_url: `${webAppURL}/assets/og.png`, | ||
thumbnail_width: '1280', | ||
title: snippet.name, | ||
type: 'rich', | ||
version: '1.0', | ||
width: 750, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12422,95 +12422,47 @@ tsutils@^3.21.0: | |
dependencies: | ||
tslib "^1.8.1" | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-android-arm64/-/turbo-android-arm64-1.3.1.tgz#dae9bd087d6a17409fbd10ed82489a1ff39cbcc8" | ||
integrity sha512-JcnZh9tLbZDpKaXaao/s/k4qXt3TbNEc1xEYYXurVWnqiMueGeS7QAtThVB85ZSqzj7djk+ngSrZabPy5RG25Q== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.npmjs.org/turbo-darwin-64/-/turbo-darwin-64-1.3.1.tgz" | ||
integrity sha512-TIGDradVFoGck86VIuM38KaDeNxdKaP2ti93UpQeFw26ZhPIeTAa6wUgnz4DQP6bjIvQmXlYJ16ETZb4tFYygg== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-darwin-arm64/-/turbo-darwin-arm64-1.3.1.tgz#94a361e4e73ad02995303cf6c3d8cb03e85fcae4" | ||
integrity sha512-aLBq8KiMMmop7uKBkvDt/y+eER2UzxZyUzh1KWcZ7DZB5tFZnknEUyf2qggY2vd2WcDVfQ1EUjZ0MFxhhVaVzA== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-freebsd-64/-/turbo-freebsd-64-1.3.1.tgz#64b8fc1b9f2ad9b76b532ffdcce267b2934ecb86" | ||
integrity sha512-BOr/ifmxjlBeuDkDQLUJtzqzXQ2zPHHcI14U9Ys+z4Mza1uzQn/oSJqQvU5RuyRBVai7noMrpPS7QuKtDz0Cyg== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-freebsd-arm64/-/turbo-freebsd-arm64-1.3.1.tgz#b798af9b8898210058ca2752eadb711369f9ecea" | ||
integrity sha512-bHPZjK4xnGLz6/oxl5XmWhdYOdtBMSadrGhptWSZ0wBGNn/gQzDTeZAkQeqhh25AD0eM1hzDe8QUz8GlS43lrA== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-32/-/turbo-linux-32-1.3.1.tgz#9eecada1c13f6391a7c6267349a0486987144093" | ||
integrity sha512-c5okimusfvivu9wS8MKSr+rXpQAV+M4TyR9JX+spIK8B1I7AjfECAqiK2D5WFWO1bQ33bUAuxXOEpUuLpgEm+g== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-64/-/turbo-linux-64-1.3.1.tgz#eaf195b90a80f238561ab11fbde17c07af481c57" | ||
integrity sha512-O0pNX+N5gbmRcyZT+jsCPUNCN3DpIZHqNN35j7MT5nr0IkZa83CGbZnrEc+7Qws//jFJ26EngqD/JyRB2E8nwQ== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-arm64/-/turbo-linux-arm64-1.3.1.tgz#ff9dc17c352c5f59440cb55cff59cb8b23db9d1b" | ||
integrity sha512-D6+1MeS/x+/VCCooHPU4NIpB8qI/eW70eMRA79bqTPaxxluP0g2CaxXgucco05P51YtNsSxeVcH7X76iadON6Q== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-arm/-/turbo-linux-arm-1.3.1.tgz#6be53e62a60a3c6f3ab33585f0442eb7441ecf3a" | ||
integrity sha512-f+r6JIwv/7ylxxJtgVi8cVw+6oNoD/r1IMTU6ejH8bfyMZZko4kkNwH9VYribQ44KDkJEgzdltnzFG5f6Hz10g== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-mips64le/-/turbo-linux-mips64le-1.3.1.tgz#ceddf8c8e222e66d05f7a68a71f66a2a3a0272a3" | ||
integrity sha512-yL64jgwVCziOpBcdpMxIsczkgwwOvmaqKObFKWyCNlk/LOl5NKODLwXEaryLaALtpwUAoS4ltMSI64gKqmLrOA== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-ppc64le/-/turbo-linux-ppc64le-1.3.1.tgz#aa5658f6d19775e06b9fd136491dceab93ecffb2" | ||
integrity sha512-tjnM+8RosykS1lBpOPLDXGOz/Po2h796ty17uBd7IFslWPOI16a/akFOFoLH8PCiGGJMe3CYgRhEKn4sPWNxFA== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-windows-32/-/turbo-windows-32-1.3.1.tgz#e6e570bb381d9a4f78ea6e72102ab9bf493a3ad2" | ||
integrity sha512-Snnv+TVigulqwK6guHKndMlrLw88NXj8BtHRGrEksPR0QkyuHlwLf+tHYB4HmvpUl4W9lnXQf4hsljWP64BEdw== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.3.1.tgz#f891097331125c935cdaa160cc80c4cfc3e61b0e" | ||
integrity sha512-gLeohHG07yIhON1Pp0YNE00i/yzip2GFhkA6HdJaK95uE5bKULpqxuO414hOS/WzGwrGVXBKCImfe24XXh5T+Q== | ||
|
||
[email protected]: | ||
version "1.3.1" | ||
resolved "https://registry.yarnpkg.com/turbo-windows-arm64/-/turbo-windows-arm64-1.3.1.tgz#5abe1743b93e272641018cef213b21ac6c984f04" | ||
integrity sha512-0MWcHLvYgs/qdcoTFZ55nu8HhrpeiwXEMw9cbNfgqTlzy3OsrAsovYEJFyQ8KSxeploiD+QJlCdvhxx+5C0tlA== | ||
|
||
turbo@^1.3.1: | ||
version "1.3.1" | ||
resolved "https://registry.npmjs.org/turbo/-/turbo-1.3.1.tgz" | ||
integrity sha512-DXckoGKlZgvTn/PrHpBI/57aeXR7tfyPf2dK+4LmBczt24ELA3o6eYHeA7KzfpSYhB2LE9qveYFQ6mJ1OzGjjg== | ||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-darwin-64/-/turbo-darwin-64-1.5.5.tgz#710d4e7999066bd4f500456f7cd1c30f6e6205ed" | ||
integrity sha512-HvEn6P2B+NXDekq9LRpRgUjcT9/oygLTcK47U0qsAJZXRBSq/2hvD7lx4nAwgY/4W3rhYJeWtHTzbhoN6BXqGQ== | ||
|
||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-darwin-arm64/-/turbo-darwin-arm64-1.5.5.tgz#f7955a800e945ab110e8a6e23f60a2b9795296ab" | ||
integrity sha512-Dmxr09IUy6M0nc7/xWod9galIO2DD500B75sJSkHeT+CCdJOWnlinux0ZPF8CSygNqymwYO8AO2l15/6yxcycg== | ||
|
||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-64/-/turbo-linux-64-1.5.5.tgz#f31eb117a9b605f5731048c50473bff903850047" | ||
integrity sha512-wd07TZ4zXXWjzZE00FcFMLmkybQQK/NV9ff66vvAV0vdiuacSMBCNLrD6Mm4ncfrUPW/rwFW5kU/7hyuEqqtDw== | ||
|
||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-linux-arm64/-/turbo-linux-arm64-1.5.5.tgz#b9ce6912ae6477e829355d6f012500bfef58669d" | ||
integrity sha512-q3q33tuo74R7gicnfvFbnZZvqmlq7Vakcvx0eshifnJw4PR+oMnTCb4w8ElVFx070zsb8DVTibq99y8NJH8T1Q== | ||
|
||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-windows-64/-/turbo-windows-64-1.5.5.tgz#609098de3bc6178f733615d21b06d5c1602637eb" | ||
integrity sha512-lPp9kHonNFfqgovbaW+UAPO5cLmoAN+m3G3FzqcrRPnlzt97vXYsDhDd/4Zy3oAKoAcprtP4CGy0ddisqsKTVw== | ||
|
||
[email protected]: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo-windows-arm64/-/turbo-windows-arm64-1.5.5.tgz#60522e1e347a54c64bdddb68089fc322ee19c3d7" | ||
integrity sha512-3AfGULKNZiZVrEzsIE+W79ZRW1+f5r4nM4wLlJ1PTBHyRxBZdD6KTH1tijGfy/uTlcV5acYnKHEkDc6Q9PAXGQ== | ||
|
||
turbo@^1.5.4: | ||
version "1.5.5" | ||
resolved "https://registry.yarnpkg.com/turbo/-/turbo-1.5.5.tgz#9fc3a917c914ffa113c260a4eadb4bc632eee227" | ||
integrity sha512-PVQSDl0STC9WXIyHcYUWs9gXsf8JjQig/FuHfuB8N6+XlgCGB3mPbfMEE6zrChGz2hufH4/guKRX1XJuNL6XTA== | ||
optionalDependencies: | ||
turbo-android-arm64 "1.3.1" | ||
turbo-darwin-64 "1.3.1" | ||
turbo-darwin-arm64 "1.3.1" | ||
turbo-freebsd-64 "1.3.1" | ||
turbo-freebsd-arm64 "1.3.1" | ||
turbo-linux-32 "1.3.1" | ||
turbo-linux-64 "1.3.1" | ||
turbo-linux-arm "1.3.1" | ||
turbo-linux-arm64 "1.3.1" | ||
turbo-linux-mips64le "1.3.1" | ||
turbo-linux-ppc64le "1.3.1" | ||
turbo-windows-32 "1.3.1" | ||
turbo-windows-64 "1.3.1" | ||
turbo-windows-arm64 "1.3.1" | ||
turbo-darwin-64 "1.5.5" | ||
turbo-darwin-arm64 "1.5.5" | ||
turbo-linux-64 "1.5.5" | ||
turbo-linux-arm64 "1.5.5" | ||
turbo-windows-64 "1.5.5" | ||
turbo-windows-arm64 "1.5.5" | ||
|
||
type-check@^0.4.0, type-check@~0.4.0: | ||
version "0.4.0" | ||
|
@@ -12596,6 +12548,11 @@ typescript@^4.8.2: | |
resolved "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz" | ||
integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw== | ||
|
||
typescript@^4.8.4: | ||
version "4.8.4" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" | ||
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== | ||
|
||
ua-parser-js@^0.7.30: | ||
version "0.7.31" | ||
resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.31.tgz" | ||
|