Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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