Skip to content

Commit

Permalink
Update fb_tbl.R
Browse files Browse the repository at this point in the history
Add lines to detect user's ip, if the ip is in China, use the mirror site
  • Loading branch information
guohuansu authored Nov 20, 2024
1 parent f503885 commit d094114
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions R/fb_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}") |>
Expand All @@ -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() |>
Expand Down

0 comments on commit d094114

Please sign in to comment.