mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 17:44:50 +00:00
feat: imgur proxying for blocked countries (#7104)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ISO3166 } from '@modrinth/api-client'
|
||||
import { useUserCountry as useInjectedUserCountry } from '@modrinth/ui'
|
||||
|
||||
import { useRequestHeaders, useState } from '#imports'
|
||||
import { countries, subdivisions } from '~/generated/state.json'
|
||||
|
||||
export const useCountries = () => {
|
||||
@@ -35,38 +35,4 @@ export const useSubdivisions = (countryCode: ComputedRef<string> | Ref<string> |
|
||||
return computed(() => byCountry[unref(code)] ?? [])
|
||||
}
|
||||
|
||||
export const useUserCountry = () => {
|
||||
const country = useState<string>('userCountry', () => 'US')
|
||||
const fromServer = useState<boolean>('userCountryFromServer', () => false)
|
||||
|
||||
if (import.meta.server) {
|
||||
const headers = useRequestHeaders(['cf-ipcountry', 'accept-language'])
|
||||
const cf = headers['cf-ipcountry']
|
||||
if (cf) {
|
||||
country.value = cf.toUpperCase()
|
||||
fromServer.value = true
|
||||
} else {
|
||||
const al = headers['accept-language'] || ''
|
||||
const tag = al.split(',')[0]
|
||||
const val = tag.split('-')[1]?.toLowerCase()
|
||||
if (val) {
|
||||
country.value = val
|
||||
fromServer.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.client) {
|
||||
onMounted(() => {
|
||||
if (fromServer.value) return
|
||||
// @ts-expect-error - ignore TS not knowing about navigator.userLanguage
|
||||
const lang = navigator.language || navigator.userLanguage || ''
|
||||
const region = lang.split('-')[1]
|
||||
if (region) {
|
||||
country.value = region.toUpperCase()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return country
|
||||
}
|
||||
export const useUserCountry = useInjectedUserCountry
|
||||
|
||||
Reference in New Issue
Block a user