Skip to content

Commit

Permalink
fix: improve support for embedding complex urls (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuur29 authored Oct 29, 2021
1 parent 3d29fc8 commit 7301ff3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/portal/link-toolbar/link-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const LinkToolbar = () => {
if (!result) {
return
}
const bookmarkUrl = `/api/extract?type=${type}&url=${href}`
const bookmarkUrl = `/api/extract?type=${type}&url=${encodeURIComponent(href)}`
const transaction = state.tr.replaceWith(
result.pos,
result.pos + result.node.nodeSize,
Expand Down
9 changes: 8 additions & 1 deletion pages/api/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const expires = 86400
export default api()
.use(useReferrer)
.get(async (req, res) => {
const { url } = req.query as { url: string }
const url = decodeURIComponent((req.query as { url: string }).url)
if (!url) {
return res.APIError.NOT_SUPPORTED.throw('missing url')
}

const result = await unfurl(url as string, {
oembed: true,
})
Expand Down Expand Up @@ -39,6 +40,12 @@ export default api()
...result.open_graph,
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)
Expand Down

0 comments on commit 7301ff3

Please sign in to comment.