fix: daily vani

This commit is contained in:
Krispire Admin
2026-07-11 01:13:34 +05:30
parent 3de7e5faec
commit 47b3a6d96e
+10 -9
View File
@@ -88,19 +88,20 @@ func (r *VaniRepo) Insert(ctx context.Context, pick *model.VaniPick) error {
}
// BookTitle resolves a book code to its display title (from book_meta.data.title),
// or "" if unknown. Used to label a prose pick with its book name.
// or "" if unknown. Used to label a prose pick with its book name. Decoding into
// a typed struct avoids the bson.M-nested-doc pitfall (nested documents decode
// as bson.D, so a `raw["data"].(bson.M)` assertion would silently fail).
func (r *VaniRepo) BookTitle(ctx context.Context, book string) string {
var raw bson.M
var doc struct {
Data struct {
Title string `bson:"title"`
} `bson:"data"`
}
if err := r.mongo.Collection("book_meta").
FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&raw); err != nil {
FindOne(ctx, bson.D{{Key: "book", Value: book}}).Decode(&doc); err != nil {
return ""
}
if data, ok := raw["data"].(bson.M); ok {
if t, ok := data["title"].(string); ok {
return t
}
}
return ""
return doc.Data.Title
}
// --- Mongo: random candidate sampling ---