Files
MeBox/internal/service/public_url.go
T
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

50 lines
1.7 KiB
Go

package service
import (
"context"
"net/url"
"strings"
"github.com/truewhile/MeBox/internal/config"
"github.com/truewhile/MeBox/internal/repository"
)
// PublicServerURL returns the operator-configured public MeBox base
// URL. It is intentionally read from Setting first so Docker users only need to
// fill one domain in the admin settings page after deployment.
func PublicServerURL(ctx context.Context, repo *repository.Container, cfg *config.Config) string {
for _, key := range []string{"app.server_url", "server.url", "public.server_url", "strm.base_url"} {
if repo != nil && repo.Setting != nil {
if value, err := repo.Setting.Get(ctx, key); err == nil && strings.TrimSpace(value) != "" {
return strings.TrimRight(strings.TrimSpace(value), "/")
}
}
}
if cfg != nil && strings.TrimSpace(cfg.App.ServerURL) != "" {
return strings.TrimRight(strings.TrimSpace(cfg.App.ServerURL), "/")
}
return ""
}
// BuildPublicAPIURL builds an API URL. Without a public base it returns a
// relative same-origin URL; with a configured domain it returns an absolute URL.
func BuildPublicAPIURL(ctx context.Context, repo *repository.Container, cfg *config.Config, apiPath string, query url.Values) string {
apiPath = "/" + strings.TrimLeft(strings.TrimSpace(apiPath), "/")
if query != nil && len(query) > 0 {
apiPath += "?" + query.Encode()
}
base := PublicServerURL(ctx, repo, cfg)
if base == "" {
return apiPath
}
u, err := url.Parse(base)
if err != nil || u.Scheme == "" || u.Host == "" {
return apiPath
}
u.Path = strings.TrimRight(u.Path, "/") + "/" + strings.TrimLeft(strings.Split(apiPath, "?")[0], "/")
if query != nil && len(query) > 0 {
u.RawQuery = query.Encode()
}
return u.String()
}