mirror of https://git.jolheiser.com/dotnix.git
feat: serve
Signed-off-by: jolheiser <git@jolheiser.com>
parent
c59f51c041
commit
5c15a08292
|
@ -33,6 +33,7 @@
|
||||||
xdg.configFile = {
|
xdg.configFile = {
|
||||||
"nushell/jolheiser.nu".source = ./nushell/jolheiser.nu;
|
"nushell/jolheiser.nu".source = ./nushell/jolheiser.nu;
|
||||||
"nushell/ssh.nu".source = ./nushell/ssh.nu;
|
"nushell/ssh.nu".source = ./nushell/ssh.nu;
|
||||||
|
"nushell/miniserve.nu".source = ./nushell/miniserve.nu;
|
||||||
"nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu;
|
"nushell/ohmyposh.nu".source = ./nushell/ohmyposh.nu;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,3 +102,4 @@ $env.EDITOR = 'hx'
|
||||||
$env.SSH_AUTH_SOCK = '/run/user/1000/ssh-agent'
|
$env.SSH_AUTH_SOCK = '/run/user/1000/ssh-agent'
|
||||||
source ~/.config/nushell/ohmyposh.nu
|
source ~/.config/nushell/ohmyposh.nu
|
||||||
source ~/.config/nushell/ssh.nu
|
source ~/.config/nushell/ssh.nu
|
||||||
|
source ~/.config/nushell/miniserve.nu
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
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)"
|
||||||
|
}
|
Loading…
Reference in New Issue