Files
MeBox/internal/service/service_library_normalize.go
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

85 lines
2.0 KiB
Go

package service
import (
"context"
"path/filepath"
"strings"
"github.com/truewhile/MeBox/internal/model"
)
func (c *Container) NormalizeLocalLibraryPaths(ctx context.Context) error {
if c == nil || c.Repo == nil || c.Repo.Library == nil || c.Repo.DB == nil {
return nil
}
libs, err := c.Repo.Library.List(ctx)
if err != nil {
return err
}
for _, lib := range libs {
if _, ok := ParseCloudLibraryMount(lib.Path); ok {
continue
}
if len(lib.Roots) == 0 {
normalized := normalizePersistedLocalLibraryPath(lib.Path)
if sameLibraryPath(normalized, lib.Path) {
continue
}
if err := c.Repo.DB.WithContext(ctx).
Model(&model.Library{}).
Where("id = ?", lib.ID).
Update("path", normalized).Error; err != nil {
return err
}
continue
}
primaryPath := ""
for i, root := range lib.Roots {
if _, ok := ParseCloudLibraryMount(root.Path); ok {
if i == 0 {
primaryPath = root.Path
}
continue
}
normalized := normalizePersistedLocalLibraryPath(root.Path)
if i == 0 {
primaryPath = normalized
}
if sameLibraryPath(normalized, root.Path) || strings.TrimSpace(root.ID) == "" {
continue
}
if err := c.Repo.DB.WithContext(ctx).
Model(&model.LibraryRoot{}).
Where("id = ?", root.ID).
Update("path", normalized).Error; err != nil {
return err
}
}
if strings.TrimSpace(primaryPath) != "" && !sameLibraryPath(primaryPath, lib.Path) {
if err := c.Repo.DB.WithContext(ctx).
Model(&model.Library{}).
Where("id = ?", lib.ID).
Update("path", primaryPath).Error; err != nil {
return err
}
}
}
return nil
}
func normalizePersistedLocalLibraryPath(pathValue string) string {
pathValue = strings.TrimSpace(pathValue)
if pathValue == "" {
return ""
}
if !isRelativeVolumeMarkerPath(pathValue) {
return filepath.Clean(pathValue)
}
return resolveMappedDestinationPath(pathValue)
}
func (c *Container) NormalizeCloudLibraryTypes(ctx context.Context) error {
// 网盘后端已移除,不再存在 cloud:// 挂载库类型需修正。
return nil
}