fix(api): lazy cover self-heal + tmp-file skip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -47,6 +48,29 @@ func TestCoverCBZAndPlaceholder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 不经 scanner 直接入库(模拟缓存丢失/卷漂移)→ GET cover 就地抽图自愈并落盘(tmp+rename)
|
||||
func TestCoverSelfHeal(t *testing.T) {
|
||||
st, _, h, booksDir := setupAPI(t)
|
||||
atok := adminToken(t, h)
|
||||
lib, root := newLibrary(t, st, h, atok, booksDir, "comics")
|
||||
p := filepath.Join(root, "heal.cbz")
|
||||
writeCBZ(t, p, 2)
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id, err := st.InsertBook(context.Background(), lib.ID, "heal.cbz", "heal", "cbz", fi.Size(), fi.ModTime().Unix(), 2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 1; i <= 2; i++ { // 第二次走已缓存目录,均应 200 image/*
|
||||
w := do(h, "GET", "/api/books/"+itoa(id)+"/cover", atok, nil)
|
||||
if w.Code != 200 || !strings.Contains(w.Header().Get("Content-Type"), "image/") {
|
||||
t.Fatalf("self-heal cover pass %d: %d %q", i, w.Code, w.Header().Get("Content-Type"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPages(t *testing.T) {
|
||||
h, cbzID, txtID := serveFixture(t)
|
||||
tok := adminToken(t, h)
|
||||
|
||||
Reference in New Issue
Block a user