Skip to content

Commit

Permalink
Add get_file_versions() in favour of list_file_versions()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Jul 26, 2024
1 parent 5e2f3f9 commit 00b0651
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ Remotes:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(create_folder)
export(delete_file_or_folder)
export(download_files)
export(file_exists)
export(get_file_versions)
export(get_version_info)
export(list_file_versions)
export(list_files)
Expand Down
39 changes: 30 additions & 9 deletions R/list_file_versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,41 @@
#'
list_file_versions <- function(path, pattern = NULL, ...)
{
file_info <- kwb.nextcloud::list_files(path, pattern, full_info = TRUE, ...)
kwb.utils::warningDeprecated("list_file_versions", "get_file_versions")

version_info <- kwb.nextcloud::get_version_info(file_info$fileid)
file_info <- list_files(path, pattern, full_info = TRUE, ...)
get_file_versions(file_info)
}

# get_file_versions ------------------------------------------------------------

#' Get Information on Versions of Given Files
#'
#' @param file_info data frame as returned by \code{\link{list_files}} when
#' being called with \code{full_info = TRUE}
#' @returns data frame
#' @importFrom kwb.utils moveColumnsToFront selectColumns
#' @export
get_file_versions <- function(file_info)
{
# Remove information on directories
file_info <- file_info[!kwb.utils::selectColumns(file_info, "is_dir"), ]

columns_x <- c("fileid", "file", "lastmodified", "etag")
columns_y <- c("fileid", "version", "href")
# Get version information for the remaining files
file_ids <- kwb.utils::selectColumns(file_info, "fileid")
version_info <- get_version_info(file_ids)

columns_file_info <- c("fileid", "file", "lastmodified", "etag")
columns_version_info <- c("fileid", "version", "href")

result <- merge(
kwb.utils::selectColumns(file_info, columns_x),
kwb.utils::selectColumns(version_info, columns_y),
x = kwb.utils::selectColumns(file_info, columns_file_info),
y = kwb.utils::selectColumns(version_info, columns_version_info),
by = "fileid"
)

kwb.utils::moveColumnsToFront(result, columns = c(
"fileid", "file", "version"
))
kwb.utils::moveColumnsToFront(
result,
columns = c("fileid", "file", "version")
)
}
18 changes: 18 additions & 0 deletions man/get_file_versions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00b0651

Please sign in to comment.