Merge pull request 'QOL improvements' from testing into main
Reviewed-on: #1
This commit is contained in:
commit
fe522cbee3
|
@ -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 ./...
|
|
@ -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:"
|
|
@ -1,3 +1,9 @@
|
||||||
# uploader
|
# uploader
|
||||||
|
|
||||||
Small HTTP server that lets users easily upload files to your computer.
|
Small HTTP server that lets users easily upload files to your computer.
|
||||||
|
|
||||||
|
## Usage:
|
||||||
|
```
|
||||||
|
./uploader
|
||||||
|
```
|
||||||
|
Visit http://localhost:8080/
|
||||||
|
|
|
@ -16,7 +16,21 @@
|
||||||
<button id="but">
|
<button id="but">
|
||||||
Upload
|
Upload
|
||||||
</button>
|
</button>
|
||||||
|
<progress id="progress" value="0" max="100">Upload progress:</progress>
|
||||||
</form>
|
</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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,16 @@
|
||||||
border: 2px black solid;
|
border: 2px black solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.centered {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
text-align: center;
|
||||||
|
border: 2px solid #ff6e00;
|
||||||
|
border-radius: 50%;
|
||||||
|
padding: 1%;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
|
@ -38,9 +47,28 @@ form {
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #ff6e00;
|
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 {
|
#main {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
|
@ -48,6 +76,7 @@ a:hover {}
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding-left: 5%;
|
padding-left: 5%;
|
||||||
padding-right: 5%;
|
padding-right: 5%;
|
||||||
|
outline: solid 2px #ff6e00;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
|
|
33
main.go
33
main.go
|
@ -1,29 +1,20 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// func getRoot(w http.ResponseWriter, r *http.Request) {
|
//go:embed assets
|
||||||
// fmt.Printf("Received connection\n")
|
var assetsFolder embed.FS
|
||||||
// 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))
|
|
||||||
// }
|
|
||||||
|
|
||||||
func uploadFile(w http.ResponseWriter, r *http.Request) {
|
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")
|
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)
|
log.Printf("Error happened receiving file: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
_, err = os.Stat("./temp/")
|
_, err = os.Stat("./temp/")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir("./temp/", 0700)
|
os.Mkdir("./temp/", 0700)
|
||||||
|
@ -40,19 +33,23 @@ func uploadFile(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error happened opening file: %v\n", err)
|
log.Printf("Error happened opening file: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[%v] Received file \"%v\" from %v\n", r.RemoteAddr, header.Filename, r.UserAgent())
|
log.Printf("[%v] Received file \"%v\" from %v\n", r.RemoteAddr, header.Filename, r.UserAgent())
|
||||||
io.Copy(f, file)
|
io.Copy(f, file)
|
||||||
|
|
||||||
defer file.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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)
|
http.HandleFunc("/api/upload", uploadFile)
|
||||||
|
|
||||||
fmt.Println("Listening on port 8080...")
|
fmt.Println("Listening on port 8080...")
|
||||||
|
|
||||||
err := http.ListenAndServe(":8080", nil)
|
err = http.ListenAndServe(":8080", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue