feat: imgur proxying for blocked countries (#7104)

This commit is contained in:
Calum H.
2026-08-11 16:40:03 +00:00
committed by GitHub
parent 26e05ee9e5
commit 2d567b93ce
12 changed files with 167 additions and 37 deletions
+2
View File
@@ -32,6 +32,7 @@ import { LabrinthCollectionsModule } from './labrinth/collections'
import { LabrinthContentV3Module } from './labrinth/content/v3'
import { LabrinthExternalProjectsInternalModule } from './labrinth/external-projects/internal'
import { LabrinthFriendsV3Module } from './labrinth/friends/v3'
import { LabrinthGeoIpModule } from './labrinth/geoip'
import { LabrinthGlobalsInternalModule } from './labrinth/globals/internal'
import { LabrinthImagesV3Module } from './labrinth/images/v3'
import { LabrinthLimitsV3Module } from './labrinth/limits/v3'
@@ -111,6 +112,7 @@ export const MODULE_REGISTRY = {
labrinth_content_v3: LabrinthContentV3Module,
labrinth_external_projects_internal: LabrinthExternalProjectsInternalModule,
labrinth_friends_v3: LabrinthFriendsV3Module,
labrinth_geoip: LabrinthGeoIpModule,
labrinth_globals_internal: LabrinthGlobalsInternalModule,
labrinth_images_v3: LabrinthImagesV3Module,
labrinth_moderation_internal: LabrinthModerationInternalModule,
@@ -0,0 +1,23 @@
import { AbstractModule } from '../../core/abstract-module'
export class LabrinthGeoIpModule extends AbstractModule {
public getModuleID(): string {
return 'labrinth_geoip'
}
public async getCountry(): Promise<string | undefined> {
const trace = await this.client.request<string>('/trace', {
api: 'https://api.modrinth.com',
version: 'cdn-cgi',
method: 'GET',
skipAuth: true,
})
const country = trace
.split('\n')
.find((line) => line.startsWith('loc='))
?.slice(4)
.toUpperCase()
return country?.match(/^[A-Z]{2}$/) ? country : undefined
}
}
@@ -8,6 +8,7 @@ export * from './collections'
export * from './content/v3'
export * from './external-projects/internal'
export * from './friends/v3'
export * from './geoip'
export * from './globals/internal'
export * from './images/v3'
export * from './limits/v3'