Skip to contents

Produces one attach row per local file for the guarded flow: zotPreview(), zotApprove(), zotExecute() and zotVerify(). Files whose MD5 is already an attachment of the same parent are omitted.

Usage

ztAttachPlan(config, files, library = "user")

Arguments

config

A zotConfig() object.

files

A data.table with path and parentKey (NA for a standalone attachment) and, optionally, filename, contentType and charset; NA in an optional column takes the default.

library

"user" or a group id.

Value

A guarded-flow plan of attach rows, empty when every file is already attached.

Details

Every file is checked before any request: a missing or empty file is refused with a zotPlanError. Each row records the file's md5 and filesize, so the approval of its preview binds the exact bytes. The stored filename is cleaned with ztCleanName(); contentType and charset default to the choice ztAttach() documents. The path is kept as given, and a relative path is resolved against the working directory of execution.

Planning reads the children of each distinct parent once through zotListItems() and omits the rows whose MD5 is already attached there, with a message per omitted file. A parent whose children exceed one listing page is refused with a zotBoundError, because the omission could not see every attachment. Standalone files are not compared. Planning does not write.

Examples

Path <- tempfile(fileext = ".md")
writeLines("# Notes", Path)
Performer <- function(config, method, path, query, body, version) {
  list(status = 200L,
       headers = list(`total-results` = "0", `last-modified-version` = "7"),
       body = list())
}
Config <- zotConfig(userID = "42", key = "example", performer = Performer)
Files <- data.table::data.table(path = Path, parentKey = "PARENT1")
Plan <- ztAttachPlan(Config, files = Files, library = "user")
Plan$payload[[1L]]$contentType
#> [1] "text/markdown"
unlink(Path)