refactor: audit, split server.go, add unit tests, and fix latent bugs

- Remove dead code: browser cdp/content_scrape strategies, writer package,
  printUsage, downloadAndStoreCoverCLI in main.go
- Fix bugs: defer-in-loop in pocketbase deleteWhere, listAll() pagination
  hard cap removed, splitChapterTitle off-by-one in date extraction
- Split server.go (~1700 lines) into focused handler files:
  handlers_audio, handlers_browse, handlers_progress, handlers_ranking,
  handlers_scrape
- Export htmlutil.AttrVal/TextContent/ResolveURL; add storage/coverutil.go
  to consolidate duplicate helpers
- Flatten deeply nested conditionals: voices() early-return guards,
  ScrapeCatalogue next-link double attr scan, chapterNumberFromKey dead
  strings.Cut line, splitChapterTitle double-nested unit/suffix loop
- Add unit tests: htmlutil (9 funcs), novelfire ScrapeMetadata (3 cases),
  orchestrator Run (5 cases), storage chapterNumberFromKey/splitChapterTitle
  (22 cases); all pass with go build/vet/test clean
This commit is contained in:
Admin
2026-03-04 22:14:23 +05:00
parent 7b48707cd9
commit fb6b364382
26 changed files with 2359 additions and 2392 deletions

View File

@@ -335,6 +335,9 @@ func TestServer_PresignChapter_NotFound(t *testing.T) {
// MinIO presign on a non-existent key returns an error; server returns 500.
// (Some MinIO versions return a valid presigned URL anyway, which is also acceptable.)
t.Logf("presign non-existent chapter status: %d", resp.StatusCode)
if resp.StatusCode != http.StatusInternalServerError && resp.StatusCode != http.StatusOK {
t.Errorf("status = %d, want 500 or 200", resp.StatusCode)
}
}
// TestServer_ChapterText writes a chapter and verifies
@@ -395,13 +398,6 @@ func mapKeys(m map[string]interface{}) []string {
return keys
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// cookieJar is a minimal http.CookieJar that stores cookies by host.
type cookieJar struct {
cookies map[string][]*http.Cookie