diff --git a/.gitea/workflows/go-audit.yaml b/.gitea/workflows/go-audit.yaml new file mode 100644 index 0000000..70c5e4b --- /dev/null +++ b/.gitea/workflows/go-audit.yaml @@ -0,0 +1,25 @@ +name: Go audit +run-name: ${{ gitea.actor }} pulled to main! 🚀 +on: + pull_request: + branches: [main] +jobs: + audit: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: '>=1.22.0' + + - name: Verify dependencies + run: go mod verify + + - name: Build + run: go build -v ./... + + - name: Run go vet + run: go vet ./... diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..8e02d12 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 1 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +gitea_urls: + api: https://git.bulgariu.xyz/api/v1 + download: https://git.bulgariu.xyz + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + goarch: + - amd64 + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4b1b2f0 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +uploader: + go build -o ./uploader . + strip ./uploader diff --git a/README.md b/README.md index 623e342..e48a67d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # uploader -Small HTTP server that lets users easily upload files to your computer. \ No newline at end of file +Small HTTP server that lets users easily upload files to your computer. + +## Usage: +``` +./uploader +``` +Visit http://localhost:8080/ diff --git a/assets/index.html b/assets/index.html index 20af6cb..b449b2e 100644 --- a/assets/index.html +++ b/assets/index.html @@ -16,7 +16,21 @@ + Upload progress: + + +

+ +

+ + + + diff --git a/assets/style.css b/assets/style.css index 0b4c5a6..c68725e 100644 --- a/assets/style.css +++ b/assets/style.css @@ -7,7 +7,16 @@ border: 2px black solid; } +.centered { + text-align: center; +} +img { + text-align: center; + border: 2px solid #ff6e00; + border-radius: 50%; + padding: 1%; +} button { background-color: #eee; @@ -38,9 +47,28 @@ form { a { color: #ff6e00; + text-decoration: none; } -a:hover {} +a:hover { + text-decoration: underline; +} + +progress::-moz-progress-bar { + background-color: #ff6e00; +} + +progress::-webkit-progress-value { + background-color: #ff6e00; +} + +progress { + color: #ff6e00; +} + +footer { + top: 100%; +} #main { background-color: #eee; @@ -48,6 +76,7 @@ a:hover {} height: 100%; padding-left: 5%; padding-right: 5%; + outline: solid 2px #ff6e00; } .container { diff --git a/main.go b/main.go index f135922..7c2cce8 100644 --- a/main.go +++ b/main.go @@ -1,29 +1,20 @@ package main import ( + "embed" "fmt" "io" + "io/fs" "log" "net/http" "os" ) -// func getRoot(w http.ResponseWriter, r *http.Request) { -// fmt.Printf("Received connection\n") -// file, err := os.Open("./index.html") -// if err != nil { -// log.Printf("Error happened opening index.html: %v\n", err) -// } -// defer file.Close() -// data, err := io.ReadAll(file) -// if err != nil { -// log.Printf("Error happened reading data: %v\n", err) -// } -// fmt.Fprint(w, string(data)) -// } +//go:embed assets +var assetsFolder embed.FS func uploadFile(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "You have uploaded something") + fmt.Fprintln(w, "Successful upload!") file, header, err := r.FormFile("file") @@ -31,6 +22,8 @@ func uploadFile(w http.ResponseWriter, r *http.Request) { log.Printf("Error happened receiving file: %v\n", err) } + defer file.Close() + _, err = os.Stat("./temp/") if os.IsNotExist(err) { os.Mkdir("./temp/", 0700) @@ -40,19 +33,23 @@ func uploadFile(w http.ResponseWriter, r *http.Request) { if err != nil { log.Printf("Error happened opening file: %v\n", err) } + log.Printf("[%v] Received file \"%v\" from %v\n", r.RemoteAddr, header.Filename, r.UserAgent()) io.Copy(f, file) - - defer file.Close() } func main() { - http.Handle("/", http.FileServer(http.Dir("./assets"))) + serverRoot, err := fs.Sub(assetsFolder, "assets") + if err != nil { + log.Fatalf("Error occurred setting HTML root: %v\n", err) + } + + http.Handle("/", http.FileServer(http.FS(serverRoot))) http.HandleFunc("/api/upload", uploadFile) fmt.Println("Listening on port 8080...") - err := http.ListenAndServe(":8080", nil) + err = http.ListenAndServe(":8080", nil) if err != nil { log.Fatal(err) }