From 03677e24beb95fa150cff3071bb9c005d6c24563 Mon Sep 17 00:00:00 2001 From: Ricardo Band Date: Sat, 6 Apr 2024 18:57:43 +0200 Subject: [PATCH] small improvements; aur package --- .forgejo/workflows/tests.yml | 3 +- Makefile | 1 + README.md | 28 +-- aur/PKGBUILD | 53 +++++ aur/sanic.service | 28 +++ aur/sanic.sysusers | 3 + aur/sanic.tmpfiles | 3 + go.mod | 22 +- go.sum | 48 ++--- gomod2nix.toml | 40 ++-- mpd.go | 57 +++++- server.go | 3 +- static/index.html | 4 +- static/{controls.js => index.js} | 333 +++++++++++++++++-------------- static/util.js | 47 ----- 15 files changed, 386 insertions(+), 287 deletions(-) create mode 100644 aur/PKGBUILD create mode 100644 aur/sanic.service create mode 100644 aur/sanic.sysusers create mode 100644 aur/sanic.tmpfiles rename static/{controls.js => index.js} (64%) delete mode 100644 static/util.js diff --git a/.forgejo/workflows/tests.yml b/.forgejo/workflows/tests.yml index 5c3b26f..592b843 100644 --- a/.forgejo/workflows/tests.yml +++ b/.forgejo/workflows/tests.yml @@ -35,10 +35,9 @@ jobs: go-version-file: "go.mod" check-latest: true - name: Run Linter - uses: dominikh/staticcheck-action@v1.3.0 + uses: dominikh/staticcheck-action@v1 with: version: "latest" install-go: false - name: Run tests run: make test - diff --git a/Makefile b/Makefile index bcfe74c..f8eee1e 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ build: ## Compile project update: ## Update go dependencies go get -u + which gomod2nix && gomod2nix tidy: ## Add missing and remove unused modules go mod tidy diff --git a/README.md b/README.md index 31a5b0d..15c8a52 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ Example flake setup (untested): ```nix { + description = "Example Flake to install sanic on your host"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; sanic = { - url = "git+https://git.berlin.ccc.de/cccb/sanic?ref=main"; + url = "git.berlin.ccc.de/cccb/sanic"; inputs.nixpkgs.follows = "nixpkgs"; }; }; @@ -37,16 +38,17 @@ Example flake setup (untested): pkgs = import nixpkgs { inherit system; }; in { - devShell.${system} = pkgs.mkShell { - packages = [ - sanic.packages.${system}.default + nixosConfigurations."myhostname".nixpkgs.lib.nixosSystem = { + inherit system; + modules = [ + { environment.systemPackages = [ sanic.packages.${system}.default ]; } ]; }; }; } ``` -### Arch Linux (Manjaro, etc) +### Arch Linux Install from the AUR: @@ -54,18 +56,6 @@ Install from the AUR: yay -S sanic ``` -### Debian (Ubuntu, Mint, etc) - -_tba_ - -### Red Hat (Fedora, Rocky Linux, etc) - -_tba_ - -### Windows / macOS - -lol! 🀣 - ## πŸ› οΈ Development sanic is developed using [Nix][nix], but you can also just use the usual Golang tooling. @@ -77,7 +67,7 @@ Update go depdendencies like this: ```shell go get -u # or `make update` go mod tidy # or `make tidy` -gomod2nix +gomod2nix # sync go deps with nix ``` ### ❄️ w/ Nix @@ -88,7 +78,7 @@ Enter development shell (also has [mpc][mpc] client installed for testing): nix develop ``` -Build nix flake: +Build sanic: ```shell nix build diff --git a/aur/PKGBUILD b/aur/PKGBUILD new file mode 100644 index 0000000..3f7f4f9 --- /dev/null +++ b/aur/PKGBUILD @@ -0,0 +1,53 @@ +# Maintainer: Ricardo Band + +pkgname=sanic +pkgver=0.0.1 +pkgrel=1 +pkgdesc="chaos music control inspired by relaxx player" +arch=('any') +url=https://git.berlin.ccc.de/cccb/sanic +license=('custom:MIT') +makedepends=('go') +source=("$pkgname.service" + "$pkgname.sysusers" + "$pkgname.tmpfiles" + "$url/archive/v$pkgver.tar.gz") +sha256sums=("1337deadbeef" + "1337deadbeef" + "1337deadbeef" + "1337deadbeef") + +prepare() { + cd "$pkgname-$pkgver" + + mkdir -p build/ +} + +build() { + cd "$pkgname-$pkgver" + + export CGO_CPPFLAGS="$CPPFLAGS" + export CGO_CFLAGS="$CFLAGS" + export CGO_CXXFLAGS="$CXXFLAGS" + export CGO_LDFLAGS="$LDFLAGS" + export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw" + + go build -o build/ . +} + +check() { + cd "$pkgname-$pkgver" + + go test ./... +} + +package() { + cd "$pkgname-$pkgver" + + install -Dm644 "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE" + install -Dm755 build/$pkgname "$pkgdir"/usr/bin/$pkgname + install -Dm644 "../$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service" + install -Dm644 "../$pkgname.sysusers" "$pkgdir/usr/lib/sysusers.d/$pkgname.conf" + install -Dm644 "../$pkgname.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf" +} + diff --git a/aur/sanic.service b/aur/sanic.service new file mode 100644 index 0000000..0afa7e9 --- /dev/null +++ b/aur/sanic.service @@ -0,0 +1,28 @@ +[Unit] +Description=chaos music control +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=sanic +Group=sanic +ExecStart=/usr/bin/sanic +Restart=always +# security +NoNewPrivileges=true +ProtectSystem=strict +ProtectHome=yes +StateDirectory=sanic +StateDirectoryMode=0750 +ConfigurationDirectory=sanic +ConfigurationDirectoryMode=0750 +PrivateTmp=true +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectKernelLogs=true +ProtectControlGroups=true + +[Install] +WantedBy=multi-user.target + diff --git a/aur/sanic.sysusers b/aur/sanic.sysusers new file mode 100644 index 0000000..a286acc --- /dev/null +++ b/aur/sanic.sysusers @@ -0,0 +1,3 @@ +u sanic - "chaos music control" /run/sanic /usr/bin/nologin +g sanic - - + diff --git a/aur/sanic.tmpfiles b/aur/sanic.tmpfiles new file mode 100644 index 0000000..cff6c68 --- /dev/null +++ b/aur/sanic.tmpfiles @@ -0,0 +1,3 @@ +d /etc/sanic 0750 sanic sanic +d /run/sanic 0750 sanic sanic + diff --git a/go.mod b/go.mod index 2b26b9c..f432930 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,31 @@ -module github.com/cccb/sanic +module git.berlin.ccc.de/cccb/sanic go 1.21 require ( github.com/fhs/gompd/v2 v2.3.0 - github.com/labstack/echo-contrib v0.15.0 + github.com/labstack/echo-contrib v0.16.0 github.com/labstack/echo/v4 v4.11.4 - golang.org/x/net v0.20.0 + golang.org/x/net v0.24.0 gopkg.in/ini.v1 v1.67.0 ) require ( github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/prometheus/client_golang v1.18.0 // indirect - github.com/prometheus/client_model v0.5.0 // indirect - github.com/prometheus/common v0.46.0 // indirect - github.com/prometheus/procfs v0.12.0 // indirect + github.com/prometheus/client_golang v1.19.0 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.52.2 // indirect + github.com/prometheus/procfs v0.13.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect - google.golang.org/protobuf v1.32.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index 42e764c..42cb079 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,17 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fhs/gompd/v2 v2.3.0 h1:wuruUjmOODRlJhrYx73rJnzS7vTSXSU7pWmZtM3VPE0= github.com/fhs/gompd/v2 v2.3.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/labstack/echo-contrib v0.15.0 h1:9K+oRU265y4Mu9zpRDv3X+DGTqUALY6oRHCSZZKCRVU= -github.com/labstack/echo-contrib v0.15.0/go.mod h1:lei+qt5CLB4oa7VHTE0yEfQSEB9XTJI1LUqko9UWvo4= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/labstack/echo-contrib v0.16.0 h1:vk5Kd+egpTOJxD3l+3IvZzQWPbrXiYxhkkgkJL99j/w= +github.com/labstack/echo-contrib v0.16.0/go.mod h1:mjX5VB3OqJcroIEycptBOY9Hr7rK+unq79W8QFKGNV0= github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8= github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= @@ -23,34 +23,34 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= -github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y= -github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= +github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.52.2 h1:LW8Vk7BccEdONfrJBDffQGRtpSzi5CQaRZGtboOO2ck= +github.com/prometheus/common v0.52.2/go.mod h1:lrWtQx+iDfn2mbH5GUzlH9TSHyfZpHkSiG1W7y3sF2Q= +github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= +github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/gomod2nix.toml b/gomod2nix.toml index 0bb7d37..0d7f7f4 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -5,8 +5,8 @@ schema = 3 version = "v1.0.1" hash = "sha256-h75GUqfwJKngCJQVE5Ao5wnO3cfKD9lSIteoLp/3xJ4=" [mod."github.com/cespare/xxhash/v2"] - version = "v2.2.0" - hash = "sha256-nPufwYQfTkyrEkbBrpqM3C2vnMxfIz6tAaBmiUP7vd4=" + version = "v2.3.0" + hash = "sha256-7hRlwSR+fos1kx4VZmJ/7snR7zHh8ZFKX+qqqqGcQpY=" [mod."github.com/fhs/gompd/v2"] version = "v2.3.0" hash = "sha256-JBb7BvLu1wlUAbMt/g5JmJtA3fxqr6dKWeeLwfGsB08=" @@ -14,8 +14,8 @@ schema = 3 version = "v3.2.2+incompatible" hash = "sha256-LOkpuXhWrFayvVf1GOaOmZI5YKEsgqVSb22aF8LnCEM=" [mod."github.com/labstack/echo-contrib"] - version = "v0.15.0" - hash = "sha256-bDjEAJc5gPs+G5M8fbTSBFgb0t4dTYqdECyvHvuf3gY=" + version = "v0.16.0" + hash = "sha256-YnO4Ngu+gb/upIo856FDCtcTev36Vs/xUvP2qMiSGnA=" [mod."github.com/labstack/echo/v4"] version = "v4.11.4" hash = "sha256-pVKfkZtxi5e/1MTK2RcKWSgNpEbRDo3lKUVKo01WYO0=" @@ -29,17 +29,17 @@ schema = 3 version = "v0.0.20" hash = "sha256-qhw9hWtU5wnyFyuMbKx+7RB8ckQaFQ8D+8GKPkN3HHQ=" [mod."github.com/prometheus/client_golang"] - version = "v1.18.0" - hash = "sha256-kuC6WUg2j7A+9qnSp5VZSYo+oltgLvj/70TpqlCJIdE=" + version = "v1.19.0" + hash = "sha256-YV8sxMPR+xorTUCriTfcFsaV2b7PZfPJDQmOgUYOZJo=" [mod."github.com/prometheus/client_model"] - version = "v0.5.0" - hash = "sha256-/sXlngf8AoEIeLIiaLg6Y7uYPVq7tI0qnLt0mUyKid4=" + version = "v0.6.1" + hash = "sha256-rIDyUzNfxRA934PIoySR0EhuBbZVRK/25Jlc/r8WODw=" [mod."github.com/prometheus/common"] - version = "v0.46.0" - hash = "sha256-Q303suNDzc+DbIYhiqURNhymXeheWEshwm7XasKnX+Y=" + version = "v0.52.2" + hash = "sha256-XQUvk9/Kwf9NDlDUVl7mOWRD7z7z9QEbLH/rNU4D2nI=" [mod."github.com/prometheus/procfs"] - version = "v0.12.0" - hash = "sha256-Y4ZZmxIpVCO67zN3pGwSk2TcI88zvmGJkgwq9DRTwFw=" + version = "v0.13.0" + hash = "sha256-J31K36TkIiQU2EGOcmqDa+dkoKXiVuxafPVT4rKbEsg=" [mod."github.com/valyala/bytebufferpool"] version = "v1.0.0" hash = "sha256-I9FPZ3kCNRB+o0dpMwBnwZ35Fj9+ThvITn8a3Jr8mAY=" @@ -47,14 +47,14 @@ schema = 3 version = "v1.2.2" hash = "sha256-gp+lNXE8zjO+qJDM/YbS6V43HFsYP6PKn4ux1qa5lZ0=" [mod."golang.org/x/crypto"] - version = "v0.18.0" - hash = "sha256-BuMVUxOIyfLo8MOhqYt+uQ8NDN6P2KdblKyfPxINzQ4=" + version = "v0.22.0" + hash = "sha256-2+u9nd32+Bi7EEv7QFc12CRTbfV7DApNv+yKIr7+lTw=" [mod."golang.org/x/net"] - version = "v0.20.0" - hash = "sha256-PCttIsWSBQd6fDXL49jepszUAMLnAGAKR//5EDO3XDk=" + version = "v0.24.0" + hash = "sha256-w1c21ljta5wNIyel9CSIn/crPzwOCRofNKhqmfs4aEQ=" [mod."golang.org/x/sys"] - version = "v0.16.0" - hash = "sha256-ZkGclbp2S7NQYhbuGji6XokCn2Qi1BJy8dwyAOTV8sY=" + version = "v0.19.0" + hash = "sha256-cmuL31TYLJmDm/fDnI2Sn0wB88cpdOHV1+urorsJWx4=" [mod."golang.org/x/text"] version = "v0.14.0" hash = "sha256-yh3B0tom1RfzQBf1RNmfdNWF1PtiqxV41jW1GVS6JAg=" @@ -62,8 +62,8 @@ schema = 3 version = "v0.5.0" hash = "sha256-W6RgwgdYTO3byIPOFxrP2IpAZdgaGowAaVfYby7AULU=" [mod."google.golang.org/protobuf"] - version = "v1.32.0" - hash = "sha256-GJuTkMGHCzHbyK4yD5kY4oMn8wQWqgkeBK//yVDqHJk=" + version = "v1.33.0" + hash = "sha256-cWwQjtUwSIEkAlAadrlxK1PYZXTRrV4NKzt7xDpJgIU=" [mod."gopkg.in/ini.v1"] version = "v1.67.0" hash = "sha256-V10ahGNGT+NLRdKUyRg1dos5RxLBXBk1xutcnquc/+4=" diff --git a/mpd.go b/mpd.go index e5c499c..2db65b2 100644 --- a/mpd.go +++ b/mpd.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/fhs/gompd/v2/mpd" "github.com/labstack/echo/v4" "net/http" @@ -23,7 +24,7 @@ func updateDb(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, strconv.Itoa(jobId)) + return c.String(http.StatusOK, fmt.Sprintf("Database update started with job id %d", jobId)) } func previousTrack(c echo.Context) error { @@ -39,7 +40,7 @@ func previousTrack(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, "Playing previous track in queue") } func nextTrack(c echo.Context) error { @@ -55,7 +56,7 @@ func nextTrack(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, "PLaying next track in queue") } func stopPlayback(c echo.Context) error { @@ -71,7 +72,7 @@ func stopPlayback(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, "Playback stopped") } func resumePlayback(c echo.Context) error { @@ -98,7 +99,7 @@ func resumePlayback(c echo.Context) error { } } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, "Playback resumed") } func pausePlayback(c echo.Context) error { @@ -114,7 +115,7 @@ func pausePlayback(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, "Playback paused") } func seek(c echo.Context) error { @@ -134,12 +135,13 @@ func seek(c echo.Context) error { return c.String(http.StatusBadRequest, "seconds must be positive integer") } + // TODO: Duration type seems to be used incorrectly err = conn.SeekCur(time.Duration(seconds)*time.Second, false) if err != nil { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, fmt.Sprintf("Seeked current track to %d seconds", seconds)) } func toggleRepeat(c echo.Context) error { @@ -154,16 +156,19 @@ func toggleRepeat(c echo.Context) error { if err != nil { c.Logger().Error(err) } + var msg string if status["repeat"] == "1" { err = conn.Repeat(false) + msg = "Toggled Repeat mode to off" } else { err = conn.Repeat(true) + msg = "Toggled Repeat mode to on" } if err != nil { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, msg) } func toggleRandom(c echo.Context) error { @@ -178,16 +183,19 @@ func toggleRandom(c echo.Context) error { if err != nil { c.Logger().Error(err) } + var msg string if status["random"] == "1" { err = conn.Random(false) + msg = "Toggled Random mode to off" } else { err = conn.Random(true) + msg = "Toggled Random mode to on" } if err != nil { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, msg) } func setVolume(c echo.Context) error { @@ -212,7 +220,7 @@ func setVolume(c echo.Context) error { c.Logger().Error(err) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, fmt.Sprintf("Set volume to %d", level)) } // Queue @@ -236,5 +244,32 @@ func deleteTrackFromQueue(c echo.Context) error { return c.String(http.StatusBadRequest, err.Error()) } - return c.String(http.StatusOK, "") + return c.String(http.StatusOK, fmt.Sprintf("Removed song %d from queue", songId)) +} + +func moveTrackInQueue(c echo.Context) error { + // Connect to MPD server + conn, err := mpd.Dial("tcp", "localhost:6600") + if err != nil { + c.Logger().Error(err) + } + defer conn.Close() + + songId, err := strconv.Atoi(c.Param("song_id")) + if err != nil { + c.Logger().Error(err) + } + + position, err := strconv.Atoi(c.Param("position")) + if err != nil { + c.Logger().Error(err) + } + + err = conn.MoveID(songId, position) + if err != nil { + c.Logger().Error(err) + return c.String(http.StatusBadRequest, err.Error()) + } + + return c.String(http.StatusOK, fmt.Sprintf("Moved song %d to position %d", songId, position)) } diff --git a/server.go b/server.go index 8c72c12..6ae971a 100644 --- a/server.go +++ b/server.go @@ -89,7 +89,8 @@ func main() { g.GET("/random", toggleRandom) g.GET("/volume/:level", setVolume) - g.GET("/queue/delete/:song_id", deleteTrackFromQueue) + g.GET("/queue/:song_id/delete", deleteTrackFromQueue) + g.GET("/queue/:song_id/move/:position", moveTrackInQueue) g.GET("/download", downloadTrack) diff --git a/static/index.html b/static/index.html index 211a438..5eb308b 100644 --- a/static/index.html +++ b/static/index.html @@ -62,7 +62,7 @@
- Fall On Your Sword - Shatner Of The Mount by Fall On Your Sword +
@@ -226,7 +226,7 @@ Sanic MPD Web UI 0.1.0 - by XenGi and coon © 2023 - +