nu-modules/filestore.nu

34 lines
886 B
Plaintext

use std log
# upload documents to filestore and returns the location
export def put [glob:string,
--product:string="xs",
--tenantId:string="0000016",
] {
expand-glob $glob
| par-each { |x|
let location = (put-single $x.name $x.type (random uuid) $product $tenantId)
{
file: $x.name,
location: $location
}
} | flatten
}
def put-single [
document:path,
content_type:string,
container_id:string,
product:string,
tenantId:string,
] {
log debug $"Uploading file ($document) of type ($content_type)"
let filename = ($document | path basename)
http post -H ["Content-Type", $content_type] $"http://localhost:8300/api/v1/($product)/($tenantId)/($container_id)/($filename)" $document
}
def expand-glob [glob:string] {
glob -D $glob
| each {|x| ls --mime-type $x | first}
}