This commit is contained in:
toom1996
2026-10-18 17:42:10 +08:00
parent 1b06bd5bda
commit 1de1ec46a6
58 changed files with 5281 additions and 19191 deletions

View File

@ -27,6 +27,7 @@ import (
"fashionapi/internal/repository"
"fashionapi/internal/router"
"fashionapi/internal/service"
"fashionapi/internal/vision"
"github.com/gin-gonic/gin"
)
@ -169,9 +170,30 @@ func main() {
} else {
slog.Info("图片存储(本地)", "prefix", cfg.Upload.URLPrefix)
}
// 视觉服务(FashionSigLIP):可选,仅用于后台「疑似同款」提示,不参与任何去重。
// 未启用时两者均为 nil,IngestService 会整体跳过 embed(零开销),入库行为与启用前一致。
var (
visionClient *vision.Client
embedRepo repository.EmbeddingRepository
)
if cfg.Vision.Enabled {
visionClient = vision.New(
cfg.Vision.Endpoint,
cfg.Vision.Dim,
time.Duration(cfg.Vision.TimeoutSeconds)*time.Second,
cfg.Vision.FailThreshold,
)
embedRepo = repository.NewEmbeddingRepository(db)
slog.Info("视觉服务已启用",
"endpoint", cfg.Vision.Endpoint,
"dim", cfg.Vision.Dim,
"similar_threshold", cfg.Vision.SimilarThreshold)
} else {
slog.Info("视觉服务未启用(不产出语义向量,后台无「疑似同款」提示)")
}
// 爬虫入库服务:注入 mediaRepo(引用计数删孤儿)+ imgDel(S4/本地删除器)。
// 必须在 articleSvc / snapSvc 之前创建——图集服务删除时需调用它把「清理存储孤儿图」异步入队。
ingestSvc := service.NewIngestService(ingestRepo, brandRepo, mediaRepo, imgUp, imgDel, localUp, cfg.Ingest.DownloadProxy, translateSvc)
ingestSvc := service.NewIngestService(ingestRepo, brandRepo, mediaRepo, imgUp, imgDel, localUp, cfg.Ingest.DownloadProxy, translateSvc, visionClient, embedRepo)
// 图集服务:注入 ingestSvc 作为「清理孤儿图」的入队器,使下架/删除异步触发存储清理。
articleSvc = service.NewArticleService(articleRepo, mediaRepo, imgComposer, imgDel, ingestSvc)
snapSvc = service.NewStreetSnapService(snapRepo, mediaRepo, imgComposer, imgDel, ingestSvc)
@ -183,13 +205,21 @@ func main() {
Brand: handler.NewBrandHandler(brandSvc),
StreetSnap: handler.NewStreetSnapHandler(snapSvc, favSvc),
Auth: handler.NewAuthHandler(authSvc),
Favorite: handler.NewFavoriteHandler(favSvc),
History: handler.NewHistoryHandler(histSvc),
Health: handler.NewHealthHandler(),
Favorite: handler.NewFavoriteHandler(favSvc),
History: handler.NewHistoryHandler(histSvc),
Health: handler.NewHealthHandler(),
})
// 5.5 装配管理后台(Backstage)handler,供下方独立引擎使用。
backstageHandler := handler.NewBackstageHandler(authSvc, brandSvc, articleSvc, snapSvc, reviewSvc, ingestSvc, adminRepo, translateSvc)
// 「疑似同款」服务与视觉服务同开关:未启用时 embedRepo 为 nil,页面上不出现该角标。
similarSvc := service.NewSimilarService(embedRepo, cfg.Vision.SimilarThreshold)
// 把「疑似同款」服务注入入库流程:写完向量后顺手预计算近邻并落库,
// 后台页面因此只需读一次小查询(原先是页面内对每张图实时检索,一个 116 张图的图集要 5 秒)。
ingestSvc.SetSimilar(similarSvc)
backstageHandler := handler.NewBackstageHandler(authSvc, brandSvc, articleSvc, snapSvc, reviewSvc, ingestSvc, adminRepo, translateSvc, similarSvc)
// 手工建稿:复用入库仓储的写入方法(Create*WithImages,事务内完成)与同一套存储上传
// (imgUp = S4/本地主上传器,sha1 内容寻址),保证与爬虫入库产出的 key / 行结构一致。
backstageHandler.SetManual(service.NewManualArticleService(ingestRepo, brandRepo, imgUp, localUp, visionClient, embedRepo))
// 爬虫上报 handler(HMAC 验签入口)
ingestHandler := handler.NewIngestHandler(ingestSvc, brandSvc)