Compare commits
No commits in common. "ccc7a027cabb68c7f725cf5f089c4a6ad7ed8305" and "71bf97de217e39e452444c5f1c23e98f9f31a921" have entirely different histories.
ccc7a027ca
...
71bf97de21
2
.gitignore
vendored
2
.gitignore
vendored
@ -20,4 +20,4 @@
|
|||||||
|
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
files/
|
|
||||||
|
13
Dockerfile
13
Dockerfile
@ -1,13 +0,0 @@
|
|||||||
FROM golang:1.20-alpine
|
|
||||||
|
|
||||||
RUN apk add --no-cache git
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
|
||||||
RUN go mod download
|
|
||||||
COPY . .
|
|
||||||
RUN go build -o main .
|
|
||||||
|
|
||||||
EXPOSE 48723
|
|
||||||
|
|
||||||
CMD ["./main"]
|
|
@ -1,8 +0,0 @@
|
|||||||
services:
|
|
||||||
web:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- "48723:48723"
|
|
||||||
volumes:
|
|
||||||
- /mnt/storage/files:/app/files
|
|
||||||
restart: unless-stopped
|
|
54
server.go
54
server.go
@ -1,54 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
func uploadFile(wr http.ResponseWriter, rq *http.Request) {
|
|
||||||
fmt.Println("File Upload Endpoint Hit")
|
|
||||||
err := rq.ParseMultipartForm(128 << 20)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(wr, "Unable to parse form", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve the uploaded file using the form field `myFile`
|
|
||||||
file, handler, er := rq.FormFile("file")
|
|
||||||
if er != nil {
|
|
||||||
http.Error(wr, "Error getting the file", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if handler.Size > 128<<20 {
|
|
||||||
http.Error(wr, "Max file size is 128mb.", http.StatusRequestEntityTooLarge)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
fname := fmt.Sprintf("%d%s", rand.Intn(1000000), filepath.Ext(handler.Filename))
|
|
||||||
destPath := filepath.Join("./files", fname)
|
|
||||||
destFile, er := os.Create(destPath)
|
|
||||||
if er != nil {
|
|
||||||
http.Error(wr, "OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer destFile.Close()
|
|
||||||
_, er = io.Copy(destFile, file)
|
|
||||||
if er != nil {
|
|
||||||
http.Error(wr, "OOPSIE WOOPSIE!! Uwu We made a fucky wucky!! A wittle fucko boingo! The code monkeys at our headquarters are working VEWY HAWD to fix this!", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(wr, "Success! Your file should now be accessible here: https://files.fzorb.xyz/%s\n", fname)
|
|
||||||
fmt.Printf("File successfully saved to: %s\n", destPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("Server now listening on port 48723")
|
|
||||||
http.HandleFunc("/upload", uploadFile)
|
|
||||||
http.ListenAndServe(":48723", nil)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user