refactor: sync masto (#1121)
This commit is contained in:
parent
eb1f769e32
commit
4422a57f49
81 changed files with 397 additions and 367 deletions
|
@ -4,7 +4,7 @@ export default defineNuxtRouteMiddleware((to) => {
|
|||
if (to.path === '/signin/callback')
|
||||
return
|
||||
|
||||
onMastoInit(() => {
|
||||
onHydrated(() => {
|
||||
if (!currentUser.value) {
|
||||
if (to.path === '/home' && to.query['share-target'] !== undefined)
|
||||
return navigateTo('/share-target')
|
||||
|
|
|
@ -2,23 +2,14 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
|||
if (process.server)
|
||||
return
|
||||
|
||||
const masto = useMasto()
|
||||
|
||||
// Skip running middleware before masto has been initialised
|
||||
if (!masto)
|
||||
return
|
||||
|
||||
if (!('server' in to.params))
|
||||
return
|
||||
|
||||
const user = currentUser.value
|
||||
|
||||
const masto = useMasto()
|
||||
if (!user) {
|
||||
if (from.params.server !== to.params.server) {
|
||||
await masto.loginTo({
|
||||
server: to.params.server as string,
|
||||
})
|
||||
}
|
||||
if (from.params.server !== to.params.server)
|
||||
loginTo(masto, { server: to.params.server as string })
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -49,11 +40,8 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
|
|||
return getAccountRoute(account)
|
||||
}
|
||||
|
||||
if (!masto.loggedIn.value)
|
||||
await masto.loginTo(currentUser.value)
|
||||
|
||||
// If we're logged in, search for the local id the account or status corresponds to
|
||||
const { accounts, statuses } = await masto.v2.search({ q: `https:/${to.fullPath}`, resolve: true, limit: 1 })
|
||||
const { accounts, statuses } = await masto.client.value.v2.search({ q: `https:/${to.fullPath}`, resolve: true, limit: 1 })
|
||||
if (statuses[0])
|
||||
return getStatusRoute(statuses[0])
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue