fix: improve support for embedding complex urls (#117)

This commit is contained in:
Tuur Lievens 2021-10-29 03:21:06 +02:00 committed by GitHub
parent 3d29fc8602
commit 7301ff3c9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -31,7 +31,7 @@ const LinkToolbar = () => {
if (!result) { if (!result) {
return return
} }
const bookmarkUrl = `/api/extract?type=${type}&url=${href}` const bookmarkUrl = `/api/extract?type=${type}&url=${encodeURIComponent(href)}`
const transaction = state.tr.replaceWith( const transaction = state.tr.replaceWith(
result.pos, result.pos,
result.pos + result.node.nodeSize, result.pos + result.node.nodeSize,

View File

@ -7,10 +7,11 @@ const expires = 86400
export default api() export default api()
.use(useReferrer) .use(useReferrer)
.get(async (req, res) => { .get(async (req, res) => {
const { url } = req.query as { url: string } const url = decodeURIComponent((req.query as { url: string }).url)
if (!url) { if (!url) {
return res.APIError.NOT_SUPPORTED.throw('missing url') return res.APIError.NOT_SUPPORTED.throw('missing url')
} }
const result = await unfurl(url as string, { const result = await unfurl(url as string, {
oembed: true, oembed: true,
}) })
@ -39,6 +40,12 @@ export default api()
...result.open_graph, ...result.open_graph,
url: `${url}.pibb`, url: `${url}.pibb`,
} }
} else if (/(app|viewer).diagrams.net\//.test(url)) {
const data = url.split('#')?.[1]
result.open_graph = {
...result.open_graph,
url: `https://viewer.diagrams.net/?highlight=0000ff&edit=_blank&layers=1&nav=1#${data}`,
}
} }
res.json(result) res.json(result)