export def serve [ 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 ] { let endpoint = if $public { "http://privserve" } else { "http://files" } let url = if $public { "http://pubserve.serval-vibes.ts.net" } else { "http://files" } let upload = $"($endpoint)/upload" let baseName = $path | path basename let cleanDir = if $dir != null { $"($dir | str trim --char '/')" } else { "" } # When uploading, "" is invalid. It must either be "/" or relative "foo/bar/" let uploadDir = $"($cleanDir)/" let serveDir = if $cleanDir != "" { $uploadDir } else { "" } if ($path | path type) == "dir" { let prefix = $path | path expand print "dirs" glob -F $"($prefix)/**" | each {|g| let b = $g | str replace $prefix "" print $b } print "files" glob -D $"($prefix)/**" | each {|g| let f = $g | str replace $prefix "" print $f } } else { ^curl -F $"mkdir=($uploadDir)" $"($upload)?path=/" ^curl -F $"path=@($path)" $"($upload)?path=($uploadDir)" } $"($url)/($serveDir)($baseName)" }