moduleminiserve{exportdefserve[path:path# The path to serve
--dir(-d):string# The base dir in miniserve for the path
--public(-p)# Send to http://pubserve (via http://privserve) rather than http://files
--verbose(-v)# Print uploads
]{letendpoint=if$public{"http://privserve"}else{"http://files"}leturl=if$public{"http://pubserve.serval-vibes.ts.net"}else{"http://files"}letupload=$"($endpoint)/upload"letbaseName=$path|pathbasenameletcleanDir=if$dir!=null{$"($dir|strtrim--char'/')"}else{""}# When uploading, "" is invalid. It must either be "/" or relative "foo/bar/"
letuploadDir=$"($cleanDir)/"letserveDir=if$cleanDir!=""{$uploadDir}else{""}if($path|pathtype)=="dir"{letprefix=$path|pathexpandletbaseDir=[$cleanDir,($prefix|pathbasename|strtrim--char'/')]|pathjoinglob-F$"($prefix)/**"|each{|g|letb=$g|strreplace$prefix""|strtrim--left--char'/'letd=[$baseDir,$b]|pathjoinif$verbose{print$"Creating dir ($d)"}^curl-F$"mkdir=($d)"$"($upload)?path=/"|complete}glob-D$"($prefix)/**"|each{|g|letf=$g|strreplace$prefix""|strtrim--left--char'/'lett=[$baseDir,$f]|pathjoinletp=$t|pathdirnameif$verbose{print$"Uploading ($g) to ($t)"}^curl-F$"path=@($g)"$"($upload)?path=($p)"|complete}}else{if$verbose{print$"Creating dir ($uploadDir)"}^curl-F$"mkdir=($uploadDir)"$"($upload)?path=/"|completeif$verbose{print$"Uploading ($path|pathexpand) to ($serveDir)($baseName)"}^curl-F$"path=@($path)"$"($upload)?path=($uploadDir)"|complete}$"($url)/($serveDir)($baseName)"}}useminiserve*