Skip to content

Commit

Permalink
zenodo namespaces hash algo now
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Jan 21, 2025
1 parent a3ffbe4 commit 6a8811b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: contentid
Version: 0.0.18
Version: 0.0.19
Title: An Interface for Content-Based Identifiers
Description: An interface for creating, registering, and resolving content-based
identifiers for data management. Content-based identifiers rely on
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# contentid 0.0.19

* Patch parsing for further changes to Zenodo API
* handle un-padded base64 from ni:// standard safely (for openssl 4.0)

# contentid 0.0.18

* Patch parsing for new Zenodo API
Expand Down
22 changes: 14 additions & 8 deletions R/zenodo_registry.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# md5 only for now
# id <- "hash://md5/eb5e8f37583644943b86d1d9ebd4ded5"
# sources_zenodo(id)
sources_zenodo <- function(id, host = "https://zenodo.org"){
query <- "/api/records?q=files.entries.checksum:"
hash <- strip_prefix(id)
algo <- extract_algo(id)

if(!grepl("md5", algo)){
if(getOption("verbose", FALSE))
message("Zenodo only supports MD5 checksums at this time")
return(null_query())
}
# if(!grepl("md5", algo)){
# if(getOption("verbose", FALSE))
# message("Zenodo only supports MD5 checksums at this time")
# return(null_query())
# }

checksum <- curl::curl_escape(paste0('"', algo, ":", hash, '"'))
url <- paste0(host, query, checksum, '&allversions=true')
Expand Down Expand Up @@ -38,11 +39,16 @@ sources_zenodo <- function(id, host = "https://zenodo.org"){

## The associated record may also have other files, match by id:
ids <- vapply(matches$files, `[[`, character(1L), "checksum")
item <- matches$files[ids == hash]
raw_ids <- gsub("\\w+:", "", ids)
item <- matches$files[raw_ids == hash]

if(length(item) != 1) {
stop(paste("ids", paste0(ids, collapse=", "), "not matching hash", hash))
}
file <- item[[1]]

download_url <- file$links$download
size <- file$filesize
download_url <- file$links$self
size <- file$size
date <- matches$created
out <- registry_entry(id, source = download_url, size =size, date = date)
out
Expand Down

0 comments on commit 6a8811b

Please sign in to comment.