refactor: sync masto (#1121)

This commit is contained in:
三咲智子 Kevin Deng 2023-01-15 16:38:02 +08:00 committed by GitHub
parent eb1f769e32
commit 4422a57f49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 397 additions and 367 deletions

View file

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

View file

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