Skip to content

Commit 76ec384

Browse files
committed
feat: enhance scheduled backup logging, implement session expiration handling, and update demo cron schedule.
1 parent 7ce564d commit 76ec384

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

demo/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"extensions": [
1010
".json"
1111
],
12-
"cronSchedule": "5 * * * *",
12+
"cronSchedule": "*/10 * * * *",
1313
"cronEnabled": true,
1414
"auth": {
1515
"username": "admin",

src/core/scheduler.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,29 @@ export const createScheduler = onBackup => {
3131
backupJob = new CronJob(
3232
cronSchedule,
3333
async () => {
34-
console.log('Running scheduled backup...')
35-
try {
36-
// Generate timestamp for the backup
37-
const now = new Date()
38-
const timestamp =
39-
now.getFullYear() +
40-
'-' +
41-
String(now.getMonth() + 1).padStart(2, '0') +
42-
'-' +
43-
String(now.getDate()).padStart(2, '0') +
44-
'_' +
45-
String(now.getHours()).padStart(2, '0') +
46-
'-' +
47-
String(now.getMinutes()).padStart(2, '0') +
48-
'-' +
49-
String(now.getSeconds()).padStart(2, '0')
34+
// Generate timestamp for the backup
35+
const now = new Date()
36+
const timestamp =
37+
now.getFullYear() +
38+
'-' +
39+
String(now.getMonth() + 1).padStart(2, '0') +
40+
'-' +
41+
String(now.getDate()).padStart(2, '0') +
42+
'_' +
43+
String(now.getHours()).padStart(2, '0') +
44+
'-' +
45+
String(now.getMinutes()).padStart(2, '0') +
46+
'-' +
47+
String(now.getSeconds()).padStart(2, '0')
48+
49+
const timeStr = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`
50+
console.log(`📦 Running scheduled backup at ${timeStr}`)
5051

52+
try {
5153
await onBackup(timestamp)
52-
console.log('Scheduled backup completed')
54+
console.log(`✅ Scheduled backup completed at ${timeStr}`)
5355
} catch (e) {
54-
console.error('Scheduled backup failed:', e)
56+
console.error(`❌ Scheduled backup failed at ${timeStr}:`, e)
5557
}
5658
},
5759
null,

src/views/scripts/backupApp.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ export const backupAppScript = ({ config, jobStatus }) => `
285285
headers: { 'Content-Type': 'application/json' },
286286
body: JSON.stringify({ key })
287287
})
288+
289+
// Handle session expiration
290+
if (res.status === 401) {
291+
this.addLog('Session expired. Redirecting to login...', 'error')
292+
setTimeout(() => window.location.href = '/backup/login', 1500)
293+
return
294+
}
295+
288296
const data = await res.json()
289297
if (data.status === 'success') {
290298
this.addLog(data.message, 'success')
@@ -303,6 +311,14 @@ export const backupAppScript = ({ config, jobStatus }) => `
303311
headers: { 'Content-Type': 'application/json' },
304312
body: JSON.stringify({ key })
305313
})
314+
315+
// Handle session expiration
316+
if (res.status === 401) {
317+
this.addLog('Session expired. Redirecting to login...', 'error')
318+
setTimeout(() => window.location.href = '/backup/login', 1500)
319+
return
320+
}
321+
306322
const data = await res.json()
307323
if (data.status === 'success') {
308324
this.addLog(data.message, 'success')
@@ -322,12 +338,22 @@ export const backupAppScript = ({ config, jobStatus }) => `
322338
headers: { 'Content-Type': 'application/json' },
323339
body: JSON.stringify(this.configForm)
324340
})
341+
342+
// Handle session expiration
343+
if (res.status === 401) {
344+
this.addLog('Session expired. Redirecting to login...', 'error')
345+
setTimeout(() => window.location.href = '/backup/login', 1500)
346+
return
347+
}
348+
325349
const data = await res.json()
326350
if (data.status === 'success') {
327351
this.config = data.config
328352
if (data.jobStatus) this.cronStatus = data.jobStatus
329353
this.addLog('Configuration updated', 'success')
330354
this.activeTab = 'dashboard'
355+
} else {
356+
throw new Error(data.message || 'Failed to save config')
331357
}
332358
} catch (err) {
333359
this.addLog('Failed to save config: ' + err.message, 'error')

0 commit comments

Comments
 (0)