mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
b0fe40142a
* 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>
95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
)
|
|
|
|
func (p *OrganizePipelineService) syncScrapedOrganizedNames(ctx context.Context, opts OrganizeOptions, res *OrganizeResult, path string) {
|
|
if p == nil || p.organizer == nil || p.repo == nil || p.repo.DB == nil || res == nil || res.DryRun {
|
|
return
|
|
}
|
|
for _, target := range organizeNameSyncTargets(res, path) {
|
|
media := p.mediaByPath(ctx, target)
|
|
if media == nil {
|
|
continue
|
|
}
|
|
before := media.Path
|
|
syncOpts := opts
|
|
syncOpts.SourcePath = ""
|
|
syncOpts.TransferMode = TransferMove
|
|
after, err := p.organizer.SyncMediaPathWithMetadata(ctx, media.ID, syncOpts)
|
|
if err != nil {
|
|
res.Errors = append(res.Errors, filepath.Base(before)+": "+err.Error())
|
|
if p.log != nil {
|
|
p.log.Warn("organize pipeline scrape rename failed",
|
|
zap.String("media", media.ID),
|
|
zap.String("path", before),
|
|
zap.Error(err))
|
|
}
|
|
continue
|
|
}
|
|
if samePath(before, after) {
|
|
continue
|
|
}
|
|
res.Items = append(res.Items, OrganizePreviewItem{
|
|
Source: before,
|
|
Target: after,
|
|
Action: "organize",
|
|
Reason: "scraped metadata rename",
|
|
Title: media.Title,
|
|
})
|
|
if p.log != nil {
|
|
p.log.Info("organize pipeline synced scraped media name",
|
|
zap.String("media", media.ID),
|
|
zap.String("from", before),
|
|
zap.String("to", after))
|
|
}
|
|
}
|
|
}
|
|
|
|
func organizeNameSyncTargets(res *OrganizeResult, path string) []string {
|
|
seen := map[string]struct{}{}
|
|
out := make([]string, 0, len(res.Items)+1)
|
|
add := func(value string) {
|
|
value = strings.TrimSpace(value)
|
|
if value == "" {
|
|
return
|
|
}
|
|
key := strings.ToLower(filepath.Clean(value))
|
|
if _, ok := seen[key]; ok {
|
|
return
|
|
}
|
|
seen[key] = struct{}{}
|
|
out = append(out, value)
|
|
}
|
|
for _, item := range res.Items {
|
|
switch item.Action {
|
|
case "organize", "replace", "reclassify":
|
|
add(item.Target)
|
|
}
|
|
}
|
|
add(path)
|
|
return out
|
|
}
|
|
|
|
func (p *OrganizePipelineService) mediaByPath(ctx context.Context, path string) *model.Media {
|
|
path = filepath.Clean(strings.TrimSpace(path))
|
|
if path == "" || path == "." {
|
|
return nil
|
|
}
|
|
var media model.Media
|
|
if err := p.repo.DB.WithContext(ctx).
|
|
Where("path = ? AND deleted_at IS NULL", path).
|
|
Limit(1).
|
|
Take(&media).Error; err != nil {
|
|
return nil
|
|
}
|
|
return &media
|
|
}
|