mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-05 21:06:38 +08:00
refactor: split modules and harden scraping workflows
This commit is contained in:
@@ -17,14 +17,22 @@ import (
|
||||
// 异步执行, 立即返回 202;通过 WS hub "scrape" topic 推送进度。
|
||||
func repairAndRescrapeAllHandler(svc *service.Container) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
options, err := scrapeOptionsFromRequest(c, true)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid scrape options"})
|
||||
return
|
||||
}
|
||||
task := startScrapeHTTPTask(svc, "全库修复并重刮", "", "")
|
||||
go func() {
|
||||
result, err := svc.RepairAndRescrapeAllLibraries(context.Background())
|
||||
go func(options service.ScrapeOptions) {
|
||||
result, err := svc.RepairAndRescrapeAllLibraries(context.Background(), options)
|
||||
metrics := map[string]int64{
|
||||
"repaired": int64(result.Repaired),
|
||||
"libraries": int64(result.Libraries),
|
||||
"matched": int64(result.Matched),
|
||||
"reset": int64(result.Reset),
|
||||
"repaired": int64(result.Repaired),
|
||||
"reclassified": int64(result.Reclassified),
|
||||
"libraries": int64(result.Libraries),
|
||||
"matched": int64(result.Matched),
|
||||
"processed": int64(result.Processed),
|
||||
"errors": int64(result.Errors),
|
||||
"reset": int64(result.Reset),
|
||||
}
|
||||
stage := "completed"
|
||||
message := "全库修复并重刮完成"
|
||||
@@ -33,7 +41,7 @@ func repairAndRescrapeAllHandler(svc *service.Container) gin.HandlerFunc {
|
||||
message = "全库修复并重刮失败"
|
||||
}
|
||||
finishHTTPTask(task, err, stage, message, metrics, nil)
|
||||
}()
|
||||
}(options)
|
||||
c.JSON(http.StatusAccepted, gin.H{"status": "started"})
|
||||
}
|
||||
}
|
||||
@@ -46,14 +54,22 @@ func repairAndRescrapeAllHandler(svc *service.Container) gin.HandlerFunc {
|
||||
func repairAndRescrapeLibraryHandler(svc *service.Container) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
libraryID := c.Param("id")
|
||||
options, err := scrapeOptionsFromRequest(c, true)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid scrape options"})
|
||||
return
|
||||
}
|
||||
task := startScrapeHTTPTask(svc, "媒体库修复并重刮", "", "")
|
||||
go func() {
|
||||
result, err := svc.RepairAndRescrapeLibrary(context.Background(), libraryID)
|
||||
go func(options service.ScrapeOptions) {
|
||||
result, err := svc.RepairAndRescrapeLibrary(context.Background(), libraryID, options)
|
||||
metrics := map[string]int64{
|
||||
"repaired": int64(result.Repaired),
|
||||
"libraries": int64(result.Libraries),
|
||||
"matched": int64(result.Matched),
|
||||
"reset": int64(result.Reset),
|
||||
"repaired": int64(result.Repaired),
|
||||
"reclassified": int64(result.Reclassified),
|
||||
"libraries": int64(result.Libraries),
|
||||
"matched": int64(result.Matched),
|
||||
"processed": int64(result.Processed),
|
||||
"errors": int64(result.Errors),
|
||||
"reset": int64(result.Reset),
|
||||
}
|
||||
stage := "completed"
|
||||
message := "媒体库修复并重刮完成"
|
||||
@@ -62,7 +78,7 @@ func repairAndRescrapeLibraryHandler(svc *service.Container) gin.HandlerFunc {
|
||||
message = "媒体库修复并重刮失败"
|
||||
}
|
||||
finishHTTPTask(task, err, stage, message, metrics, nil)
|
||||
}()
|
||||
}(options)
|
||||
c.JSON(http.StatusAccepted, gin.H{"status": "started"})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user