You've already forked AstralRinth
forked from didirus/AstralRinth
fix: add x-panel-version header (#4855)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { AuthFeature, TauriModrinthClient } from '@modrinth/api-client'
|
import { AuthFeature, PanelVersionFeature, TauriModrinthClient } from '@modrinth/api-client'
|
||||||
import {
|
import {
|
||||||
ArrowBigUpDashIcon,
|
ArrowBigUpDashIcon,
|
||||||
ChangeSkinIcon,
|
ChangeSkinIcon,
|
||||||
@@ -115,6 +115,7 @@ const tauriApiClient = new TauriModrinthClient({
|
|||||||
new AuthFeature({
|
new AuthFeature({
|
||||||
token: async () => (await getCreds()).session,
|
token: async () => (await getCreds()).session,
|
||||||
}),
|
}),
|
||||||
|
new PanelVersionFeature(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
provideModrinthClient(tauriApiClient)
|
provideModrinthClient(tauriApiClient)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { PANEL_VERSION } from '@modrinth/api-client'
|
||||||
import type { V1ErrorInfo } from '@modrinth/utils'
|
import type { V1ErrorInfo } from '@modrinth/utils'
|
||||||
import { ModrinthServerError, ModrinthServersFetchError } from '@modrinth/utils'
|
import { ModrinthServerError, ModrinthServersFetchError } from '@modrinth/utils'
|
||||||
import { $fetch, FetchError } from 'ofetch'
|
import { $fetch, FetchError } from 'ofetch'
|
||||||
@@ -103,6 +104,7 @@ export async function useServersFetch<T>(
|
|||||||
const headers: Record<string, string> = {
|
const headers: Record<string, string> = {
|
||||||
'User-Agent': 'Modrinth/1.0 (https://modrinth.com)',
|
'User-Agent': 'Modrinth/1.0 (https://modrinth.com)',
|
||||||
'X-Archon-Request': 'true',
|
'X-Archon-Request': 'true',
|
||||||
|
'X-Panel-Version': String(PANEL_VERSION),
|
||||||
Vary: 'Accept, Origin',
|
Vary: 'Accept, Origin',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
NuxtCircuitBreakerStorage,
|
NuxtCircuitBreakerStorage,
|
||||||
type NuxtClientConfig,
|
type NuxtClientConfig,
|
||||||
NuxtModrinthClient,
|
NuxtModrinthClient,
|
||||||
|
PanelVersionFeature,
|
||||||
VerboseLoggingFeature,
|
VerboseLoggingFeature,
|
||||||
} from '@modrinth/api-client'
|
} from '@modrinth/api-client'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
@@ -31,6 +32,7 @@ export function createModrinthClient(
|
|||||||
maxFailures: 3,
|
maxFailures: 3,
|
||||||
resetTimeout: 30000,
|
resetTimeout: 30000,
|
||||||
}),
|
}),
|
||||||
|
new PanelVersionFeature(),
|
||||||
...optionalFeatures,
|
...optionalFeatures,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
18
packages/api-client/src/features/panel-version.ts
Normal file
18
packages/api-client/src/features/panel-version.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { AbstractFeature } from '../core/abstract-feature'
|
||||||
|
import type { RequestContext } from '../types/request'
|
||||||
|
|
||||||
|
export const PANEL_VERSION = 1
|
||||||
|
|
||||||
|
export class PanelVersionFeature extends AbstractFeature {
|
||||||
|
async execute<T>(next: () => Promise<T>, context: RequestContext): Promise<T> {
|
||||||
|
context.options.headers = {
|
||||||
|
...context.options.headers,
|
||||||
|
'X-Panel-Version': String(PANEL_VERSION),
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldApply(_: RequestContext): boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ export {
|
|||||||
type CircuitBreakerStorage,
|
type CircuitBreakerStorage,
|
||||||
InMemoryCircuitBreakerStorage,
|
InMemoryCircuitBreakerStorage,
|
||||||
} from './features/circuit-breaker'
|
} from './features/circuit-breaker'
|
||||||
|
export { PANEL_VERSION, PanelVersionFeature } from './features/panel-version'
|
||||||
export { type BackoffStrategy, type RetryConfig, RetryFeature } from './features/retry'
|
export { type BackoffStrategy, type RetryConfig, RetryFeature } from './features/retry'
|
||||||
export { type VerboseLoggingConfig, VerboseLoggingFeature } from './features/verbose-logging'
|
export { type VerboseLoggingConfig, VerboseLoggingFeature } from './features/verbose-logging'
|
||||||
export type { InferredClientModules } from './modules'
|
export type { InferredClientModules } from './modules'
|
||||||
|
|||||||
Reference in New Issue
Block a user