Files
AstralRinth/apps/frontend/src/helpers/api.ts
Calum H. 099011a177 feat: modrinth hosting - files tab refactor (#4912)
* feat: api-client module for content v0

* feat: delete unused components + modules + setting

* feat: xhr uploading

* feat: fs module -> api-client

* feat: migrate files.vue to use tanstack

* fix: mem leak + other issues

* fix: build

* feat: switch to monaco

* fix: go back to using ace, but improve preloading + theme

* fix: styling + dead attrs

* feat: match figma

* fix: padding

* feat: files-new for ui page structure

* feat: finalize files.vue

* fix: lint

* fix: qa

* fix: dep

* fix: lint

* fix: lockfile merge

* feat: icons on navtab

* fix: surface alternating on table

* fix: hover surface color

---------

Signed-off-by: Calum H. <contact@cal.engineer>
Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
2026-01-06 00:35:51 +00:00

54 lines
1.4 KiB
TypeScript

import {
type AbstractFeature,
type AuthConfig,
AuthFeature,
CircuitBreakerFeature,
NodeAuthFeature,
nodeAuthState,
NuxtCircuitBreakerStorage,
type NuxtClientConfig,
NuxtModrinthClient,
PanelVersionFeature,
VerboseLoggingFeature,
} from '@modrinth/api-client'
import type { Ref } from 'vue'
export function createModrinthClient(
auth: Ref<{ token: string | undefined }>,
config: { apiBaseUrl: string; archonBaseUrl: string; rateLimitKey?: string },
): NuxtModrinthClient {
const optionalFeatures = [
import.meta.dev ? (new VerboseLoggingFeature() as AbstractFeature) : undefined,
].filter(Boolean) as AbstractFeature[]
const clientConfig: NuxtClientConfig = {
labrinthBaseUrl: config.apiBaseUrl,
archonBaseUrl: config.archonBaseUrl,
rateLimitKey: config.rateLimitKey,
features: [
// for modrinth hosting
// is skipped for normal reqs
new NodeAuthFeature({
getAuth: () => nodeAuthState.getAuth?.() ?? null,
refreshAuth: async () => {
if (nodeAuthState.refreshAuth) {
await nodeAuthState.refreshAuth()
}
},
}),
new AuthFeature({
token: async () => auth.value.token,
} as AuthConfig),
new CircuitBreakerFeature({
storage: new NuxtCircuitBreakerStorage(),
maxFailures: 3,
resetTimeout: 30000,
}),
new PanelVersionFeature(),
...optionalFeatures,
],
}
return new NuxtModrinthClient(clientConfig)
}