mirror of
https://github.com/elk-zone/elk.git
synced 2025-05-08 16:22:49 +03:00
feat: make internal app URLs permalinks (#329)
This commit is contained in:
parent
4f8f2ed1f1
commit
eb022c92e8
19 changed files with 99 additions and 51 deletions
pages
|
@ -1,43 +1,23 @@
|
|||
<script setup lang="ts">
|
||||
import { parseURL } from 'ufo'
|
||||
import { HANDLED_MASTO_URLS } from '~/constants'
|
||||
import { hasProtocol, parseURL } from 'ufo'
|
||||
|
||||
definePageMeta({
|
||||
name: 'permalink',
|
||||
middleware: async (to) => {
|
||||
try {
|
||||
let permalink = Array.isArray(to.params.permalink)
|
||||
? to.params.permalink.join('/')
|
||||
: to.params.permalink
|
||||
const permalink = Array.isArray(to.params.permalink)
|
||||
? to.params.permalink.join('/')
|
||||
: to.params.permalink
|
||||
|
||||
if (!HANDLED_MASTO_URLS.test(permalink))
|
||||
return '/home'
|
||||
|
||||
if (!permalink.startsWith('http'))
|
||||
permalink = `https://${permalink}`
|
||||
|
||||
if (!currentUser.value) {
|
||||
const { host, pathname } = parseURL(permalink)
|
||||
await loginTo({ server: host! })
|
||||
|
||||
if (pathname.match(/^\/@[^/]+$/))
|
||||
return `${pathname}@${host}`
|
||||
if (hasProtocol(permalink)) {
|
||||
const { host, pathname } = parseURL(permalink)
|
||||
|
||||
if (host) {
|
||||
await loginTo({ server: host })
|
||||
return pathname
|
||||
}
|
||||
|
||||
const { value } = await useMasto().search({ q: permalink, resolve: true, limit: 1 }).next()
|
||||
|
||||
const { accounts, statuses } = value
|
||||
if (statuses[0])
|
||||
return getStatusRoute(statuses[0])
|
||||
|
||||
if (accounts[0])
|
||||
return getAccountRoute(accounts[0])
|
||||
}
|
||||
catch {}
|
||||
|
||||
return '/home'
|
||||
// We've reached a page that doesn't exist
|
||||
return false
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue