From cc8fa7101fc9c4b3eb0078538e0298b54bdc3613 Mon Sep 17 00:00:00 2001 From: cld9x <46501326+cld9x@users.noreply.github.com> Date: Mon, 10 Jan 2022 23:17:20 +0100 Subject: [PATCH] Drop fileb0x in favour of native go:embed directive (#647) --- .assets.toml | 14 ---------- .gitignore | 1 - .gitpod.dockerfile | 1 - .goreleaser.yml | 1 - Dockerfile | 3 +- README.md | 3 +- go.mod | 66 +++++++++++++++++++++++++++++++++++++++++++- main.go | 2 -- pkg/server/server.go | 4 +-- pkg/tasks/dms.go | 4 +-- pkg/tasks/state.go | 18 ++++++++---- pkg/tray/main.go | 8 ++++-- ui/fs.go | 6 ++++ 13 files changed, 95 insertions(+), 36 deletions(-) delete mode 100644 .assets.toml create mode 100644 ui/fs.go diff --git a/.assets.toml b/.assets.toml deleted file mode 100644 index 1b0ebc5c8..000000000 --- a/.assets.toml +++ /dev/null @@ -1,14 +0,0 @@ -pkg = "assets" -dest = "./pkg/assets/" -fmt = false - -clean = true -output = "ab0x.go" -unexporTed = false -spread = true -debug = false - -[[custom]] -files = ["./ui/dist/"] -base = "./ui/dist/" -exclude = [".DS_Store"] diff --git a/.gitignore b/.gitignore index e68d765e4..e48fb0ca9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ test.db /test_cache /dist/ -/pkg/assets/ node_modules/ /ui/dist/ diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile index a60cdf976..58a7c4398 100644 --- a/.gitpod.dockerfile +++ b/.gitpod.dockerfile @@ -11,7 +11,6 @@ RUN export PATH=$(echo "$PATH" | sed -e 's|:/workspace/go/bin||' -e 's|:/home/gi ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH RUN go get -u -v \ - github.com/UnnoTed/fileb0x \ github.com/cosmtrek/air && \ sudo rm -rf $GOPATH/src && \ sudo rm -rf $GOPATH/pkg diff --git a/.goreleaser.yml b/.goreleaser.yml index e50370bd1..68a455642 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,7 +1,6 @@ before: hooks: - go mod download - - go get github.com/UnnoTed/fileb0x - go generate ./... builds: diff --git a/Dockerfile b/Dockerfile index f82f75ccc..549fe29f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,7 @@ ENV GO_VERSION=1.17.5 \ GOPATH=$HOME/go-packages \ GOROOT=$HOME/go ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH -RUN curl -fsSL https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz | tar -xzv \ - && go get -u -v github.com/UnnoTed/fileb0x +RUN curl -fsSL https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz | tar -xzv WORKDIR /app ADD . /app diff --git a/README.md b/README.md index 2e2d8f933..fa4a87860 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,9 @@ Ask your questions and suggest features on [Discord](https://discord.gg/wdCHXAG) Make sure you have following installed: -- Go 1.13 +- Go 1.17 - Node.js 12.x - Yarn 1.17.x -- fileb0x (run `go get github.com/UnnoTed/fileb0x` outside project directory) - air (run `go get github.com/cosmtrek/air` outside project directory) Once all of the above is installed, running `yarn dev` from project directory launches file-watchers providing livereload for both Go and JavaScript. diff --git a/go.mod b/go.mod index 3bccd4b4c..a9c599746 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/xbapps/xbvr -go 1.16 +go 1.17 require ( github.com/ProtonMail/go-appdir v1.1.0 @@ -65,22 +65,86 @@ require ( ) require ( + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/RoaringBitmap/roaring v0.4.23 // indirect github.com/anacrolix/envpprof v1.0.0 // indirect github.com/anacrolix/missinggo v1.1.0 // indirect + github.com/andybalholm/cascadia v1.3.1 // indirect github.com/antchfx/htmlquery v1.0.0 // indirect github.com/antchfx/xmlquery v1.0.0 // indirect github.com/antchfx/xpath v0.0.0-20190129040759-c8489ed3251e // indirect + github.com/beorn7/perks v1.0.1 // indirect + github.com/blevesearch/go-porterstemmer v1.0.3 // indirect + github.com/blevesearch/mmap-go v1.0.2 // indirect + github.com/blevesearch/segment v0.9.0 // indirect + github.com/blevesearch/snowballstem v0.9.0 // indirect + github.com/blevesearch/zap/v11 v11.0.14 // indirect + github.com/blevesearch/zap/v12 v12.0.14 // indirect + github.com/blevesearch/zap/v13 v13.0.6 // indirect + github.com/blevesearch/zap/v14 v14.0.5 // indirect + github.com/blevesearch/zap/v15 v15.0.3 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/couchbase/vellum v1.0.2 // indirect github.com/dsnet/compress v0.0.1 // indirect + github.com/fcjr/aia-transport-go v1.2.2 // indirect + github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect + github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect + github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect + github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 // indirect + github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 // indirect + github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect + github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/swag v0.19.15 // indirect + github.com/go-sql-driver/mysql v1.5.0 // indirect + github.com/go-stack/stack v1.8.0 // indirect github.com/gobwas/glob v0.2.3 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/snappy v0.0.3 // indirect + github.com/google/btree v1.0.0 // indirect + github.com/gorilla/websocket v1.4.2 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/json-iterator/go v1.1.11 // indirect github.com/kennygrant/sanitize v1.2.4 // indirect + github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-colorable v0.1.1 // indirect github.com/mattn/go-isatty v0.0.7 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect github.com/mozillazg/go-unidecode v0.1.0 // indirect + github.com/mschoch/smat v0.2.0 // indirect + github.com/muesli/smartcrop v0.3.0 // indirect github.com/nwaples/rardecode v1.0.0 // indirect + github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect + github.com/philhofer/fwd v1.0.0 // indirect github.com/pierrec/lz4 v2.0.5+incompatible // indirect + github.com/prometheus/client_golang v1.11.0 // indirect + github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/common v0.26.0 // indirect + github.com/prometheus/procfs v0.6.0 // indirect + github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect + github.com/steveyen/gtreap v0.1.0 // indirect github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea // indirect + github.com/tidwall/match v1.0.3 // indirect + github.com/tidwall/pretty v1.0.2 // indirect + github.com/tinylib/msgp v1.1.0 // indirect + github.com/ugorji/go/codec v1.1.13 // indirect + github.com/ulikunitz/xz v0.5.6 // indirect + github.com/willf/bitset v1.1.10 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect + go.etcd.io/bbolt v1.3.5 // indirect + golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/sourcemap.v1 v1.0.5 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + willnorris.com/go/gifresize v1.0.0 // indirect ) diff --git a/main.go b/main.go index 711e7abd6..d3f655d69 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,5 @@ package main -//go:generate fileb0x .assets.toml - import ( "github.com/xbapps/xbvr/pkg/server" ) diff --git a/pkg/server/server.go b/pkg/server/server.go index d09a8c031..359f9dd5e 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -22,13 +22,13 @@ import ( "github.com/rs/cors" "github.com/xbapps/xbvr/pkg/analytics" "github.com/xbapps/xbvr/pkg/api" - "github.com/xbapps/xbvr/pkg/assets" "github.com/xbapps/xbvr/pkg/common" "github.com/xbapps/xbvr/pkg/config" "github.com/xbapps/xbvr/pkg/migrations" "github.com/xbapps/xbvr/pkg/models" "github.com/xbapps/xbvr/pkg/session" "github.com/xbapps/xbvr/pkg/tasks" + "github.com/xbapps/xbvr/ui" "willnorris.com/go/imageproxy" ) @@ -121,7 +121,7 @@ func StartServer(version, commit, branch, date string) { // Static files if !common.EnvConfig.Debug { - authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.FileServer(assets.HTTP)) + authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.StripPrefix("/dist/", http.FileServer(http.FS(ui.Assets)))) } else { authHandle("/ui/", common.IsUIAuthEnabled(), common.GetUISecret, http.FileServer(http.Dir("ui/dist"))) } diff --git a/pkg/tasks/dms.go b/pkg/tasks/dms.go index 1919168f1..8daacae27 100644 --- a/pkg/tasks/dms.go +++ b/pkg/tasks/dms.go @@ -10,9 +10,9 @@ import ( "time" "github.com/nfnt/resize" - "github.com/xbapps/xbvr/pkg/assets" "github.com/xbapps/xbvr/pkg/config" "github.com/xbapps/xbvr/pkg/dms/dlna/dms" + "github.com/xbapps/xbvr/ui" ) type dmsConfig struct { @@ -103,7 +103,7 @@ func initDMS() { } func getIconReader(fn string) (io.Reader, error) { - b, err := assets.ReadFile("dlna/" + fn + ".png") + b, err := ui.Assets.ReadFile("dist/dlna/" + fn + ".png") return bytes.NewReader(b), err } diff --git a/pkg/tasks/state.go b/pkg/tasks/state.go index 66cfa28cc..fabdd05eb 100644 --- a/pkg/tasks/state.go +++ b/pkg/tasks/state.go @@ -1,24 +1,32 @@ package tasks import ( + "io/fs" "strings" - "github.com/xbapps/xbvr/pkg/assets" "github.com/xbapps/xbvr/pkg/common" "github.com/xbapps/xbvr/pkg/config" + "github.com/xbapps/xbvr/ui" ) func UpdateState() { // DLNA - config.State.DLNA.Running = IsDMSStarted() - config.State.DLNA.RecentIP = config.RecentIPAddresses - dlnaImages, _ := assets.WalkDirs("dlna", false) + var dlnaImages []string + fs.WalkDir(ui.Assets, "dist/dlna", func(path string, d fs.DirEntry, err error) error { + if !d.IsDir() { + dlnaImages = append(dlnaImages, path) + } + return nil + }) config.State.DLNA.Images = make([]string, 0) for _, v := range dlnaImages { - config.State.DLNA.Images = append(config.State.DLNA.Images, strings.Replace(strings.Split(v, "/")[1], ".png", "", -1)) + config.State.DLNA.Images = append(config.State.DLNA.Images, strings.Replace(strings.Split(v, "/")[2], ".png", "", -1)) } + config.State.DLNA.Running = IsDMSStarted() + config.State.DLNA.RecentIP = config.RecentIPAddresses + config.SaveState() } diff --git a/pkg/tray/main.go b/pkg/tray/main.go index c99cbdfac..af3130a95 100644 --- a/pkg/tray/main.go +++ b/pkg/tray/main.go @@ -9,9 +9,9 @@ import ( "github.com/getlantern/systray" "github.com/marcsauter/single" "github.com/skratchdot/open-golang/open" - "github.com/xbapps/xbvr/pkg/assets" "github.com/xbapps/xbvr/pkg/config" "github.com/xbapps/xbvr/pkg/server" + "github.com/xbapps/xbvr/ui" ) var version = "CURRENT" @@ -38,9 +38,11 @@ func onReady() { }() if runtime.GOOS == "windows" { - systray.SetIcon(assets.FileIconsXbvrWinIco) + iconData, _ := ui.Assets.ReadFile("dist/icons/xbvr-win.ico") + systray.SetIcon(iconData) } else { - systray.SetIcon(assets.FileIconsXbvr128Png) + iconData, _ := ui.Assets.ReadFile("dist/icons/xbvr-128.png") + systray.SetIcon(iconData) } systray.SetTooltip(fmt.Sprintf("XBVR")) diff --git a/ui/fs.go b/ui/fs.go new file mode 100644 index 000000000..40aa37c6f --- /dev/null +++ b/ui/fs.go @@ -0,0 +1,6 @@ +package ui + +import "embed" + +//go:embed dist +var Assets embed.FS