You've already forked AstralRinth
forked from didirus/AstralRinth
* feat: base locking impl * feat: lock logic in place in rev endpoint + fetch rev * feat: frontend impl and finalize * feat: auto skip if using the moderation queue page * fix: qa issues * fix: async state + locking fix * fix: lint * fix: fmt * fix: qa issue * fix: qa + redirect bug * fix: lint * feat: delete all locks endpoint for admins * fix: dedupe * fix: fmt * fix: project redirect move to middleware * fix: lint
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { AuthFeature, type NuxtClientConfig, NuxtModrinthClient } from '@modrinth/api-client'
|
|
import type { H3Event } from 'h3'
|
|
|
|
async function getRateLimitKeyFromSecretsStore(): Promise<string | undefined> {
|
|
try {
|
|
const mod = 'cloudflare:workers'
|
|
const { env } = await import(/* @vite-ignore */ mod)
|
|
return await env.RATE_LIMIT_IGNORE_KEY?.get()
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export interface ServerModrinthClientOptions {
|
|
event?: H3Event
|
|
authToken?: string
|
|
}
|
|
|
|
export function useServerModrinthClient(options?: ServerModrinthClientOptions): NuxtModrinthClient {
|
|
const config = useRuntimeConfig(options?.event)
|
|
const apiBaseUrl = (config.apiBaseUrl || config.public.apiBaseUrl).replace('/v2/', '/')
|
|
|
|
const features = []
|
|
|
|
if (options?.authToken) {
|
|
features.push(
|
|
new AuthFeature({
|
|
token: options.authToken,
|
|
tokenPrefix: '',
|
|
}),
|
|
)
|
|
}
|
|
|
|
const clientConfig: NuxtClientConfig = {
|
|
labrinthBaseUrl: apiBaseUrl,
|
|
rateLimitKey: config.rateLimitKey || getRateLimitKeyFromSecretsStore,
|
|
features,
|
|
}
|
|
|
|
return new NuxtModrinthClient(clientConfig)
|
|
}
|