Fix media classification scraping and Chinese naming

This commit is contained in:
ShukeBta
2026-07-15 20:45:24 +08:00
parent 923198ccea
commit 19381eb270
33 changed files with 1150 additions and 67 deletions
+18 -1
View File
@@ -23,6 +23,24 @@ func scanLibraryHandler(svc *service.Container) gin.HandlerFunc {
return
}
if _, ok := service.ParseCloudLibraryMount(lib.Path); ok {
status, started, startErr := svc.Scan.StartCloudLibraryScan(id, true)
if startErr != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": startErr.Error()})
return
}
if !started {
c.JSON(http.StatusAccepted, gin.H{
"library_id": id,
"queued": true,
"cloud": true,
"already_running": true,
"stage": status.Stage,
"state": status.State,
"message": "该云盘媒体库正在后台扫描,请在任务面板查看进度",
"estimate_message": "页面关闭不会中断扫描",
})
return
}
task := startScanHTTPTask(svc, "云盘扫描队列", lib.Name, lib.Path)
if svc.WSHub != nil {
svc.WSHub.Publish("scan", gin.H{
@@ -34,7 +52,6 @@ func scanLibraryHandler(svc *service.Container) gin.HandlerFunc {
"estimate_message": "小目录通常几十秒;几万文件的大目录可能需要数分钟到数小时,取决于网盘接口速度",
})
}
_, _, _ = svc.Scan.StartCloudLibraryScan(id, true)
finishHTTPTask(task, nil, "queued", "云盘扫描已加入后台队列", map[string]int64{"queued": 1}, nil)
c.JSON(http.StatusAccepted, gin.H{
"library_id": id,
+35
View File
@@ -293,6 +293,41 @@ func TestListLibrarySeriesDoesNotTruncateLargeEpisodeLibraries(t *testing.T) {
}
}
func TestScanLibraryHandlerSurfacesCloudQueueStartFailure(t *testing.T) {
gin.SetMode(gin.TestMode)
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
if err != nil {
t.Fatal(err)
}
if err := db.AutoMigrate(&model.Library{}, &model.LibraryRoot{}, &model.Media{}, &model.Setting{}); err != nil {
t.Fatal(err)
}
repos := repository.New(db)
lib := model.Library{Name: "旧夸克云盘", Path: service.BuildCloudLibraryPath(service.LegacyQuarkProvider, "archive", "archive"), Type: "movie", Enabled: true}
if err := repos.Library.Create(t.Context(), &lib); err != nil {
t.Fatal(err)
}
log := zap.NewNop()
svc := &service.Container{
Log: log,
Repo: repos,
Scan: service.NewScannerService(&config.Config{}, log, repos, service.NewHub(log), nil, nil),
}
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: lib.ID}}
c.Request = httptest.NewRequest(http.MethodPost, "/api/libraries/"+lib.ID+"/scan", nil)
scanLibraryHandler(svc)(c)
if w.Code != http.StatusBadRequest {
t.Fatalf("status=%d body=%s, want bad request", w.Code, w.Body.String())
}
if !strings.Contains(w.Body.String(), "deprecated") {
t.Fatalf("body=%s, want cloud queue start error", w.Body.String())
}
}
func TestScrapeOptionsFromRequestPreservesEpisodeImagesFalse(t *testing.T) {
gin.SetMode(gin.TestMode)
w := httptest.NewRecorder()