mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 14:19:56 +00:00
fix(dashboard): address code review feedback for PR #336
- Fix documentation: config.yaml -> settings.json in backups-section - Wrap restoreBackup in useCallback for callback stability - Auth middleware verified: inherited from app.use(authMiddleware)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Backups Section
|
* Backups Section
|
||||||
* Settings section for managing config.yaml backups (list and restore)
|
* Settings section for managing settings.json backups (list and restore)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect, useState, useCallback, useRef } from 'react';
|
import { useEffect, useState, useCallback, useRef } from 'react';
|
||||||
@@ -73,38 +73,41 @@ export default function BackupsSection() {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Restore backup
|
// Restore backup (wrapped in useCallback for callback stability)
|
||||||
const restoreBackup = async (timestamp: string) => {
|
const restoreBackup = useCallback(
|
||||||
// Abort previous restore request
|
async (timestamp: string) => {
|
||||||
restoreAbortControllerRef.current?.abort();
|
// Abort previous restore request
|
||||||
restoreAbortControllerRef.current = new AbortController();
|
restoreAbortControllerRef.current?.abort();
|
||||||
|
restoreAbortControllerRef.current = new AbortController();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setRestoring(timestamp);
|
setRestoring(timestamp);
|
||||||
setError(null);
|
setError(null);
|
||||||
const response = await fetch('/api/persist/restore', {
|
const response = await fetch('/api/persist/restore', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ timestamp }),
|
body: JSON.stringify({ timestamp }),
|
||||||
signal: restoreAbortControllerRef.current.signal,
|
signal: restoreAbortControllerRef.current.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
throw new Error(data.error || 'Failed to restore backup');
|
throw new Error(data.error || 'Failed to restore backup');
|
||||||
|
}
|
||||||
|
|
||||||
|
setSuccess('Backup restored successfully');
|
||||||
|
await fetchBackups();
|
||||||
|
await fetchRawConfig();
|
||||||
|
} catch (err) {
|
||||||
|
// Ignore abort errors
|
||||||
|
if (err instanceof Error && err.name === 'AbortError') return;
|
||||||
|
setError(err instanceof Error ? err.message : 'Unknown error');
|
||||||
|
} finally {
|
||||||
|
setRestoring(null);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
setSuccess('Backup restored successfully');
|
[fetchBackups, fetchRawConfig]
|
||||||
await fetchBackups();
|
);
|
||||||
await fetchRawConfig();
|
|
||||||
} catch (err) {
|
|
||||||
// Ignore abort errors
|
|
||||||
if (err instanceof Error && err.name === 'AbortError') return;
|
|
||||||
setError(err instanceof Error ? err.message : 'Unknown error');
|
|
||||||
} finally {
|
|
||||||
setRestoring(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load on mount
|
// Load on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -199,8 +202,8 @@ export default function BackupsSection() {
|
|||||||
<h2 className="text-lg font-semibold">Settings Backups</h2>
|
<h2 className="text-lg font-semibold">Settings Backups</h2>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
Restore previous versions of your config.yaml file. Backups are created automatically
|
Restore previous versions of your settings.json file. Backups are created
|
||||||
when settings are modified.
|
automatically when settings are modified.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user