Skip to content

Commit

Permalink
Drop fileb0x in favour of native go:embed directive (xbapps#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
cld9x authored Jan 10, 2022
1 parent b2a7f09 commit cc8fa71
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 36 deletions.
14 changes: 0 additions & 14 deletions .assets.toml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test.db
/test_cache

/dist/
/pkg/assets/

node_modules/
/ui/dist/
Expand Down
1 change: 0 additions & 1 deletion .gitpod.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
before:
hooks:
- go mod download
- go get github.com/UnnoTed/fileb0x
- go generate ./...

builds:
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
66 changes: 65 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/xbapps/xbvr

go 1.16
go 1.17

require (
github.com/ProtonMail/go-appdir v1.1.0
Expand Down Expand Up @@ -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
)
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package main

//go:generate fileb0x .assets.toml

import (
"github.com/xbapps/xbvr/pkg/server"
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/tasks/dms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 13 additions & 5 deletions pkg/tasks/state.go
Original file line number Diff line number Diff line change
@@ -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()
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/tray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"))

Expand Down
6 changes: 6 additions & 0 deletions ui/fs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ui

import "embed"

//go:embed dist
var Assets embed.FS

0 comments on commit cc8fa71

Please sign in to comment.