create: admin.html, admin.js, help.html, index.html, info.html, info.js, k.html, k.js, login.html, main.js, style.css, xlsx.full.min.js, auth.js, package.json, server.js, sqllite.js

This commit is contained in:
Калугин Олег Александрович
2026-04-13 12:30:38 +00:00
committed by GitVerse
parent 2d007d2359
commit fe3824b9da
7 changed files with 80 additions and 9 deletions

View File

@@ -242,12 +242,10 @@ function parseLessonFromJsonRecord(record) {
let fields = {};
if (Array.isArray(record)) {
// Массив пар [["key","value"], ...]
for (const [key, value] of record) {
fields[key.trim()] = (value || '').toString().trim();
}
} else if (typeof record === 'object' && record !== null) {
// Обычный объект
fields = { ...record };
Object.keys(fields).forEach(k => {
fields[k.trim()] = (fields[k] || '').toString().trim();
@@ -282,7 +280,7 @@ app.post('/api/admin/import/preview', isAuthenticated, isAdmin, async (req, res)
try {
lesson = parseLessonFromJsonRecord(record);
} catch(e) {
continue; // пропускаем битые записи
continue;
}
if (lesson.teacher && lesson.subject && !isNaN(lesson.parallel)) {
preview.push(lesson);
@@ -336,6 +334,17 @@ app.post('/api/admin/import', isAuthenticated, isAdmin, async (req, res) => {
}
});
// --------------------- НОВЫЙ ЭНДПОИНТ: полная очистка базы ---------------------
app.post('/api/admin/clear-db', isAuthenticated, isAdmin, async (req, res) => {
try {
await db.clearAllData();
res.json({ success: true, message: 'База данных очищена' });
} catch (err) {
console.error('Ошибка очистки БД:', err);
res.status(500).json({ error: 'Не удалось очистить базу данных' });
}
});
// --------------------- Статические страницы ---------------------
app.get('/admin', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'admin.html'));