mirror of
https://github.com/notea-org/notea.git
synced 2024-10-04 10:27:35 +03:00
fix: improve support for embedding complex urls (#117)
This commit is contained in:
parent
3d29fc8602
commit
7301ff3c9e
@ -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,
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user