mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
fix: clamp review star value to 0-5 range to prevent repeat() RangeError
WeRead API returns star=100 for book reviews and star=-1 for thoughts, causing '☆'.repeat(5-100) to throw 'Invalid count value: -95'.
This commit is contained in:
1 parent
ae40ed93d6
commit
4d8cc2a2d7
1 file changed
+2
-1
+2
-1
@@ -813,7 +813,8 @@ function openNotes(bookId, title, author, cover) {
|
||||
if (data.review_count > 0) {
|
||||
html += `<div class="notes-section-title">💭 想法/点评 (${data.review_count})</div>`;
|
||||
data.reviews.forEach((r) => {
|
||||
const stars = r.star > 0 ? `<span class="review-star">${"★".repeat(r.star)}${"☆".repeat(5 - r.star)}</span>` : "";
|
||||
const starVal = Math.max(0, Math.min(5, parseInt(r.star) || 0));
|
||||
const stars = starVal > 0 ? `<span class="review-star">${"★".repeat(starVal)}${"☆".repeat(5 - starVal)}</span>` : "";
|
||||
html += `
|
||||
<div class="review-item">
|
||||
${escapeHtml(r.content)}
|
||||
|
||||
Reference in new issue
Block a user