fix(flashcards): добавлен /api/ префикс в 12 вызовах LS.api
LS.api = apiFetch — принимает полный путь без автодобавления /api/. Все 12 вызовов исправлены: /flashcards/... → /api/flashcards/... Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+12
-12
@@ -407,8 +407,8 @@ async function init() {
|
|||||||
|
|
||||||
async function loadDecks() {
|
async function loadDecks() {
|
||||||
const [decks, stats] = await Promise.all([
|
const [decks, stats] = await Promise.all([
|
||||||
LS.api('/flashcards/decks').catch(()=>({decks:[]})),
|
LS.api('/api/flashcards/decks').catch(()=>({decks:[]})),
|
||||||
LS.api('/flashcards/stats').catch(()=>null),
|
LS.api('/api/flashcards/stats').catch(()=>null),
|
||||||
]);
|
]);
|
||||||
_decks = decks.decks || [];
|
_decks = decks.decks || [];
|
||||||
renderStats(stats);
|
renderStats(stats);
|
||||||
@@ -483,7 +483,7 @@ async function openDeck(id) {
|
|||||||
_curDeck = _decks.find(d => d.id === id);
|
_curDeck = _decks.find(d => d.id === id);
|
||||||
if (!_curDeck) return;
|
if (!_curDeck) return;
|
||||||
document.getElementById('cards-deck-title').textContent = _curDeck.title;
|
document.getElementById('cards-deck-title').textContent = _curDeck.title;
|
||||||
const data = await LS.api(`/flashcards/decks/${id}/cards`).catch(()=>({cards:[]}));
|
const data = await LS.api(`/api/flashcards/decks/${id}/cards`).catch(()=>({cards:[]}));
|
||||||
_cards = data.cards || [];
|
_cards = data.cards || [];
|
||||||
renderCardList();
|
renderCardList();
|
||||||
document.getElementById('view-decks').style.display = 'none';
|
document.getElementById('view-decks').style.display = 'none';
|
||||||
@@ -547,7 +547,7 @@ async function addCard() {
|
|||||||
const front = document.getElementById('new-card-front').value.trim();
|
const front = document.getElementById('new-card-front').value.trim();
|
||||||
const back = document.getElementById('new-card-back').value.trim();
|
const back = document.getElementById('new-card-back').value.trim();
|
||||||
if (!front && !back) return;
|
if (!front && !back) return;
|
||||||
const card = await LS.api(`/flashcards/decks/${_curDeck.id}/cards`, {
|
const card = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards`, {
|
||||||
method: 'POST', body: JSON.stringify({ front, back })
|
method: 'POST', body: JSON.stringify({ front, back })
|
||||||
}).catch(()=>null);
|
}).catch(()=>null);
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
@@ -566,14 +566,14 @@ async function saveCard(id, field, value) {
|
|||||||
const card = _cards.find(c => c.id === id);
|
const card = _cards.find(c => c.id === id);
|
||||||
if (!card) return;
|
if (!card) return;
|
||||||
card[field] = value;
|
card[field] = value;
|
||||||
await LS.api(`/flashcards/cards/${id}`, {
|
await LS.api(`/api/flashcards/cards/${id}`, {
|
||||||
method: 'PUT', body: JSON.stringify({ [field]: value })
|
method: 'PUT', body: JSON.stringify({ [field]: value })
|
||||||
}).catch(()=>{});
|
}).catch(()=>{});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteCard(id) {
|
async function deleteCard(id) {
|
||||||
if (!confirm('Удалить карточку?')) return;
|
if (!confirm('Удалить карточку?')) return;
|
||||||
await LS.api(`/flashcards/cards/${id}`, { method: 'DELETE' }).catch(()=>{});
|
await LS.api(`/api/flashcards/cards/${id}`, { method: 'DELETE' }).catch(()=>{});
|
||||||
_cards = _cards.filter(c => c.id !== id);
|
_cards = _cards.filter(c => c.id !== id);
|
||||||
renderCardList();
|
renderCardList();
|
||||||
}
|
}
|
||||||
@@ -594,7 +594,7 @@ async function saveBulk() {
|
|||||||
return { front: (front||'').trim(), back: rest.join(sep).trim() };
|
return { front: (front||'').trim(), back: rest.join(sep).trim() };
|
||||||
}).filter(c => c.front);
|
}).filter(c => c.front);
|
||||||
if (!cards.length) return;
|
if (!cards.length) return;
|
||||||
const result = await LS.api(`/flashcards/decks/${_curDeck.id}/cards/bulk`, {
|
const result = await LS.api(`/api/flashcards/decks/${_curDeck.id}/cards/bulk`, {
|
||||||
method: 'POST', body: JSON.stringify({ cards })
|
method: 'POST', body: JSON.stringify({ cards })
|
||||||
}).catch(()=>null);
|
}).catch(()=>null);
|
||||||
if (result?.inserted) {
|
if (result?.inserted) {
|
||||||
@@ -618,7 +618,7 @@ async function startStudy() {
|
|||||||
async function startStudyForDeck(deckId) {
|
async function startStudyForDeck(deckId) {
|
||||||
_curDeck = _curDeck || _decks.find(d => d.id === deckId);
|
_curDeck = _curDeck || _decks.find(d => d.id === deckId);
|
||||||
if (!_curDeck) return;
|
if (!_curDeck) return;
|
||||||
const data = await LS.api(`/flashcards/decks/${deckId}/study`).catch(()=>null);
|
const data = await LS.api(`/api/flashcards/decks/${deckId}/study`).catch(()=>null);
|
||||||
if (!data || !data.cards?.length) {
|
if (!data || !data.cards?.length) {
|
||||||
LS.toast('Нет карточек для повторения — всё актуально!', 'success');
|
LS.toast('Нет карточек для повторения — всё актуально!', 'success');
|
||||||
return;
|
return;
|
||||||
@@ -693,7 +693,7 @@ async function answer(quality) {
|
|||||||
else if (quality === 4) _sessionStats.good++;
|
else if (quality === 4) _sessionStats.good++;
|
||||||
else if (quality === 5) _sessionStats.easy++;
|
else if (quality === 5) _sessionStats.easy++;
|
||||||
// send review
|
// send review
|
||||||
await LS.api(`/flashcards/cards/${card.id}/review`, {
|
await LS.api(`/api/flashcards/cards/${card.id}/review`, {
|
||||||
method: 'POST', body: JSON.stringify({ quality })
|
method: 'POST', body: JSON.stringify({ quality })
|
||||||
}).catch(()=>{});
|
}).catch(()=>{});
|
||||||
// animate swipe
|
// animate swipe
|
||||||
@@ -826,7 +826,7 @@ async function saveDeckModal() {
|
|||||||
const desc = document.getElementById('modal-deck-desc').value.trim();
|
const desc = document.getElementById('modal-deck-desc').value.trim();
|
||||||
if (!title) { document.getElementById('modal-deck-name').focus(); return; }
|
if (!title) { document.getElementById('modal-deck-name').focus(); return; }
|
||||||
if (_editingDeckId) {
|
if (_editingDeckId) {
|
||||||
await LS.api(`/flashcards/decks/${_editingDeckId}`, {
|
await LS.api(`/api/flashcards/decks/${_editingDeckId}`, {
|
||||||
method: 'PUT', body: JSON.stringify({ title, description: desc, color: _deckColor })
|
method: 'PUT', body: JSON.stringify({ title, description: desc, color: _deckColor })
|
||||||
}).catch(()=>{});
|
}).catch(()=>{});
|
||||||
_curDeck.title = title; _curDeck.description = desc; _curDeck.color = _deckColor;
|
_curDeck.title = title; _curDeck.description = desc; _curDeck.color = _deckColor;
|
||||||
@@ -834,7 +834,7 @@ async function saveDeckModal() {
|
|||||||
const d = _decks.find(x => x.id === _editingDeckId);
|
const d = _decks.find(x => x.id === _editingDeckId);
|
||||||
if (d) { d.title = title; d.description = desc; d.color = _deckColor; }
|
if (d) { d.title = title; d.description = desc; d.color = _deckColor; }
|
||||||
} else {
|
} else {
|
||||||
const deck = await LS.api('/flashcards/decks', {
|
const deck = await LS.api('/api/flashcards/decks', {
|
||||||
method: 'POST', body: JSON.stringify({ title, description: desc, color: _deckColor })
|
method: 'POST', body: JSON.stringify({ title, description: desc, color: _deckColor })
|
||||||
}).catch(()=>null);
|
}).catch(()=>null);
|
||||||
if (deck) { _decks.unshift(deck); renderDecks(); }
|
if (deck) { _decks.unshift(deck); renderDecks(); }
|
||||||
@@ -845,7 +845,7 @@ async function saveDeckModal() {
|
|||||||
async function confirmDeleteDeck() {
|
async function confirmDeleteDeck() {
|
||||||
if (!_curDeck) return;
|
if (!_curDeck) return;
|
||||||
if (!await LS.confirm(`Удалить колоду «${_curDeck.title}» и все карточки?`, { title: 'Удаление колоды', confirmText: 'Удалить', danger: true })) return;
|
if (!await LS.confirm(`Удалить колоду «${_curDeck.title}» и все карточки?`, { title: 'Удаление колоды', confirmText: 'Удалить', danger: true })) return;
|
||||||
await LS.api(`/flashcards/decks/${_curDeck.id}`, { method: 'DELETE' }).catch(()=>{});
|
await LS.api(`/api/flashcards/decks/${_curDeck.id}`, { method: 'DELETE' }).catch(()=>{});
|
||||||
_decks = _decks.filter(d => d.id !== _curDeck.id);
|
_decks = _decks.filter(d => d.id !== _curDeck.id);
|
||||||
_curDeck = null; _cards = [];
|
_curDeck = null; _cards = [];
|
||||||
showDecks();
|
showDecks();
|
||||||
|
|||||||
Reference in New Issue
Block a user