diff --git a/DESCRIPTION b/DESCRIPTION index 025399c..89ba517 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,5 +42,5 @@ Imports: jsonlite, HARtools, lubridate -RoxygenNote: 6.0.0 +RoxygenNote: 6.0.1 Remotes: wch/harbor diff --git a/NEWS.md b/NEWS.md index 6812531..50f12ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * added HAR support * added `as_req()` * added `as_request()` +* added `wait` value range check for `render_` functions (min 0, max 10) 0.2.0 diff --git a/R/aaa.r b/R/aaa.r index a414d96..2b5a0a6 100644 --- a/R/aaa.r +++ b/R/aaa.r @@ -13,4 +13,16 @@ parse_query <- function(query) { FUN.VALUE=character(2)) purrr::set_names(as.list(curl::curl_unescape(params[2,])), curl::curl_unescape(params[1,])) +} + +check_wait <- function(wait) { + if (wait<0) { + message("The 'wait' parameter cannot be less than 0; auto-changing it to 0") + wait <- 0 + } else if (wait>10) { + message("The 'wait' parameter cannot be greater than 10 in render_... calls; auto-changing it to 10") + message("Use the direct lua interface or lua DSL wrapper functions to set higher 'wait' vales.") + wait <- 10 + } + wait } \ No newline at end of file diff --git a/R/render-har.r b/R/render-har.r index 586e07c..97cefd9 100644 --- a/R/render-har.r +++ b/R/render-har.r @@ -14,6 +14,8 @@ render_har <- function(splash_obj = splash_local, url, base_url, response_body=F forbidden_content_types, viewport="1024x768", images, headers, body, http_method, save_args, load_args) { + wait <- check_wait(wait) + params <- list(url=url, timeout=timeout, wait=wait, viewport=jsonlite::unbox(viewport), response_body=as.numeric(response_body)) diff --git a/R/render-html.r b/R/render-html.r index 66d3d27..d9ef5d3 100644 --- a/R/render-html.r +++ b/R/render-html.r @@ -35,6 +35,8 @@ render_html <- function(splash_obj = splash_local, url, base_url, timeout=30, re forbidden_content_types, viewport="1024x768", images, headers, body, http_method, save_args, load_args, raw_html=FALSE) { + wait <- check_wait(wait) + params <- list(url=url, timeout=timeout, wait=wait, viewport=jsonlite::unbox(viewport)) if (!missing(base_url)) params$base_url <- jsonlite::unbox(base_url) diff --git a/R/render-jpg.r b/R/render-jpg.r index 6b8b2a6..4c06d32 100644 --- a/R/render-jpg.r +++ b/R/render-jpg.r @@ -14,6 +14,8 @@ render_jpeg <- render_jpg <- function( forbidden_content_types, viewport="full", images, headers, body, http_method, save_args, load_args) { + wait <- check_wait(wait) + params <- list(url=url, timeout=timeout, wait=if (render_all & wait == 0) 0.5 else wait, viewport=viewport, diff --git a/R/render-json.r b/R/render-json.r index 027684c..70376c0 100644 --- a/R/render-json.r +++ b/R/render-json.r @@ -35,6 +35,8 @@ render_json <- function(splash_obj = splash_local, url, base_url=NULL, quality=7 iframes=TRUE, script=TRUE, console=TRUE, history=TRUE, har=TRUE, response_body=FALSE) { + wait <- check_wait(wait) + params <- list(url=url, timeout=timeout, wait=wait, viewport=jsonlite::unbox(viewport), quality=quality, render_all=as.numeric(render_all), html=as.numeric(html), png=as.numeric(png), jpeg=as.numeric(jpeg), diff --git a/R/render-png.r b/R/render-png.r index 31b3558..a755e35 100644 --- a/R/render-png.r +++ b/R/render-png.r @@ -14,6 +14,8 @@ render_png <- function( forbidden_content_types, viewport="full", images, headers, body, http_method, save_args, load_args) { + wait <- check_wait(wait) + params <- list(url=url, timeout=timeout, wait=if (render_all & wait == 0) 0.5 else wait, viewport=jsonlite::unbox(viewport), diff --git a/R/render_file.R b/R/render_file.R index b46497a..86e3094 100644 --- a/R/render_file.R +++ b/R/render_file.R @@ -16,6 +16,8 @@ #' @export render_file <- function(splash_obj = splash_local, file_path, output=c("html", "png"), wait=0, viewport="1024x768", ...) { + wait <- check_wait(wait) + output <- match.arg(output, c("html", "png")) file.copy(file_path, .pkgenv$temp_dir)