From aee8773cd26754571d0090aebf56a1ca99ebfc9a Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Thu, 17 Oct 2024 12:05:34 +0200 Subject: [PATCH] filebrowser container support --- docker-compose.yml | 14 +++++++++++++ .../pages/filebrowser/Filebrowser.js | 10 ++++++++++ public/js/service/stats.js | 3 ++- types/config.go | 2 ++ web/setup.go | 20 +++++++++++++++++++ web/stats.go | 6 ++++-- 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 239ecc10..08bb19bb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,6 +19,7 @@ services: SERVER_NAME: "dev-server" DEFAULT_THEME: "darkly" ENABLE_FEATURES: "shell,luashell,minetest_config,docker,modmanagement,signup,chat,minetest_web" + FILEBROWSER_URL: "http://filebrowser/" INSTALL_MTUI_MOD: "true" MINETEST_CONFIG: "/world/minetest.conf" GEOIP_API: "https://hosting.minetest.ch/api/geoip" @@ -41,7 +42,20 @@ services: working_dir: /app command: ["go", "run", "."] + filebrowser: + image: filebrowser/filebrowser:v2.31.2 + ports: + - 8081:80 + environment: + FB_DATABASE: /database/filebrowser.db + FB_BASEURL: /filebrowser + FB_NOAUTH: "true" + volumes: + - world_dir:/srv + - filebrowser_db:/database + volumes: go_cache: {} go_dir: {} world_dir: {} + filebrowser_db: {} \ No newline at end of file diff --git a/public/js/components/pages/filebrowser/Filebrowser.js b/public/js/components/pages/filebrowser/Filebrowser.js index 128d8dc2..362f5a4c 100644 --- a/public/js/components/pages/filebrowser/Filebrowser.js +++ b/public/js/components/pages/filebrowser/Filebrowser.js @@ -15,6 +15,7 @@ import format_size from "../../../util/format_size.js"; import format_time from "../../../util/format_time.js"; import { START, FILEBROWSER } from "../../Breadcrumb.js"; import { can_edit } from "./common.js"; +import { get_filebrowser_enabled } from "../../../service/stats.js"; export default { props: ["pathMatch"], @@ -107,6 +108,7 @@ export default { }); }, can_edit: can_edit, + filebrowser_enabled: get_filebrowser_enabled, is_json_profile: function(filename) { return filename.match(/^profile-.*.json$/); }, @@ -159,6 +161,14 @@ export default { }, template: /*html*/` +
+
+
+ + Note: To upload larger files use the dedicated filebrowser interface and enable the maintenance mode for database files +
+
+
diff --git a/public/js/service/stats.js b/public/js/service/stats.js index c1c05990..302b12e6 100644 --- a/public/js/service/stats.js +++ b/public/js/service/stats.js @@ -18,4 +18,5 @@ export const stop_polling = () => clearInterval(handle); export const get_player_count = () => store.player_count; export const get_players = () => store.players; -export const get_maintenance = () => store.maintenance; \ No newline at end of file +export const get_maintenance = () => store.maintenance; +export const get_filebrowser_enabled = () => store.filebrowser_enabled; \ No newline at end of file diff --git a/types/config.go b/types/config.go index 078c73ec..d492497c 100644 --- a/types/config.go +++ b/types/config.go @@ -18,6 +18,7 @@ type Config struct { Webdev bool Servername string EnabledFeatures []string + FilebrowserURL string InstallMtuiMod bool AutoReconfigureMods bool LogStreamURL string @@ -48,6 +49,7 @@ func NewConfig(world_dir string) *Config { Webdev: os.Getenv("WEBDEV") == "true", Servername: os.Getenv("SERVER_NAME"), EnabledFeatures: strings.Split(os.Getenv("ENABLE_FEATURES"), ","), + FilebrowserURL: os.Getenv("FILEBROWSER_URL"), InstallMtuiMod: os.Getenv("INSTALL_MTUI_MOD") == "true", AutoReconfigureMods: os.Getenv("AUTORECONFIGURE_MODS") == "true", LogStreamURL: os.Getenv("LOG_STREAM_URL"), diff --git a/web/setup.go b/web/setup.go index 0f857c91..cd6663f3 100644 --- a/web/setup.go +++ b/web/setup.go @@ -5,6 +5,8 @@ import ( "mtui/public" "mtui/types" "net/http" + "net/http/httputil" + "net/url" "os" "time" @@ -28,6 +30,24 @@ func Setup(a *app.App) error { return err } + if a.Config.FilebrowserURL != "" { + // enable filebrowser access with "server" priv + remote, err := url.Parse(a.Config.FilebrowserURL) + if err != nil { + panic(err) + } + + handler := func(p *httputil.ReverseProxy) func(http.ResponseWriter, *http.Request) { + return api.SecurePriv("server", func(w http.ResponseWriter, r *http.Request, c *types.Claims) { + r.Host = remote.Host + p.ServeHTTP(w, r) + }) + } + + proxy := httputil.NewSingleHostReverseProxy(remote) + r.PathPrefix("/filebrowser/").HandlerFunc(handler(proxy)) + } + // always on api r.HandleFunc("/api/maintenance", api.SecurePriv(types.PRIV_SERVER, api.GetMaintenanceMode)).Methods(http.MethodGet) r.HandleFunc("/api/maintenance", api.SecurePriv(types.PRIV_SERVER, api.EnableMaintenanceMode)).Methods(http.MethodPut) diff --git a/web/stats.go b/web/stats.go index 7c6eae3a..2b40c830 100644 --- a/web/stats.go +++ b/web/stats.go @@ -30,13 +30,15 @@ func (a *Api) StatsEventListener(c chan *bridge.CommandResponse) { type StatResponse struct { *command.StatsCommand - Maintenance bool `json:"maintenance"` + Maintenance bool `json:"maintenance"` + FilebrowserEnabled bool `json:"filebrowser_enabled"` } func (a *Api) GetStats(w http.ResponseWriter, r *http.Request, claims *types.Claims) { sc := &StatResponse{ - StatsCommand: &command.StatsCommand{}, + StatsCommand: &command.StatsCommand{}, + FilebrowserEnabled: a.app.Config.FilebrowserURL != "", } sc.Maintenance = a.app.MaintenanceMode.Load()