mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
refactor(schema): simplify validation and OpenAPI generation (#2709)
This commit is contained in:
@@ -118,6 +118,7 @@ WORKDIR /usr/src/app
|
||||
COPY Cargo.lock ./
|
||||
COPY fluxer_common/ fluxer_common/
|
||||
COPY fluxer_app_proxy/ fluxer_app_proxy/
|
||||
COPY packages/constants/src/AgeGeos.json packages/constants/src/AgeGeos.json
|
||||
|
||||
RUN printf '%s\n' \
|
||||
'[workspace]' \
|
||||
|
||||
@@ -2,6 +2,28 @@
|
||||
|
||||
use crate::config::AppProxyConfig;
|
||||
use fluxer_common::geoip::{GeoipConfig, GeoipLookup, GeoipResolver};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct GeoEntry {
|
||||
country_code: String,
|
||||
region_code: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct AgeGeos {
|
||||
age_restricted_geos: Vec<GeoEntry>,
|
||||
age_blocked_geos: Vec<GeoEntry>,
|
||||
}
|
||||
|
||||
static AGE_GEOS: LazyLock<AgeGeos> = LazyLock::new(|| {
|
||||
serde_json::from_str(include_str!("../../packages/constants/src/AgeGeos.json")).expect(
|
||||
"bundled packages/constants/src/AgeGeos.json must contain a valid age geography policy",
|
||||
)
|
||||
});
|
||||
|
||||
pub fn resolver_from_app_config(config: &AppProxyConfig) -> GeoipResolver {
|
||||
GeoipResolver::from_config(&GeoipConfig {
|
||||
@@ -18,12 +40,7 @@ pub fn build_geoip_response(lookup: GeoipLookup) -> serde_json::Value {
|
||||
"regionCode": lookup.region_code,
|
||||
"latitude": lookup.latitude.map(|v| v.to_string()),
|
||||
"longitude": lookup.longitude.map(|v| v.to_string()),
|
||||
"ageRestrictedGeos": [
|
||||
{"countryCode": "GB", "regionCode": null},
|
||||
{"countryCode": "BR", "regionCode": null}
|
||||
],
|
||||
"ageBlockedGeos": [
|
||||
{"countryCode": "US", "regionCode": "MS"}
|
||||
]
|
||||
"ageRestrictedGeos": &AGE_GEOS.age_restricted_geos,
|
||||
"ageBlockedGeos": &AGE_GEOS.age_blocked_geos,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user