diff --git a/Dockerfile b/Dockerfile index 1ab4279..895a261 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,15 @@ -FROM golang:1-bullseye AS build -RUN apt-get update -RUN apt-get -y --no-install-recommends install libavutil-dev libswscale-dev libavformat-dev libgraphicsmagick-dev +FROM golang:1 AS build WORKDIR /src COPY go.* ./ COPY pkg ./pkg/ COPY cmd ./cmd/ -COPY web /web RUN go get ./... -RUN go install ./... -ENTRYPOINT ["/go/bin/simpleauth"] +RUN CGO_ENABLED=0 GOOS=linux go install ./... + +FROM alpine AS runtime +WORKDIR /target +COPY --from=build /go/bin/ . + +FROM scratch +COPY --from=runtime /target / +ENTRYPOINT ["/webfs"] diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8175599 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Neale Pickett + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The software is provided "as is", without warranty of any kind, express or +implied, including but not limited to the warranties of merchantability, +fitness for a particular purpose and noninfringement. In no event shall the +authors or copyright holders be liable for any claim, damages or other +liability, whether in an action of contract, tort or otherwise, arising from, +out of or in connection with the software or the use or other dealings in the +software. diff --git a/README.md b/README.md new file mode 100644 index 0000000..424429a --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# webfs + +It's a WebDAV server. + +That's all it does. It serves WebDAV. + +I front-end it with Caddy, +which handles authentication and access controls. diff --git a/cmd/webfs/main.go b/cmd/webfs/main.go index 93bd59d..8be3a0f 100644 --- a/cmd/webfs/main.go +++ b/cmd/webfs/main.go @@ -1,73 +1,17 @@ package main import ( - "bytes" - "context" "flag" - "fmt" - "github.com/bakape/thumbnailer" "golang.org/x/net/webdav" "log" "net/http" - "os" - "path" - "path/filepath" - "strconv" ) -type Handler struct { - webdav.Handler -} - -func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { - width, _ := strconv.Atoi(req.FormValue("w")) - height, _ := strconv.Atoi(req.FormValue("h")) - - if (width > 0) || (height > 0) { - h.ServeThumbnail(w, req, uint(width), uint(height)) - return - } - - h.Handler.ServeHTTP(w, req) -} - -func (h *Handler) ServeThumbnail(w http.ResponseWriter, req *http.Request, width uint, height uint) { - srcPath := path.Clean(req.URL.Path) - srcFile, err := h.FileSystem.OpenFile(context.Background(), srcPath, os.O_RDONLY, 0664) - if err != nil { - http.NotFound(w, req) - return - } - defer srcFile.Close() - srcFileInfo, err := srcFile.Stat() - if err != nil { - http.NotFound(w, req) - return - } - - var opts thumbnailer.Options - opts.ThumbDims.Width = width - opts.ThumbDims.Height = height - _, thumb, err := thumbnailer.Process(srcFile, opts) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - ext := "jpeg" - if thumb.IsPNG { - ext = "png" - } - fileName := filepath.Base(srcPath) - thumbFileName := fmt.Sprintf("%s.thumb.%s", fileName, ext) - thumbRs := bytes.NewReader(thumb.Image.Data) - http.ServeContent(w, req, thumbFileName, srcFileInfo.ModTime(), thumbRs) -} - func main() { address := flag.String("a", "localhost:8080", "Address to listen to.") flag.Parse() - handler := &Handler{} + handler := &webdav.Handler{} handler.FileSystem = webdav.Dir(".") handler.LockSystem = webdav.NewMemLS()