fix(db): added access log and small addition to systemd service
This commit is contained in:
@@ -22,10 +22,19 @@ async function handler(
|
||||
// Сначала загружаем текущие настройки из базы данных
|
||||
clearSettingsCache()
|
||||
const currentSettings = loadSettings(true)
|
||||
|
||||
|
||||
// Обновление настроек
|
||||
const { weekNavigationEnabled, showAddGroupButton, showTeachersButton, vacationModeEnabled, vacationModeContent, debug } = req.body
|
||||
|
||||
console.log('[Settings API] Received settings update:', {
|
||||
weekNavigationEnabled,
|
||||
showAddGroupButton,
|
||||
showTeachersButton,
|
||||
vacationModeEnabled,
|
||||
vacationModeContent,
|
||||
hasDebug: debug !== undefined
|
||||
})
|
||||
|
||||
if (typeof weekNavigationEnabled !== 'boolean') {
|
||||
res.status(400).json({ error: 'weekNavigationEnabled must be a boolean' })
|
||||
return
|
||||
|
||||
@@ -419,6 +419,8 @@ export function getSettings(): AppSettings {
|
||||
|
||||
export function updateSettings(settings: AppSettings): void {
|
||||
const database = getDatabase()
|
||||
console.log('[Database] updateSettings called, DB path:', DB_PATH)
|
||||
|
||||
const defaultSettings: AppSettings = {
|
||||
weekNavigationEnabled: false,
|
||||
showAddGroupButton: true,
|
||||
@@ -441,9 +443,16 @@ export function updateSettings(settings: AppSettings): void {
|
||||
...settingsWithoutDebug
|
||||
}
|
||||
|
||||
database
|
||||
.prepare('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)')
|
||||
.run('app', JSON.stringify(mergedSettings))
|
||||
console.log('[Database] Saving merged settings:', mergedSettings)
|
||||
|
||||
try {
|
||||
const stmt = database.prepare('INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)')
|
||||
const result = stmt.run('app', JSON.stringify(mergedSettings))
|
||||
console.log('[Database] Settings save result:', result)
|
||||
} catch (error) {
|
||||
console.error('[Database] Error executing SQL:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Функции для работы с паролем ====================
|
||||
|
||||
@@ -62,12 +62,14 @@ export function loadSettings(forceRefresh: boolean = false): AppSettings {
|
||||
*/
|
||||
export function saveSettings(settings: AppSettings): void {
|
||||
try {
|
||||
console.log('[Settings] Saving settings to database:', settings)
|
||||
updateSettingsInDB(settings)
|
||||
console.log('[Settings] Settings saved successfully')
|
||||
// Сбрасываем кеш и timestamp
|
||||
cachedSettings = null
|
||||
cacheTimestamp = 0
|
||||
} catch (error) {
|
||||
console.error('Error saving settings to database:', error)
|
||||
console.error('[Settings] Error saving settings to database:', error)
|
||||
throw new Error('Failed to save settings')
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user