mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 05:39:38 +05:00
fix prefs, move to go tool, refine docs and etc
This commit is contained in:
20
Dockerfile
20
Dockerfile
@@ -1,4 +1,4 @@
|
||||
ARG GO_VERSION=1.25.0
|
||||
ARG GO_VERSION=1.25.1
|
||||
|
||||
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build
|
||||
ARG TARGETOS
|
||||
@@ -14,19 +14,15 @@ RUN go env -w GOPROXY=direct && \
|
||||
echo "soundcloak:x:5000:" > /etc2/group
|
||||
|
||||
COPY go.* .
|
||||
RUN go mod download -x && \
|
||||
go install -v github.com/a-h/templ/cmd/templ@latest && \
|
||||
go install -v github.com/dlclark/regexp2cg@main
|
||||
RUN go mod download -x
|
||||
COPY . .
|
||||
# usually soundcloakctl updates together with soundcloak, so we should redownload it
|
||||
RUN go install -v git.maid.zone/stuff/soundcloakctl@master && \
|
||||
soundcloakctl js download && \
|
||||
templ generate && \
|
||||
RUN go tool soundcloakctl js download && \
|
||||
go tool templ generate && \
|
||||
go generate ./lib/* && \
|
||||
soundcloakctl config codegen && \
|
||||
soundcloakctl -nozstd precompress && \
|
||||
CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -v -ldflags "-s -w -extldflags '-static' -X git.maid.zone/stuff/soundcloak/lib/cfg.Commit=`git rev-parse HEAD | head -c 7` -X git.maid.zone/stuff/soundcloak/lib/cfg.Repo=`git remote get-url origin`" -o ./app && \
|
||||
soundcloakctl postbuild
|
||||
go tool soundcloakctl config codegen && \
|
||||
go tool soundcloakctl -nozstd precompress && \
|
||||
CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -v -ldflags "-s -w -extldflags '-static' -X git.maid.zone/stuff/soundcloak/lib/cfg.Commit=`git rev-parse --short HEAD` -X git.maid.zone/stuff/soundcloak/lib/cfg.Repo=`git remote get-url origin`" -o ./app && \
|
||||
go tool soundcloakctl postbuild
|
||||
|
||||
FROM scratch
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Frontend for SoundCloud
|
||||
## [Instance Maintainer Guide](docs/INSTANCE_GUIDE.md)
|
||||
## [Development Guide](docs/DEV_GUIDE.md)
|
||||
|
||||
If you have any questions, or just wanna talk about soundcloak, you can join the maid.zone XMPP/Matrix chat: [public@muc.maid.zone](xmpp:public@muc.maid.zone?join) / [#public:maid.zone](https://matrix.to/#/#public:maid.zone)
|
||||
If you have any questions, or just wanna talk about soundcloak, you can join the maid.zone XMPP chat: [public@muc.maid.zone](xmpp:public@muc.maid.zone?join)
|
||||
|
||||
# Notice
|
||||
soundcloak is not affiliated with SoundCloud.
|
||||
4
build
4
build
@@ -1,3 +1,3 @@
|
||||
templ generate
|
||||
go tool templ generate
|
||||
go generate ./lib/*
|
||||
go build -ldflags "-X git.maid.zone/stuff/soundcloak/lib/cfg.Commit=`git rev-parse HEAD | head -c 7` -X git.maid.zone/stuff/soundcloak/lib/cfg.Repo=`git remote get-url origin`" main.go
|
||||
go build -ldflags "-X git.maid.zone/stuff/soundcloak/lib/cfg.Commit=`git rev-parse --short HEAD` -X git.maid.zone/stuff/soundcloak/lib/cfg.Repo=`git remote get-url origin`" main.go
|
||||
@@ -1,6 +1,6 @@
|
||||
# Setup
|
||||
## Prerequisites
|
||||
1. [golang](https://go.dev) (I recommend version 1.24.0)
|
||||
1. [golang](https://go.dev) (I recommend version 1.25.1)
|
||||
2. [git](https://git-scm.com)
|
||||
|
||||
## The setup
|
||||
@@ -16,41 +16,15 @@ git clone https://git.maid.zone/stuff/soundcloak
|
||||
cd soundcloak
|
||||
```
|
||||
|
||||
3. Download templ:
|
||||
3. Download required JS modules:
|
||||
|
||||
Currently it's just HLS.js
|
||||
|
||||
```sh
|
||||
go install github.com/a-h/templ/cmd/templ@latest
|
||||
go tool soundcloakctl js download
|
||||
```
|
||||
|
||||
*You might need to add go binaries to your PATH (add this line to your .bashrc / .zshrc / whatever)*
|
||||
|
||||
```sh
|
||||
export PATH=${PATH}:`go env GOPATH`/bin
|
||||
```
|
||||
|
||||
4. Download regexp2cg:
|
||||
|
||||
Not really required, but helps speed up some parts of the code that use regular expressions by generating code for them instead of compiling in runtime.
|
||||
|
||||
```sh
|
||||
go install github.com/dlclark/regexp2cg@main
|
||||
```
|
||||
|
||||
5. Download soundcloakctl:
|
||||
|
||||
Soundcloakctl is helper for soundcloak.
|
||||
|
||||
```sh
|
||||
go install git.maid.zone/stuff/soundcloakctl@master
|
||||
```
|
||||
|
||||
6. Download requried JS modules:
|
||||
|
||||
```sh
|
||||
soundcloakctl js download
|
||||
```
|
||||
|
||||
7. Build binary:
|
||||
4. Build binary:
|
||||
|
||||
This uses the `build` script, which generates code from templates, generates code for regular expiressions, and then builds the binary.
|
||||
|
||||
@@ -69,27 +43,13 @@ git pull
|
||||
|
||||
2. Update dependencies/tools:
|
||||
|
||||
You can skip some parts if the tools/dependencies have not been updated.
|
||||
```sh
|
||||
go get # for go packages
|
||||
go mod download # update tools and dependencies
|
||||
|
||||
go install github.com/a-h/templ/cmd/templ@latest # templ cli
|
||||
|
||||
go install github.com/dlclark/regexp2cg@main # regexp2 codegen cli. not required unless you've installed it
|
||||
|
||||
go install git.maid.zone/stuff/soundcloakctl@master # soundcloakctl
|
||||
|
||||
soundcloakctl js download # re-download JS modules
|
||||
go tool soundcloakctl js download # re-download JS modules
|
||||
```
|
||||
|
||||
3. Clean precompressed static files
|
||||
|
||||
Those are created by the webserver in order to more efficiently serve static files. They have the `.br` and `.gzip` extension. You can easily remove them from all directories using soundcloakctl:
|
||||
```sh
|
||||
soundcloakctl clean
|
||||
```
|
||||
|
||||
4. Run codegen and build the binary:
|
||||
3. Run codegen and build the binary:
|
||||
```sh
|
||||
./build
|
||||
```
|
||||
|
||||
@@ -42,10 +42,24 @@ Soundcloak will now be up at `127.0.0.1:4664` (or the address you specified in y
|
||||
|
||||
## Regular method
|
||||
|
||||
** Not recommended for deployment. **
|
||||
|
||||
Refer to the [developer guide](DEV_GUIDE.md#setup)
|
||||
|
||||
### Extras
|
||||
|
||||
Not required but can help. If using docker, it already does this stuff for you.
|
||||
|
||||
- Precompressing static files
|
||||
|
||||
For more effective file serving: `go tool soundcloakctl -nozstd precompress`
|
||||
|
||||
You will have to run `go tool soundcloakctl clean` and re-run the above command each time static files change.
|
||||
|
||||
- Config codegen
|
||||
|
||||
Can help reduce binary size (if you don't use certain features) and performance (not by much): `go tool soundcloakctl config codegen`
|
||||
|
||||
You will have to re-run this each time you change config or config structure changes
|
||||
|
||||
# Updating your instance
|
||||
|
||||
## Docker
|
||||
@@ -57,22 +71,9 @@ git fetch origin
|
||||
git pull
|
||||
```
|
||||
|
||||
2. Stop the container:
|
||||
|
||||
2. Rebuild and restart the container:
|
||||
```sh
|
||||
docker compose down
|
||||
```
|
||||
|
||||
3. Build the container with updated source code:
|
||||
|
||||
```sh
|
||||
docker compose build
|
||||
```
|
||||
|
||||
4. Start the container:
|
||||
|
||||
```sh
|
||||
docker compose up -d
|
||||
docker compose up --build -d
|
||||
```
|
||||
|
||||
Use `docker-compose` instead of `docker compose` if that fails.
|
||||
|
||||
20
go.mod
20
go.mod
@@ -1,6 +1,6 @@
|
||||
module git.maid.zone/stuff/soundcloak
|
||||
|
||||
go 1.25.0
|
||||
go 1.25.1
|
||||
|
||||
require (
|
||||
github.com/a-h/templ v0.3.943
|
||||
@@ -14,21 +14,39 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
git.maid.zone/stuff/soundcloakctl v0.0.0-20250828150155-48445273aad6 // indirect
|
||||
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect
|
||||
github.com/abema/go-mp4 v1.4.1 // indirect
|
||||
github.com/aler9/writerseeker v1.1.0 // indirect
|
||||
github.com/andybalholm/brotli v1.2.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
|
||||
github.com/cli/browser v1.3.0 // indirect
|
||||
github.com/dlclark/regexp2cg v0.2.0 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/gofiber/schema v1.6.0 // indirect
|
||||
github.com/gofiber/utils/v2 v2.0.0-rc.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/natefinch/atomic v1.0.1 // indirect
|
||||
github.com/philhofer/fwd v1.2.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/sunfish-shogi/bufseekio v0.1.0 // indirect
|
||||
github.com/tinylib/msgp v1.4.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
golang.org/x/crypto v0.41.0 // indirect
|
||||
golang.org/x/mod v0.26.0 // indirect
|
||||
golang.org/x/net v0.43.0 // indirect
|
||||
golang.org/x/sync v0.16.0 // indirect
|
||||
golang.org/x/sys v0.35.0 // indirect
|
||||
golang.org/x/text v0.28.0 // indirect
|
||||
golang.org/x/tools v0.35.0 // indirect
|
||||
)
|
||||
|
||||
tool (
|
||||
git.maid.zone/stuff/soundcloakctl
|
||||
github.com/a-h/templ/cmd/templ
|
||||
github.com/dlclark/regexp2cg
|
||||
)
|
||||
|
||||
24
go.sum
24
go.sum
@@ -1,3 +1,7 @@
|
||||
git.maid.zone/stuff/soundcloakctl v0.0.0-20250828150155-48445273aad6 h1:PlLbk5bPZRDyPjPo9TpQaYKDht19XUfm5+AO09sFBBE=
|
||||
git.maid.zone/stuff/soundcloakctl v0.0.0-20250828150155-48445273aad6/go.mod h1:6+m2N2tJFsrHMZ2GH7h50oAbtECoPrJr12YkZdYucuA=
|
||||
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e h1:HjVbSQHy+dnlS6C3XajZ69NYAb5jbGNfHanvm1+iYlo=
|
||||
github.com/a-h/parse v0.0.0-20250122154542-74294addb73e/go.mod h1:3mnrkvGpurZ4ZrTDbYU84xhwXW2TjTKShSwjRi2ihfQ=
|
||||
github.com/a-h/templ v0.3.943 h1:o+mT/4yqhZ33F3ootBiHwaY4HM5EVaOJfIshvd5UNTY=
|
||||
github.com/a-h/templ v0.3.943/go.mod h1:oCZcnKRf5jjsGpf2yELzQfodLphd2mwecwG4Crk5HBo=
|
||||
github.com/abema/go-mp4 v1.4.1 h1:YoS4VRqd+pAmddRPLFf8vMk74kuGl6ULSjzhsIqwr6M=
|
||||
@@ -8,12 +12,22 @@ github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwTo
|
||||
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
github.com/bogem/id3v2/v2 v2.1.4 h1:CEwe+lS2p6dd9UZRlPc1zbFNIha2mb2qzT1cCEoNWoI=
|
||||
github.com/bogem/id3v2/v2 v2.1.4/go.mod h1:l+gR8MZ6rc9ryPTPkX77smS5Me/36gxkMgDayZ9G1vY=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
||||
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
|
||||
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
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/dlclark/regexp2 v1.11.5-0.20240806004527-5bbbed8ea10b h1:AJKOdc+1fRSJ0/75Jty1npvxUUD0y7hQDg15LMAHhyU=
|
||||
github.com/dlclark/regexp2 v1.11.5-0.20240806004527-5bbbed8ea10b/go.mod h1:YvCrhrh/qlds8EhFKPtJprdXn5fWBllSw1qo99dZyiQ=
|
||||
github.com/dlclark/regexp2cg v0.2.0 h1:YTk+oP9dO74myroxiopnf/zlGOSuTGIuYhRx769YFk4=
|
||||
github.com/dlclark/regexp2cg v0.2.0/go.mod h1:K2c4ctxtSQjzgeMKKgi1rEflZVVJWZWlUUdmtjOp/y8=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
|
||||
github.com/gcottom/mp4meta v0.0.5 h1:pZZAMwRMisx7RaewO7MvjuD3t+tHCYRujpJkQI2yVHU=
|
||||
@@ -43,10 +57,14 @@ github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHP
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
|
||||
github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
|
||||
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e h1:s2RNOM/IGdY0Y6qfTeUKhDawdHDpK9RGBdx80qN4Ttw=
|
||||
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e/go.mod h1:nBdnFKj15wFbf94Rwfq4m30eAcyY9V/IyKAGQFtqkW0=
|
||||
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
|
||||
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/shamaton/msgpack/v2 v2.3.0 h1:eawIa7lQmwRv0V6rdmL/5Ev9KdJHk07eQH3ceJi3BUw=
|
||||
@@ -76,6 +94,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
|
||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
|
||||
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
@@ -83,6 +103,8 @@ golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -103,6 +125,8 @@ golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
|
||||
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -495,6 +495,7 @@ func init() {
|
||||
PlaylistTTL *time.Duration
|
||||
PlaylistCacheCleanDelay *time.Duration
|
||||
UserAgent *string
|
||||
ClientID *string
|
||||
DNSCacheTTL *time.Duration
|
||||
EnableAPI *bool
|
||||
Network *string
|
||||
@@ -561,6 +562,9 @@ func init() {
|
||||
if config.UserAgent != nil {
|
||||
UserAgent = *config.UserAgent
|
||||
}
|
||||
if config.ClientID != nil {
|
||||
ClientID = *config.ClientID
|
||||
}
|
||||
if config.DNSCacheTTL != nil {
|
||||
DNSCacheTTL = *config.DNSCacheTTL * time.Second
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"git.maid.zone/stuff/soundcloak/lib/cfg"
|
||||
"git.maid.zone/stuff/soundcloak/templates"
|
||||
@@ -110,6 +111,24 @@ type Export struct {
|
||||
Preferences *cfg.Preferences `json:",omitempty"`
|
||||
}
|
||||
|
||||
func setPrefs(c fiber.Ctx, p *cfg.Preferences) error {
|
||||
data, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cookie := fasthttp.AcquireCookie()
|
||||
cookie.SetKey("prefs")
|
||||
cookie.SetValueBytes(data)
|
||||
cookie.SetExpire(time.Now().Add(400 * 24 * time.Hour))
|
||||
cookie.SetHTTPOnly(true)
|
||||
cookie.SetSameSite(fasthttp.CookieSameSiteStrictMode)
|
||||
c.Response().Header.SetCookie(cookie)
|
||||
fasthttp.ReleaseCookie(cookie)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Load(r *fiber.App) {
|
||||
r.Get("/_/preferences", func(c fiber.Ctx) error {
|
||||
p, err := Get(c)
|
||||
@@ -157,16 +176,18 @@ func Load(r *fiber.App) {
|
||||
|
||||
if *old.Player == cfg.HLSPlayer {
|
||||
if cfg.ProxyStreams {
|
||||
if p.ProxyStreams == on {
|
||||
switch p.ProxyStreams {
|
||||
case on:
|
||||
old.ProxyStreams = &cfg.True
|
||||
} else if p.ProxyStreams == "" {
|
||||
case "":
|
||||
old.ProxyStreams = &cfg.False
|
||||
}
|
||||
}
|
||||
|
||||
if p.FullyPreloadTrack == on {
|
||||
switch p.FullyPreloadTrack {
|
||||
case on:
|
||||
old.FullyPreloadTrack = &cfg.True
|
||||
} else if p.FullyPreloadTrack == "" {
|
||||
case "":
|
||||
old.FullyPreloadTrack = &cfg.False
|
||||
}
|
||||
|
||||
@@ -182,9 +203,10 @@ func Load(r *fiber.App) {
|
||||
}
|
||||
|
||||
if cfg.ProxyImages {
|
||||
if p.ProxyImages == on {
|
||||
switch p.ProxyImages {
|
||||
case on:
|
||||
old.ProxyImages = &cfg.True
|
||||
} else if p.ProxyImages == "" {
|
||||
case "":
|
||||
old.ProxyImages = &cfg.False
|
||||
}
|
||||
}
|
||||
@@ -215,31 +237,22 @@ func Load(r *fiber.App) {
|
||||
|
||||
old.Player = &p.Player
|
||||
|
||||
data, err := json.Marshal(old)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "prefs",
|
||||
Value: cfg.B2s(data),
|
||||
Expires: time.Now().Add(400 * 24 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
SameSite: "strict",
|
||||
})
|
||||
setPrefs(c, &old)
|
||||
|
||||
return c.Redirect().To("/_/preferences")
|
||||
})
|
||||
|
||||
r.Get("/_/preferences/reset", func(c fiber.Ctx) error {
|
||||
// c.ClearCookie("prefs")
|
||||
c.Cookie(&fiber.Cookie{ // I've had some issues with c.ClearCookie() method, so using this workaround for now
|
||||
Name: "prefs",
|
||||
Value: "{}",
|
||||
Expires: time.Now().Add(400 * 24 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
SameSite: "strict",
|
||||
})
|
||||
// do not use (fiber.Ctx).Cookie() ts pmo icl
|
||||
|
||||
cookie := fasthttp.AcquireCookie()
|
||||
cookie.SetKey("prefs")
|
||||
cookie.SetValue("{}")
|
||||
cookie.SetExpire(time.Now().Add(400 * 24 * time.Hour))
|
||||
cookie.SetHTTPOnly(true)
|
||||
cookie.SetSameSite(fasthttp.CookieSameSiteStrictMode)
|
||||
c.Response().Header.SetCookie(cookie)
|
||||
fasthttp.ReleaseCookie(cookie)
|
||||
|
||||
return c.Redirect().To("/_/preferences")
|
||||
})
|
||||
@@ -279,18 +292,7 @@ func Load(r *fiber.App) {
|
||||
|
||||
Defaults(p.Preferences)
|
||||
|
||||
data, err := json.Marshal(p.Preferences)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "prefs",
|
||||
Value: cfg.B2s(data),
|
||||
Expires: time.Now().Add(400 * 24 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
SameSite: "strict",
|
||||
})
|
||||
setPrefs(c, p.Preferences)
|
||||
|
||||
return c.Redirect().To("/_/preferences")
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ var genericClient = &fasthttp.Client{
|
||||
// var scriptsRegex = regexp2.MustCompile(`^<script crossorigin src="(https://a-v2\.sndcdn\.com/assets/.+\.js)"></script>$`, 2)
|
||||
// var scriptRegex = regexp2.MustCompile(`^<script crossorigin src="(https://a-v2\.sndcdn\.com/assets/0-.+\.js)"></script>$`, 2)
|
||||
|
||||
//go:generate regexp2cg -package sc -o regexp2_codegen.go
|
||||
//go:generate go tool regexp2cg -package sc -o regexp2_codegen.go
|
||||
var clientIdRegex = regexp2.MustCompile(`client_id:"([A-Za-z0-9]{32})"`, 0) //regexp2.MustCompile(`\("client_id=([A-Za-z0-9]{32})"\)`, 0)
|
||||
var ErrVersionNotFound = errors.New("version not found")
|
||||
var ErrScriptNotFound = errors.New("script not found")
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/dlclark/regexp2"
|
||||
)
|
||||
|
||||
//go:generate regexp2cg -package textparsing -o regexp2_codegen.go
|
||||
//go:generate go tool regexp2cg -package textparsing -o regexp2_codegen.go
|
||||
var emailre = regexp2.MustCompile(`^[-a-zA-Z0-9%._\+~#=]+@[-a-zA-Z0-9%._\+~=&]{2,256}\.[a-z]{1,6}$`, 0)
|
||||
var theregex = regexp2.MustCompile(`@[a-zA-Z0-9\-_]+|(?:https?:\/\/[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{1,6}[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)|(?:[-a-zA-Z0-9%._\+~#=]+@[-a-zA-Z0-9%._\+~=&]{2,256}\.[a-z]{1,6})`, 0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user