Implement Labrinth Canary API flag (#5531)

This commit is contained in:
aecsocket
2026-03-11 15:28:09 +00:00
committed by GitHub
parent 086508be23
commit 3b21944a75
7 changed files with 71 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
let cachedRateLimitKey = undefined
let rateLimitKeyPromise = undefined
const LABRINTH_CANARY_COOKIE = 'labrinth-canary=always'
async function getRateLimitKey(config) {
if (config.rateLimitKey) return config.rateLimitKey
@@ -38,6 +39,15 @@ export const useBaseFetch = async (url, options = {}, skipAuth = false) => {
options.headers['x-ratelimit-key'] = await getRateLimitKey(config)
}
if (useFeatureFlags().value.labrinthApiCanary) {
const existingCookie = options.headers.cookie
if (!existingCookie?.split('; ').includes(LABRINTH_CANARY_COOKIE)) {
options.headers.cookie = existingCookie
? `${existingCookie}; ${LABRINTH_CANARY_COOKIE}`
: LABRINTH_CANARY_COOKIE
}
}
if (!skipAuth) {
const auth = await useAuth()