chore: rename to Elk

This commit is contained in:
Anthony Fu 2022-11-23 21:06:27 +08:00
parent 674879cb7f
commit 129e12c217
12 changed files with 35 additions and 69 deletions

View file

@ -1,42 +0,0 @@
import { emojisArrayToObject } from './utils'
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 = emojisArrayToObject(r)
}),
])
}
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
}

View file

@ -1,9 +1,9 @@
import { login as loginMasto } from 'masto'
import type { UserLogin } from '~/types'
import { DEFAULT_SERVER } from '~/constants'
import { DEFAULT_SERVER, STORAGE_KEY_CURRENT_USER, STORAGE_KEY_USERS } from '~/constants'
const users = useLocalStorage<UserLogin[]>('nuxtodon-accounts', [], { deep: true })
const currentUserId = useLocalStorage<string>('nuxtodon-current-user', '')
const users = useLocalStorage<UserLogin[]>(STORAGE_KEY_USERS, [], { deep: true })
const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, '')
export const currentUser = computed<UserLogin | undefined>(() => {
let user: UserLogin | undefined