Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

* Further escalated gradual deprecation process for legacy pins functions such as `pin()` (#879).

* Added support for `pin_list()` to `board_gcs()` for Google Cloud Storage (#889, @sverrirarnors).

# pins 1.4.1

* Support new `preview_data` parameter for pin previews on Posit Connect (#850).
Expand Down
31 changes: 30 additions & 1 deletion R/board_gcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,26 @@ secret_nonce <- function() {

#' @export
pin_list.pins_board_gcs <- function(board, ...) {
NA
resp <- googleCloudStorageR::gcs_list_objects(
bucket = board$bucket,
prefix = board$prefix
)

if (nrow(resp) == 0) {
return(character(0))
}

# Strip prefix and extract pin names (first path component)
paths <- strip_prefix(resp$name, board$prefix)

# Extract first component from each path
pin_names <- vapply(
fs::path_split(paths),
function(components) if (length(components) > 0) components[[1L]] else "",
character(1)
)

unique(sort(pin_names[pin_names != ""]))
}

#' @export
Expand Down Expand Up @@ -270,3 +289,13 @@ gcs_file_exists <- function(board, name) {
)
nrow(resp) > 0
}

strip_prefix <- function(x, prefix) {
if (is.null(prefix)) {
return(x)
}

to_strip <- startsWith(x, prefix)
x[to_strip] <- substr(x[to_strip], nchar(prefix) + 1, nchar(x[to_strip]))
x
}