feat: disable SSR
This commit is contained in:
parent
e59b3e5db2
commit
a6578155ae
29 changed files with 109 additions and 175 deletions
41
composables/servers.ts
Normal file
41
composables/servers.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import type { ServerInfo } from '~/types'
|
||||
|
||||
const ServerInfoTTL = 60 * 60 * 1000 * 12 // 12 hour
|
||||
|
||||
const serverInfoPromise = new Map<string, Promise<ServerInfo>>()
|
||||
const serverInfos = useLocalStorage<Record<string, ServerInfo>>('nuxtodon-server-info', {})
|
||||
|
||||
async function _fetchServerInfo(server: string) {
|
||||
if (!serverInfos.value[server]) {
|
||||
// @ts-expect-error init
|
||||
serverInfos.value[server] = {
|
||||
timeUpdated: 0,
|
||||
server,
|
||||
}
|
||||
}
|
||||
if (serverInfos.value[server].timeUpdated + ServerInfoTTL < Date.now()) {
|
||||
await Promise.allSettled([
|
||||
masto.instances.fetch().then((r) => {
|
||||
Object.assign(serverInfos.value[server], r)
|
||||
}),
|
||||
masto.customEmojis.fetchAll().then((r) => {
|
||||
serverInfos.value[server].customEmojis = Object.fromEntries(r.map(i => [i.shortcode, i]))
|
||||
}),
|
||||
])
|
||||
}
|
||||
return serverInfos.value[server]
|
||||
}
|
||||
|
||||
export function fetchServerInfo(server: string) {
|
||||
if (!serverInfoPromise.has(server))
|
||||
serverInfoPromise.set(server, _fetchServerInfo(server))
|
||||
return serverInfoPromise.get(server)!
|
||||
}
|
||||
|
||||
export function useServerInfo(server: string) {
|
||||
const info = ref<ServerInfo | undefined>()
|
||||
fetchServerInfo(server).then((r) => {
|
||||
info.value = r
|
||||
})
|
||||
return info
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue