From 72227af1448e769d48fc3333db1b2de49005002a Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 30 Apr 2024 12:23:40 +0200 Subject: [PATCH 1/8] Add Makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Makefile 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 From 3c1bba943e14cb03ff51eb33f630ebd1ac2a66c9 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 1 May 2024 08:40:31 +0200 Subject: [PATCH 2/8] Add workflows --- .gitea/workflows/go-audit.yaml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .gitea/workflows/go-audit.yaml diff --git a/.gitea/workflows/go-audit.yaml b/.gitea/workflows/go-audit.yaml new file mode 100644 index 0000000..19095f2 --- /dev/null +++ b/.gitea/workflows/go-audit.yaml @@ -0,0 +1,27 @@ +name: Go audit +run-name: ${{ gitea.actor }} pushed to main! 🚀 +on: + push: + branches: [main] + 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 ./... From 2919693c73a9d13f666115e06a66c640e8f59a86 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 1 May 2024 08:40:59 +0200 Subject: [PATCH 3/8] Add goreleaser.yaml --- .goreleaser.yaml | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .goreleaser.yaml 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:" From 4e412c789b6ff2814076869e2d395d7a076e8f85 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 1 May 2024 08:42:54 +0200 Subject: [PATCH 4/8] Add loading bar to webpage --- assets/index.html | 14 ++++++++++++++ assets/style.css | 19 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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..983da5b 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,16 @@ form { a { color: #ff6e00; + text-decoration: none; } -a:hover {} +a:hover { + text-decoration: underline; +} + +footer { + top: 100%; +} #main { background-color: #eee; @@ -48,6 +64,7 @@ a:hover {} height: 100%; padding-left: 5%; padding-right: 5%; + outline: solid 2px #ff6e00; } .container { From c3585f37eba1e57ee01b4ccc26326bb1afa77bc9 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 1 May 2024 09:11:25 +0200 Subject: [PATCH 5/8] Add embedding files to binary Now this app is truly portable! You don't even need the assets folder when using a compiled binary, as the HTML and CSS are now embedded to the file itself --- main.go | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) 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) } From 16d0d14c9bf6b5959527a98ca5217c83f645271b Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 2 May 2024 07:58:52 +0200 Subject: [PATCH 6/8] Modify progress bar background color --- assets/style.css | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/style.css b/assets/style.css index 983da5b..c68725e 100644 --- a/assets/style.css +++ b/assets/style.css @@ -54,6 +54,18 @@ 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%; } From 1e761345a95789ddee1f3ff40644027f16a47afb Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 2 May 2024 07:59:57 +0200 Subject: [PATCH 7/8] Update workflow to only trigger on pull --- .gitea/workflows/go-audit.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitea/workflows/go-audit.yaml b/.gitea/workflows/go-audit.yaml index 19095f2..70c5e4b 100644 --- a/.gitea/workflows/go-audit.yaml +++ b/.gitea/workflows/go-audit.yaml @@ -1,8 +1,6 @@ name: Go audit -run-name: ${{ gitea.actor }} pushed to main! 🚀 +run-name: ${{ gitea.actor }} pulled to main! 🚀 on: - push: - branches: [main] pull_request: branches: [main] jobs: From 1c224dc56ad4c844f4ad87b3652e6c1e9ab26ee5 Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 2 May 2024 08:06:52 +0200 Subject: [PATCH 8/8] Update README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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/