Merge pull request 'QOL improvements' from testing into main

Reviewed-on: #1
This commit is contained in:
raul 2024-05-02 08:16:57 +02:00
commit 135dc0d3f8
7 changed files with 145 additions and 20 deletions

View File

@ -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 ./...

51
.goreleaser.yaml Normal file
View File

@ -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:"

3
Makefile Normal file
View File

@ -0,0 +1,3 @@
uploader:
go build -o ./uploader .
strip ./uploader

View File

@ -1,3 +1,9 @@
# uploader
Small HTTP server that lets users easily upload files to your computer.
## Usage:
```
./uploader
```
Visit http://localhost:8080/

View File

@ -16,7 +16,21 @@
<button id="but">
Upload
</button>
<progress id="progress" value="0" max="100">Upload progress:</progress>
</form>
<script>
htmx.on('#form', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>
<p class="centered">
<!-- <img src="https://bulgariu.xyz/avatar.gif" alt="" width=200px height=200px > -->
</p>
<!-- <footer> -->
<!-- Licensed under the GPL v3.0 -->
<!-- </footer> -->
</div>
</div>

View File

@ -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 {

33
main.go
View File

@ -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)
}