diff --git a/R/fb_tbl.R b/R/fb_tbl.R index 193ab57..e5076aa 100644 --- a/R/fb_tbl.R +++ b/R/fb_tbl.R @@ -64,7 +64,20 @@ available_releases <- function(server = c("fishbase", "sealifebase")) { sv <- server_code(server) repo <- "datasets/cboettig/fishbase" path <- glue::glue("data/{sv}") +is_user_in_china <- function() { + response <- httr::GET("https://ipinfo.io") + if (httr::status_code(response) == 200) { + data <- jsonlite::fromJSON(httr::content(response, as = "text")) + country <- data$country + return(country == "CN") + } else FALSE +} + +if (is_user_in_china()) { + hf <- "https://hf-mirror.com" +} else { hf <- "https://huggingface.co" +} branch <- "main" versions <- glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> @@ -85,7 +98,20 @@ hf_urls <- function(path = "data/fb/v24.07/parquet", branch = "main" ) { +is_user_in_china <- function() { + response <- httr::GET("https://ipinfo.io") + if (httr::status_code(response) == 200) { + data <- jsonlite::fromJSON(httr::content(response, as = "text")) + country <- data$country + return(country == "CN") + } else FALSE +} + +if (is_user_in_china()) { + hf <- "https://hf-mirror.com" +} else { hf <- "https://huggingface.co" +} paths <- glue::glue("{hf}/api/{repo}/tree/{branch}/{path}") |> jsonlite::read_json() |>