diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 00000000..38b0771d --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 0.3.0 +Date: 2024-09-04 18:50:37 UTC +SHA: 2e2c8869b54029acd6270eadee13cddb8967765c diff --git a/NAMESPACE b/NAMESPACE index f48865c7..612deb16 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -106,6 +106,7 @@ export(repo_check_branches) export(repo_check_branches_ref) export(repo_check_manifest_dirs) export(schedule_describe) +export(set_content_image) export(set_content_tag_tree) export(set_content_tags) export(set_environment_all) diff --git a/NEWS.md b/NEWS.md index 005e4936..201b508d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # Unreleased +## Breaking changes + +- `set_image_path()`, `set_image_url()`, and `set_image_webshot()` have been + deprecated and will be removed in a future update. They have been replaced by + `set_content_image(content, path)`, which works both with local file paths and + remote URLs to images. + ## Enhancements and fixes - Fixed a bug where timestamps from Connect not in UTC were parsed as `NA` (#290) diff --git a/R/deploy.R b/R/deploy.R index 219dd905..58460490 100644 --- a/R/deploy.R +++ b/R/deploy.R @@ -487,49 +487,65 @@ has_image <- function(content) { #' #' Set the Content Image using a variety of methods. #' -#' NOTE: `set_image_webshot()` requires [webshot2::webshot()], but currently -#' skips and warns for any content that requires authentication until the -#' `webshot2` package supports authentication. -#' #' @param content A content object -#' @param path The path to an image on disk -#' @param url The url for an image -#' @param ... Additional arguments passed on to [webshot2::webshot()] +#' @param path A file path or URL to an image #' -#' @rdname set_image #' @family content functions +#' @rdname set_content_image #' @export -set_image_path <- function(content, path) { - warn_experimental("set_image_path") +set_content_image <- function(content, path) { + warn_experimental("set_content_image") validate_R6_class(content, "Content") - guid <- content$get_content()$guid + valid_path <- NULL + if (file.exists(path)) { + valid_path <- path + } else { + parsed <- httr::parse_url(path) + if (parsed$scheme %in% c("http", "https")) { + valid_path <- fs::file_temp(pattern = "image", ext = fs::path_ext(parsed[["path"]])) + httr::GET(url, httr::write_disk(valid_path)) + on.exit(unlink(valid_path)) + } + } + if (is.null(valid_path)) { + stop("Could not locate image at `path`") + } + + guid <- content$get_content()$guid con <- content$get_connect() res <- con$POST( path = unversioned_url("applications", guid, "image"), - body = httr::upload_file(path) + body = httr::upload_file(valid_path) ) # return the input (in case it inherits more than just Content) content } -#' @rdname set_image + +#' @rdname set_content_image #' @export -set_image_url <- function(content, url) { - warn_experimental("set_image_url") - validate_R6_class(content, "Content") - parsed_url <- httr::parse_url(url) - imgfile <- fs::file_temp(pattern = "image", ext = fs::path_ext(parsed_url[["path"]])) - httr::GET(url, httr::write_disk(imgfile)) +set_image_path <- function(content, path) { + lifecycle::deprecate_warn("0.3.1", "set_image_path()", "set_content_image()") + set_content_image(content, path) +} - set_image_path(content = content, path = imgfile) + +#' @rdname set_content_image +#' @export +set_image_url <- function(content, path) { + lifecycle::deprecate_warn("0.3.1", "set_image_url()", "set_content_image()") + set_content_image(content, path) } -#' @rdname set_image + + +#' @rdname set_content_image #' @export set_image_webshot <- function(content, ...) { + lifecycle::deprecate_warn("0.3.1", "set_image_webshot()", "set_content_image()") warn_experimental("set_image_webshot") validate_R6_class(content, "Content") imgfile <- fs::file_temp(pattern = "webshot", ext = ".png") @@ -561,7 +577,7 @@ set_image_webshot <- function(content, ...) { !!!args )) - set_image_path(content = content, path = imgfile) + set_content_image(content = content, path = imgfile) } diff --git a/README.Rmd b/README.Rmd index bf1eaf7c..ff62563b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -111,15 +111,15 @@ content <- client %>% # set an image for content content %>% - set_image_path("./my/local/image.png") + set_content_image("./my/local/image.png") content %>% - set_image_url("http://url.example.com/image.png") + set_content_image("http://url.example.com/image.png") # set image and a vanity URL content %>% - set_image_path("./my/local/image.png") %>% + set_content_image("./my/local/image.png") %>% set_vanity_url("/my-awesome-app") # change access_type to "anyone" diff --git a/README.md b/README.md index f77dba0b..fe2a6a41 100644 --- a/README.md +++ b/README.md @@ -106,15 +106,15 @@ content <- client %>% # set an image for content content %>% - set_image_path("./my/local/image.png") + set_content_image("./my/local/image.png") content %>% - set_image_url("http://url.example.com/image.png") + set_content_image("http://url.example.com/image.png") # set image and a vanity URL content %>% - set_image_path("./my/local/image.png") %>% + set_content_image("./my/local/image.png") %>% set_vanity_url("/my-awesome-app") # change access_type to "anyone" diff --git a/man/content_delete.Rd b/man/content_delete.Rd index 8431be54..8c82ad2a 100644 --- a/man/content_delete.Rd +++ b/man/content_delete.Rd @@ -35,7 +35,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/content_item.Rd b/man/content_item.Rd index 41dcd50f..be0a7a87 100644 --- a/man/content_item.Rd +++ b/man/content_item.Rd @@ -41,7 +41,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/content_title.Rd b/man/content_title.Rd index 3b4d2cbd..fe73afca 100644 --- a/man/content_title.Rd +++ b/man/content_title.Rd @@ -37,7 +37,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/content_update.Rd b/man/content_update.Rd index 8611a525..aee3bfbf 100644 --- a/man/content_update.Rd +++ b/man/content_update.Rd @@ -57,7 +57,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/create_random_name.Rd b/man/create_random_name.Rd index 8572693b..8ac19bbc 100644 --- a/man/create_random_name.Rd +++ b/man/create_random_name.Rd @@ -34,7 +34,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/dashboard_url.Rd b/man/dashboard_url.Rd index e7e4125d..9ae2c6a6 100644 --- a/man/dashboard_url.Rd +++ b/man/dashboard_url.Rd @@ -34,7 +34,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/dashboard_url_chr.Rd b/man/dashboard_url_chr.Rd index 350f125d..be5e14b6 100644 --- a/man/dashboard_url_chr.Rd +++ b/man/dashboard_url_chr.Rd @@ -37,7 +37,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/delete_vanity_url.Rd b/man/delete_vanity_url.Rd index b0347f1e..c72b6976 100644 --- a/man/delete_vanity_url.Rd +++ b/man/delete_vanity_url.Rd @@ -29,7 +29,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/deploy_repo.Rd b/man/deploy_repo.Rd index e6718de5..5c807dcc 100644 --- a/man/deploy_repo.Rd +++ b/man/deploy_repo.Rd @@ -71,7 +71,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/environment.Rd b/man/environment.Rd index 0b74d1d8..4544310a 100644 --- a/man/environment.Rd +++ b/man/environment.Rd @@ -54,7 +54,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/get_bundles.Rd b/man/get_bundles.Rd index 8a1ea282..7ee61104 100644 --- a/man/get_bundles.Rd +++ b/man/get_bundles.Rd @@ -34,7 +34,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, @@ -56,7 +56,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/get_image.Rd b/man/get_image.Rd index 75001ebd..15bea7cc 100644 --- a/man/get_image.Rd +++ b/man/get_image.Rd @@ -40,7 +40,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/get_vanity_url.Rd b/man/get_vanity_url.Rd index 3c601e04..14492a4f 100644 --- a/man/get_vanity_url.Rd +++ b/man/get_vanity_url.Rd @@ -32,7 +32,7 @@ Other content functions: \code{\link{get_jobs}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/git.Rd b/man/git.Rd index 08ab0c44..d8c5ef30 100644 --- a/man/git.Rd +++ b/man/git.Rd @@ -55,7 +55,7 @@ Other content functions: \code{\link{get_jobs}()}, \code{\link{get_vanity_url}()}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/jobs.Rd b/man/jobs.Rd index 4de6bfd5..52386a20 100644 --- a/man/jobs.Rd +++ b/man/jobs.Rd @@ -35,7 +35,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/permissions.Rd b/man/permissions.Rd index 7c40964a..c49d1a9b 100644 --- a/man/permissions.Rd +++ b/man/permissions.Rd @@ -79,7 +79,7 @@ Other content functions: \code{\link{get_jobs}()}, \code{\link{get_vanity_url}()}, \code{\link{git}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, diff --git a/man/set_image.Rd b/man/set_content_image.Rd similarity index 70% rename from man/set_image.Rd rename to man/set_content_image.Rd index fa72993f..0907d64c 100644 --- a/man/set_image.Rd +++ b/man/set_content_image.Rd @@ -1,35 +1,32 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/deploy.R -\name{set_image_path} +\name{set_content_image} +\alias{set_content_image} +\alias{set_image_webshot} \alias{set_image_path} \alias{set_image_url} -\alias{set_image_webshot} \title{Set the Content Image} \usage{ -set_image_path(content, path) +set_content_image(content, path) -set_image_url(content, url) +set_image_webshot(content, ...) set_image_webshot(content, ...) + +set_image_path(content, path) + +set_image_url(content, path) } \arguments{ \item{content}{A content object} -\item{path}{The path to an image on disk} - -\item{url}{The url for an image} - -\item{...}{Additional arguments passed on to \code{\link[webshot2:webshot]{webshot2::webshot()}}} +\item{path}{A file path or URL to an image} } \description{ \lifecycle{experimental} } \details{ Set the Content Image using a variety of methods. - -NOTE: \code{set_image_webshot()} requires \code{\link[webshot2:webshot]{webshot2::webshot()}}, but currently -skips and warns for any content that requires authentication until the -\code{webshot2} package supports authentication. } \seealso{ Other content functions: diff --git a/man/set_run_as.Rd b/man/set_run_as.Rd index 060c584e..673d0853 100644 --- a/man/set_run_as.Rd +++ b/man/set_run_as.Rd @@ -53,7 +53,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()}, \code{\link{verify_content_name}()} diff --git a/man/set_vanity_url.Rd b/man/set_vanity_url.Rd index 41d95427..8fe3a08a 100644 --- a/man/set_vanity_url.Rd +++ b/man/set_vanity_url.Rd @@ -46,7 +46,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{swap_vanity_url}()}, \code{\link{verify_content_name}()} diff --git a/man/swap_vanity_url.Rd b/man/swap_vanity_url.Rd index 69126ae0..83aaac9b 100644 --- a/man/swap_vanity_url.Rd +++ b/man/swap_vanity_url.Rd @@ -32,7 +32,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{verify_content_name}()} diff --git a/man/verify_content_name.Rd b/man/verify_content_name.Rd index 7219bee7..fcc28005 100644 --- a/man/verify_content_name.Rd +++ b/man/verify_content_name.Rd @@ -38,7 +38,7 @@ Other content functions: \code{\link{get_vanity_url}()}, \code{\link{git}}, \code{\link{permissions}}, -\code{\link{set_image_path}()}, +\code{\link{set_content_image}()}, \code{\link{set_run_as}()}, \code{\link{set_vanity_url}()}, \code{\link{swap_vanity_url}()} diff --git a/tests/integrated/test-deploy.R b/tests/integrated/test-deploy.R index 029c6ea8..b29c0061 100644 --- a/tests/integrated/test-deploy.R +++ b/tests/integrated/test-deploy.R @@ -165,11 +165,11 @@ test_that("deploy_current works", { # image --------------------------------------------------- -test_that("set_image_path works", { +test_that("set_content_image works with local images", { scoped_experimental_silence() img_path <- rprojroot::find_package_root_file("tests/testthat/examples/logo.png") - res <- set_image_path(cont1_content, img_path) + res <- set_content_image(cont1_content, img_path) expect_true(validate_R6_class(res, "Content")) }) @@ -244,37 +244,16 @@ test_that("get_image returns NA if no image", { expect_true(is.na(response)) }) -test_that("set_image_url works", { +test_that("set_content_image works with remote paths", { scoped_experimental_silence() - res <- set_image_url(cont1_content, glue::glue("{cont1_content$get_connect()$server}/connect/__favicon__")) + res <- set_content_image(cont1_content, glue::glue("{cont1_content$get_connect()$server}/connect/__favicon__")) expect_true(validate_R6_class(res, "Content")) # TODO: verify round-trip on the image is actually correct... SHA? }) -test_that("set_image_webshot works", { - skip("test fails commonly in CI") - scoped_experimental_silence() - cont1_content$update(access_type = "all") - res <- set_image_webshot(cont1_content) - - expect_true(validate_R6_class(res, "Content")) - # TODO: verify round-trip on the image is actually correct... SHA? - - # returns content even when it cannot take the webshot - cont1_content$update(access_type = "acl") - expect_warning( - { - res <- set_image_webshot(cont1_content) - }, - "authentication" - ) - - expect_true(validate_R6_class(res, "Content")) -}) - # vanity_url --------------------------------------------------- test_that("set_vanity_url works", { diff --git a/vignettes/getting-started.Rmd b/vignettes/getting-started.Rmd index 8455400e..333cf5be 100644 --- a/vignettes/getting-started.Rmd +++ b/vignettes/getting-started.Rmd @@ -82,7 +82,7 @@ while you wait for deployment to complete: ```r content_1 %>% - set_image_url("https://gph.is/29vyb0s") %>% + set_content_image("https://gph.is/29vyb0s") %>% set_vanity_url("/my_clever_content") # ensure the vanity URL is set as expected