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
|
@ -1,6 +1,6 @@
|
|||
export default defineNuxtRouteMiddleware((from) => {
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
if (!currentUser.value)
|
||||
return navigateTo('/public')
|
||||
else if (from.path === '/')
|
||||
if (to.path === '/')
|
||||
return navigateTo('/home')
|
||||
})
|
||||
|
|
51
middleware/permalink.global.ts
Normal file
51
middleware/permalink.global.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
// Skip running middleware before masto has been initialised
|
||||
if (!useNuxtApp().$masto)
|
||||
return
|
||||
|
||||
if (!('server' in to.params))
|
||||
return
|
||||
|
||||
if (!currentUser.value) {
|
||||
if (from.params.server !== to.params.server) {
|
||||
await loginTo({
|
||||
server: to.params.server as string,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// No need to additionally resolve an id if we're already logged in
|
||||
if (currentUser.value.server === to.params.server)
|
||||
return
|
||||
|
||||
// Tags don't need to be redirected to a local id
|
||||
if (to.params.tag)
|
||||
return
|
||||
|
||||
// Handle redirecting to new permalink structure for users with old links
|
||||
if (!to.params.server) {
|
||||
return {
|
||||
...to,
|
||||
params: {
|
||||
...to.params,
|
||||
server: currentUser.value.server,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// If we're logged in, search for the local id the account or status corresponds to
|
||||
const { value } = await useMasto().search({ q: `https:/${to.fullPath}`, 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'
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue