2022-11-29 23:51:52 +03:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { parseURL } from 'ufo'
|
2022-12-02 01:59:08 +03:00
|
|
|
import { HANDLED_MASTO_URLS } from '~/constants'
|
2022-11-29 23:51:52 +03:00
|
|
|
|
|
|
|
definePageMeta({
|
2022-11-30 20:15:18 +03:00
|
|
|
name: 'permalink',
|
2022-11-29 23:51:52 +03:00
|
|
|
middleware: async (to) => {
|
2022-11-30 16:31:33 +03:00
|
|
|
try {
|
|
|
|
let permalink = Array.isArray(to.params.permalink)
|
|
|
|
? to.params.permalink.join('/')
|
|
|
|
: to.params.permalink
|
2022-11-29 23:51:52 +03:00
|
|
|
|
2022-12-02 01:59:08 +03:00
|
|
|
if (!HANDLED_MASTO_URLS.test(permalink))
|
2022-11-30 16:31:33 +03:00
|
|
|
return '/home'
|
2022-11-29 23:51:52 +03:00
|
|
|
|
2022-11-30 16:31:33 +03:00
|
|
|
if (!permalink.startsWith('http'))
|
|
|
|
permalink = `https://${permalink}`
|
|
|
|
|
|
|
|
if (!currentUser.value) {
|
|
|
|
const { host, pathname } = parseURL(permalink)
|
|
|
|
await loginTo({ server: host! })
|
2022-12-02 01:59:08 +03:00
|
|
|
|
|
|
|
if (pathname.match(/^\/@[^/]+$/))
|
|
|
|
return `${pathname}@${host}`
|
|
|
|
|
2022-11-30 16:31:33 +03:00
|
|
|
return pathname
|
|
|
|
}
|
2022-11-29 23:51:52 +03:00
|
|
|
|
2022-11-30 16:31:33 +03:00
|
|
|
const { value } = await useMasto().search({ q: permalink, resolve: true, limit: 1 }).next()
|
2022-11-29 23:51:52 +03:00
|
|
|
|
2022-11-30 16:31:33 +03:00
|
|
|
const { accounts, statuses } = value
|
2022-11-30 20:15:18 +03:00
|
|
|
if (statuses[0])
|
|
|
|
return getStatusRoute(statuses[0])
|
|
|
|
|
2022-11-30 16:31:33 +03:00
|
|
|
if (accounts[0])
|
2022-11-30 20:15:18 +03:00
|
|
|
return getAccountRoute(accounts[0])
|
2022-11-29 23:51:52 +03:00
|
|
|
}
|
2022-11-30 16:31:33 +03:00
|
|
|
catch {}
|
2022-11-29 23:51:52 +03:00
|
|
|
|
|
|
|
return '/home'
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div />
|
|
|
|
</template>
|