diff --git a/DESCRIPTION b/DESCRIPTION index 6a9212de..aca7da6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -96,4 +96,4 @@ Remotes: Encoding: UTF-8 Language: en-GB LazyData: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/R/flywire-urls.R b/R/flywire-urls.R index a16b8b46..d7564c13 100644 --- a/R/flywire-urls.R +++ b/R/flywire-urls.R @@ -91,13 +91,17 @@ flywire_shortenurl <- function(x, include_base=TRUE, baseurl=NULL, cache=TRUE, . #' \code{flywire_expandurl} will also expand tinyurl.com URLs as well as those #' referencing a json fragment on a google cloud bucket (such as the flyem #' link shortener). If a tinyurl.com URL maps to a short URL referencing a -#' json fragment, then they will successively be expanded. +#' json fragment, then they will successively be expanded unless +#' \code{follow=FALSE}. #' #' Finally, if the URL is actually already expanded, then this will be #' returned unmodified. This is a change in behaviour as of May 2024 #' (previously an error was thrown). +#' #' @param json.only Only return the JSON fragment rather than the neuroglancer -#' URL +#' URL. Defaults to \code{FALSE}. +#' @param follow Whether to follow short URLs that specify other short URLs (see +#' details). Defaults to \code{TRUE}. #' @export #' #' @examples @@ -109,7 +113,7 @@ flywire_shortenurl <- function(x, include_base=TRUE, baseurl=NULL, cache=TRUE, . #' flywire_expandurl("https://tinyurl.com/flywirehb2") #' } #' @rdname flywire_shortenurl -flywire_expandurl <- function(x, json.only=FALSE, cache=TRUE, ...) { +flywire_expandurl <- function(x, json.only=FALSE, cache=TRUE, follow=TRUE, ...) { checkmate::assert_character(x, pattern="^http[s]{0,1}://") if(length(x)>1) { res=pbapply::pbsapply(x, flywire_expandurl, json.only=json.only, cache=cache, ...) @@ -123,6 +127,8 @@ flywire_expandurl <- function(x, json.only=FALSE, cache=TRUE, ...) { if(grepl("comsync.lijit.com", url, fixed = T)) url=httr::GET(url, config(followlocation=TRUE))$url x=url + if(!follow) + return(x) } if(isFALSE(su <- shorturl(url))) { diff --git a/man/flywire_shortenurl.Rd b/man/flywire_shortenurl.Rd index 5e321b09..a3d50a12 100644 --- a/man/flywire_shortenurl.Rd +++ b/man/flywire_shortenurl.Rd @@ -7,7 +7,7 @@ \usage{ flywire_shortenurl(x, include_base = TRUE, baseurl = NULL, cache = TRUE, ...) -flywire_expandurl(x, json.only = FALSE, cache = TRUE, ...) +flywire_expandurl(x, json.only = FALSE, cache = TRUE, follow = TRUE, ...) } \arguments{ \item{x}{One or more neuroglancer URLs or (for flywire_expandurl) @@ -30,7 +30,10 @@ generating a short URL for an \code{ngscene} list object) \emph{or} to \code{flywire_fetch} when using \code{flywire_expandurl}.} \item{json.only}{Only return the JSON fragment rather than the neuroglancer -URL} +URL. Defaults to \code{FALSE}.} + +\item{follow}{Whether to follow short URLs that specify other short URLs (see +details). Defaults to \code{TRUE}.} } \value{ A character vector containing one or more URLs. @@ -51,7 +54,8 @@ A character vector containing one or more URLs. \code{flywire_expandurl} will also expand tinyurl.com URLs as well as those referencing a json fragment on a google cloud bucket (such as the flyem link shortener). If a tinyurl.com URL maps to a short URL referencing a - json fragment, then they will successively be expanded. + json fragment, then they will successively be expanded unless + \code{follow=FALSE}. Finally, if the URL is actually already expanded, then this will be returned unmodified. This is a change in behaviour as of May 2024 diff --git a/tests/testthat/test-urls.R b/tests/testthat/test-urls.R index 7d2f21e1..f6fa5f31 100644 --- a/tests/testthat/test-urls.R +++ b/tests/testthat/test-urls.R @@ -60,6 +60,12 @@ test_that("we can work round toJSON array issue",{ hostname(fu)) }) +test_that('we can expand neuroglancer URLs without following', { + expect_equal( + flywire_expandurl('https://tinyurl.com/NeckConnective', follow = FALSE), + "https://neuroglancer-demo.appspot.com/#!gs://flyem-user-links/short/NeckConnective.json" + ) +}) test_that('we can make a neuroglancer URL', { catmaid_url <- "https://fafb.catmaid.virtualflybrain.org/?pid=2&zp=131280&yp=170014.98879622458&xp=426584.81386896875&tool=navigator&sid0=2&s0=-1"