1
0
Fork 0
mirror of https://github.com/elk-zone/elk.git synced 2025-05-08 16:22:49 +03:00

feat: make internal app URLs permalinks ()

This commit is contained in:
Daniel Roe 2022-12-04 19:56:33 +00:00 committed by GitHub
parent 4f8f2ed1f1
commit eb022c92e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 99 additions and 51 deletions

View file

@ -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>