separate html dir
This commit is contained in:
parent
094e63a2ef
commit
670fadcfbc
8 changed files with 69 additions and 45 deletions
|
@ -14,6 +14,7 @@ FROM scratch
|
|||
WORKDIR /app
|
||||
|
||||
COPY --from=go /app/nixshare ./nixshare
|
||||
COPY --from=go /app/html ./html
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
|
|
5
Makefile
5
Makefile
|
@ -6,5 +6,6 @@ deploy:
|
|||
docker push gitrepo.ru/neonxp/nixshare:latest
|
||||
docker context use curie
|
||||
docker pull gitrepo.ru/neonxp/nixshare:latest
|
||||
docker rm nixshare || true
|
||||
docker run --name nixshare -d -p 8095:8000 -v nixshare:/app/storage gitrepo.ru/neonxp/nixshare
|
||||
docker rm -f nixshare || true
|
||||
docker volume rm -f nixshare_html || true
|
||||
docker run --name nixshare -d -p 8095:8000 -v nixshare:/app/storage -v nixshare_html:/app/html gitrepo.ru/neonxp/nixshare
|
3
go.mod
3
go.mod
|
@ -4,5 +4,8 @@ go 1.23.0
|
|||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
go.neonxp.ru/mux v0.0.0-20240729221623-376839b264c7
|
||||
golang.org/x/sync v0.8.0
|
||||
)
|
||||
|
||||
require go.neonxp.ru/objectid v0.0.2 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,4 +1,8 @@
|
|||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
go.neonxp.ru/mux v0.0.0-20240729221623-376839b264c7 h1:b/AgHRmzwI+FMNrf/HYEILmntTPSRDarOMTYEmL7AS8=
|
||||
go.neonxp.ru/mux v0.0.0-20240729221623-376839b264c7/go.mod h1:5OlVmN/OgaWjghQMV8oOzUQC0lUqAoplpQsUiqL5Pgc=
|
||||
go.neonxp.ru/objectid v0.0.2 h1:Z/G6zvBxmUq0NTq681oGH8pTbBWwi6VA22YOYludIPs=
|
||||
go.neonxp.ru/objectid v0.0.2/go.mod h1:s0dRi//oe1liiKcor1KmWx09WzkD6Wtww8ZaIv+VLBs=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
|
|
39
html/index.html
Normal file
39
html/index.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>NixShare</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Nixshare</h1>
|
||||
<h2>Usage:</h2>
|
||||
<h3>Upload file:</h3>
|
||||
<pre>
|
||||
curl -d @FILENAME https://nixshare.ru/upload
|
||||
</pre>
|
||||
<h3>Upload clipboard:</h3>
|
||||
<p>X:</p>
|
||||
<pre>
|
||||
xclip -o | curl -d @- https://nixshare.ru/upload
|
||||
</pre>
|
||||
<p>Wayland (<code>wl-clipboard</code> required):</p>
|
||||
<pre>
|
||||
wl-paste | curl -d @- https://nixshare.ru/upload
|
||||
</pre>
|
||||
<h3>Shell alias:</h3>
|
||||
<p>You can add shell aliases to .bashrc or .zshrc file:</p>
|
||||
<p>X:</p>
|
||||
<pre>
|
||||
alias nsh="xclip -o | curl -d @- https://nixshare.ru/upload 2>/dev/null | xclip"
|
||||
</pre>
|
||||
<p>Wayland (<code>wl-clipboard</code> required):</p>
|
||||
<pre>
|
||||
alias nsh="wl-paste | curl -d @- https://nixshare.ru/upload 2>/dev/null | wl-copy"
|
||||
</pre>
|
||||
<h2>Author:</h2>
|
||||
<p>Alexander NeonXP Kiryukhin <<a href="mailto:a.kiryukhin@mail.ru">a.kiryukhin@mail.ru</a>></p>
|
||||
<h2>Source code:</h2>
|
||||
<a href="https://gitrepo.ru/neonxp/nixshare">gitrepo.ru/neonxp/nixshare</a>
|
||||
</body>
|
||||
</html>
|
24
main.go
24
main.go
|
@ -5,25 +5,30 @@ import (
|
|||
"flag"
|
||||
"io/fs"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"go.neonxp.ru/mux"
|
||||
"go.neonxp.ru/mux/middleware"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var (
|
||||
host string
|
||||
listen string
|
||||
path string
|
||||
ttl time.Duration
|
||||
host string
|
||||
listen string
|
||||
path string
|
||||
htmlPath string
|
||||
ttl time.Duration
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&host, "host", "https://nixshare.ru/", "host of nixshare")
|
||||
flag.StringVar(&listen, "listen", ":8000", "port to listen")
|
||||
flag.StringVar(&htmlPath, "html_path", "./html", "html directory")
|
||||
flag.StringVar(&path, "path", "./storage", "storage directory")
|
||||
flag.DurationVar(&ttl, "ttl", 24*time.Hour, "time to delete uploaded file")
|
||||
}
|
||||
|
@ -37,11 +42,16 @@ func main() {
|
|||
r := http.NewServeMux()
|
||||
|
||||
r.Handle("POST /upload", http.HandlerFunc(uploadHandler))
|
||||
r.Handle("/", http.FileServer(http.Dir(path)))
|
||||
r.Handle("/", http.FileServer(http.Dir("html")))
|
||||
r.Handle("/s/", http.StripPrefix("/s/", http.FileServer(http.Dir(path))))
|
||||
|
||||
srv := http.Server{
|
||||
Addr: listen,
|
||||
Handler: r,
|
||||
Addr: listen,
|
||||
Handler: mux.Use(r,
|
||||
middleware.Recover(slog.Default()),
|
||||
middleware.RequestID,
|
||||
middleware.Logger(slog.Default()),
|
||||
),
|
||||
}
|
||||
|
||||
eg, egCtx := errgroup.WithContext(ctx)
|
||||
|
|
|
@ -1,35 +1 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>NixShare</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Nixshare</h1>
|
||||
<h2>Usage:</h2>
|
||||
<h3>Upload file:</h3>
|
||||
<pre>
|
||||
curl -d @FILENAME https://nixshare.ru/upload
|
||||
</pre>
|
||||
<h3>Upload clipboard:</h3>
|
||||
<p>X:</p>
|
||||
<pre>
|
||||
xclip -o | curl -d @- https://nixshare.ru/upload
|
||||
</pre>
|
||||
<p>Wayland (<code>wl-clipboard</code> required):</p>
|
||||
<pre>
|
||||
wl-paste | curl -d @- https://nixshare.ru/upload
|
||||
</pre>
|
||||
<h3>Shell alias:</h3>
|
||||
<p>You can add shell aliases to .bashrc or .zshrc file:</p>
|
||||
<p>X:</p>
|
||||
<pre>
|
||||
alias nsh="xclip -o | curl -d @- https://nixshare.ru/upload 2>/dev/null | xclip"
|
||||
</pre>
|
||||
<p>Wayland (<code>wl-clipboard</code> required):</p>
|
||||
<pre>
|
||||
alias nsh="wl-paste | curl -d @- https://nixshare.ru/upload 2>/dev/null | wl-copy"
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
nothing here
|
|
@ -36,7 +36,7 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
h.Set("Content-Type", "text/plain; charset=utf-8")
|
||||
h.Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
u, err := url.JoinPath(host, section, uid)
|
||||
u, err := url.JoinPath(host, "s", section, uid)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, "can't get file url", http.StatusInternalServerError)
|
||||
|
|
Loading…
Reference in a new issue