Tạo scripts backup dữ liệu
This commit is contained in:
@@ -2026,6 +2026,58 @@ async function submitEditScene(e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Xử lý tải xuống bản sao lưu
|
||||
*/
|
||||
async function handleBackup() {
|
||||
const token = localStorage.getItem('jwt');
|
||||
try {
|
||||
showNotification("Đang chuẩn bị bản sao lưu...", "success");
|
||||
const response = await fetch(`${API_BASE_URL}/admin/backup`, {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
if (!response.ok) throw new Error("Lỗi khi tạo backup");
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `backup_3dtour_${new Date().toISOString().slice(0,10)}.zip`;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
showNotification("Đã tải xuống bản sao lưu!", "success");
|
||||
} catch (e) { showNotification(e.message, "error"); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Xử lý khôi phục dữ liệu từ file zip
|
||||
*/
|
||||
async function handleRestore(input) {
|
||||
if (!input.files || !input.files[0]) return;
|
||||
if (!confirm("CẢNH BÁO: Khôi phục dữ liệu sẽ xóa sạch dữ liệu hiện tại và thay thế bằng dữ liệu từ bản sao lưu. Bạn có chắc chắn?")) {
|
||||
input.value = ''; return;
|
||||
}
|
||||
const token = localStorage.getItem('jwt');
|
||||
const formData = new FormData();
|
||||
formData.append('backupFile', input.files[0]);
|
||||
try {
|
||||
showNotification("Đang khôi phục... Vui lòng không đóng trình duyệt.", "success");
|
||||
const response = await fetch(`${API_BASE_URL}/admin/restore`, {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': `Bearer ${token}` },
|
||||
body: formData
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.message);
|
||||
showNotification("Khôi phục thành công! Hệ thống sẽ tải lại.", "success");
|
||||
setTimeout(() => location.reload(), 2000);
|
||||
} catch (e) {
|
||||
showNotification(e.message, "error");
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a specific tab within the dashboard.
|
||||
* @param {string} tabName - The ID of the tab pane to open (e.g., 'profile', 'my-scenes').
|
||||
|
||||
Reference in New Issue
Block a user