Skip to content

Commit

Permalink
filebrowser container support
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Oct 17, 2024
1 parent 2ae0b26 commit aee8773
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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: {}
10 changes: 10 additions & 0 deletions public/js/components/pages/filebrowser/Filebrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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$/);
},
Expand Down Expand Up @@ -159,6 +161,14 @@ export default {
},
template: /*html*/`
<default-layout icon="folder" title="Filebrowser" :breadcrumb="breadcrumb">
<div class="row" v-if="filebrowser_enabled">
<div class="col-md-12">
<div class="alert alert-info">
<i class="fa fa-info"></i>
<b>Note: </b> To upload larger files use the dedicated <a href="filebrowser/">filebrowser</a> interface and enable the maintenance mode for database files
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="input-group">
Expand Down
3 changes: 2 additions & 1 deletion public/js/service/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
export const get_maintenance = () => store.maintenance;
export const get_filebrowser_enabled = () => store.filebrowser_enabled;
2 changes: 2 additions & 0 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Config struct {
Webdev bool
Servername string
EnabledFeatures []string
FilebrowserURL string
InstallMtuiMod bool
AutoReconfigureMods bool
LogStreamURL string
Expand Down Expand Up @@ -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"),
Expand Down
20 changes: 20 additions & 0 deletions web/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"mtui/public"
"mtui/types"
"net/http"
"net/http/httputil"
"net/url"
"os"
"time"

Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions web/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit aee8773

Please sign in to comment.