diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 820adf7..fdb10ad 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,8 +1,8 @@ name: Deploy on: - push: - branches: [ "master" ] + # push: + # branches: [ "master" ] release: types: [ published ] diff --git a/Makefile b/Makefile index 6a0ba3d..110d0f3 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ export HTTP_LISTEN=:8085 export PASTE_STORE=data/paste/ export ARTIFACT_STORE=data/artifact/ export IMAGE_STORE=data/image/ +export CGO_ENABLED=0 -SOURCE=$(wildcard v2/*.go) $(wildcard v2/paste/*.go) $(wildcard assets/*.go) +SOURCE=$(wildcard *.go) $(wildcard paste/*.go) $(wildcard assets/*.go) ASSETS=$(wildcard assets/*) $(wildcard assets/public/*) $(wildcard assets/src/*) $(wildcard assets/src/paste/*) ASSET_FILE=assets/build/index.html BINARY=sour.is-paste @@ -30,7 +31,7 @@ ${ASSET_FILE}: $(ASSETS) build: $(BINARY) $(BINARY): $(SOURCE) $(ASSET_FILE) - go build -o $(BINARY) ./v2 + go build -o $(BINARY) . .PHONEY: all clean build run setup # DO NOT DELETE diff --git a/image/image.go b/image/image.go index e6ac9fd..975adeb 100644 --- a/image/image.go +++ b/image/image.go @@ -49,7 +49,7 @@ func New(store string, maxSize int64) (a *image, err error) { func (a *image) RegisterHTTP(mux *http.ServeMux) { mux.Handle("/i", http.StripPrefix("/i", a)) mux.Handle("/i/", http.StripPrefix("/i/", a)) - mux.Handle("3/upload", http.StripPrefix("/3/upload", a)) + mux.Handle("/3/upload", a) } func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -63,13 +63,23 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) { a.get(ctx, w, name) case http.MethodPost: + var err error + var fd io.ReadCloser = r.Body + if r.URL.Path == "/3/upload" { + fd, _, err = r.FormFile("image") + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } + } + length := 0 if h := r.Header.Get("Content-Length"); h != "" { if i, err := strconv.Atoi(h); err != nil { length = i } } - id, err := a.put(ctx, w, r.Body, length) + id, err := a.put(ctx, w, fd, length) switch { case errors.Is(err, ErrGone): w.WriteHeader(http.StatusGone) @@ -91,7 +101,7 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) { Status int `json:"status"` }{ Data: data{ - Link: fmt.Sprintf("https://%s/%s", r.Host, id), + Link: fmt.Sprintf("https://%s/i/%s", r.Host, id), }, Success: true, Status: 200,