Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration options #1449

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type EnvConfigSpec struct {
UIUsername string `envconfig:"UI_USERNAME" required:"false"`
UIPassword string `envconfig:"UI_PASSWORD" required:"false"`
DatabaseURL string `envconfig:"DATABASE_URL" required:"false" default:""`
WsAddr string `envconfig:"XBVR_WS_ADDR" required:"false" default:""`
WebPort int `envconfig:"XBVR_WEB_PORT" required:"false" default:"0"`
}

var EnvConfig EnvConfigSpec
Expand Down
77 changes: 61 additions & 16 deletions pkg/common/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var VideoPreviewDir string
var VideoThumbnailDir string
var ScriptHeatmapDir string
var DownloadDir string
var WebPort int

func DirSize(path string) (int64, error) {
var size int64
Expand All @@ -38,41 +39,76 @@ func DirSize(path string) (int64, error) {

func InitPaths() {

enableLocalStorage := flag.Bool("localstorage", false, "Use local folder to store application data")
enableLocalStorage := flag.Bool("localstorage", false, "Optional: Use local folder to store application data")
app_dir := flag.String("app_dir", "", "Optional: path to the application directory")
cache_dir := flag.String("cache_dir", "", "Optional: path to the tempoarary scraper cache directory")
imgproxy_dir := flag.String("imgproxy_dir", "", "Optional: path to the imageproxy directory")
search_dir := flag.String("search_dir", "", "Optional: path to the Search Index directory")
preview_dir := flag.String("preview_dir", "", "Optional: path to the Scraper Cache directory")
scriptsheatmap_dir := flag.String("scripts_heatmap_dir", "", "Optional: path to the scripts_heatmap directory")
databaseurl := flag.String("database_url", "", "Optional: override default database path")
web_port := flag.Int("web_port", 0, "Optional: override default Web Page port 9999")
ws_addr := flag.String("ws_addr", "", "Optional: override default Websocket address from the default 0.0.0.0:9998")

flag.Parse()

if *enableLocalStorage {
executable, err := os.Executable()
if *app_dir == "" {
tmp := os.Getenv("XBVR_APPDIR")
app_dir = &tmp
}
if *app_dir == "" {
if *enableLocalStorage {
executable, err := os.Executable()

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

AppDir = filepath.Dir(executable)
AppDir = filepath.Dir(executable)
} else {
AppDir = appdir.New("xbvr").UserConfig()
}
} else {
AppDir = appdir.New("xbvr").UserConfig()
AppDir = *app_dir
}

CacheDir = filepath.Join(AppDir, "cache")
CacheDir = getPath(*cache_dir, "XBVR_CACHEDIR", "cache")
BinDir = filepath.Join(AppDir, "bin")
ImgDir = filepath.Join(AppDir, "imageproxy")
ImgDir = getPath(*imgproxy_dir, "XBVR_IMAGEPROXYDIR", "imageproxy")
MetricsDir = filepath.Join(AppDir, "metrics")
HeatmapDir = filepath.Join(AppDir, "heatmap")
IndexDirV2 = filepath.Join(AppDir, "search-v2")
IndexDirV2 = getPath(*search_dir, "XBVR_SEARCHDIR", "search-v2")

ScrapeCacheDir = filepath.Join(CacheDir, "scrape_cache")

VideoPreviewDir = filepath.Join(AppDir, "video_preview")
VideoPreviewDir = getPath(*preview_dir, "XBVR_VIDEOPREVIEWDIR", "video_preview")
VideoThumbnailDir = filepath.Join(AppDir, "video_thumbnail")
ScriptHeatmapDir = filepath.Join(AppDir, "script_heatmap")
ScriptHeatmapDir = getPath(*scriptsheatmap_dir, "XBVR_SCRIPTHEATMAPDIR", "script_heatmap")

DownloadDir = filepath.Join(AppDir, "download")

// Initialize DATABASE_URL once appdir path is known
if EnvConfig.DatabaseURL != "" {
DATABASE_URL = EnvConfig.DatabaseURL
if *databaseurl != "" {
DATABASE_URL = *databaseurl
} else {
DATABASE_URL = fmt.Sprintf("sqlite:%v", filepath.Join(AppDir, "main.db"))
if EnvConfig.DatabaseURL != "" {
DATABASE_URL = EnvConfig.DatabaseURL
} else {
DATABASE_URL = fmt.Sprintf("sqlite:%v", filepath.Join(AppDir, "main.db"))
}
}

if *web_port != 0 {
WebPort = *web_port
} else {
WebPort = EnvConfig.WebPort
}
if *ws_addr != "" {
WsAddr = *ws_addr
} else {
if EnvConfig.WsAddr != "" {
WsAddr = EnvConfig.WsAddr
}
}

_ = os.MkdirAll(AppDir, os.ModePerm)
Expand All @@ -86,3 +122,12 @@ func InitPaths() {
_ = os.MkdirAll(ScriptHeatmapDir, os.ModePerm)
_ = os.MkdirAll(DownloadDir, os.ModePerm)
}
func getPath(commandLinePath string, environmentName string, directoryName string) string {
if commandLinePath != "" {
return commandLinePath
}
if os.Getenv(environmentName) != "" {
return os.Getenv(environmentName)
}
return filepath.Join(AppDir, directoryName)
}
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ func LoadConfig() {
if err := json.Unmarshal([]byte(obj.Value), &Config); err != nil {
common.Log.Error("Failed to load config from database")
}
if common.WebPort != 0 && common.WebPort != Config.Server.Port {
Config.Server.Port = common.WebPort
SaveConfig()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/Socket.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default {
onReconnectSuccess: () => {
this.wsStatus = 'connected'
}
})
})

ws.subscribe('service.log', (dataArr, dataObj) => {
if (dataArr.argsDict.level == 'debug') {
Expand Down
Loading