Cập nhật tính năng quản lí dữ liệu mồ côi

This commit is contained in:
2026-06-09 15:32:06 +07:00
parent 7f32eb816c
commit 13e1c6049d
3 changed files with 254 additions and 1 deletions
+106 -1
View File
@@ -1666,11 +1666,87 @@ window.deleteUserByAdmin = async function(userId) {
});
const data = await res.json();
if (!res.ok) throw new Error(data.message);
showNotification(data.message, 'success');
// Hiển thị thông báo thành công kèm báo cáo dọn dẹp nếu có
let successMsg = data.message;
if (data.report) {
successMsg += `\n(Đã dọn dẹp: ${data.report.scenesDeleted} Scenes, ${data.report.filesRemoved} Files)`;
}
showNotification(successMsg, 'success');
loadAdminUsers();
} catch (e) { showNotification(e.message, 'error'); }
};
/**
* Giai đoạn 2 & 3: Các hàm xử lý bảo trì cho Admin tối cao
*/
window.openManualCleanupConfirm = function() {
const modal = document.getElementById('maintenance-confirm-modal');
document.getElementById('maintenance-confirm-title').innerText = "Dọn dẹp hệ thống";
document.getElementById('maintenance-confirm-desc').innerText = "Hệ thống sẽ quét và xóa bỏ tất cả các Scene, Hotspot và Asset không còn liên kết hợp lệ. Thao tác này không thể hoàn tác.";
document.getElementById('maintenance-action-type').value = 'cleanup';
document.getElementById('maintenance-confirm-btn').onclick = runManualCleanup;
modal.style.display = 'flex';
};
window.closeMaintenanceConfirm = () => {
document.getElementById('maintenance-confirm-modal').style.display = 'none';
};
async function runManualCleanup() {
const token = localStorage.getItem('jwt');
closeMaintenanceConfirm();
try {
const res = await fetch(`${API_BASE_URL}/admin/maintenance/cleanup`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
if (!res.ok) throw new Error(data.message);
const report = data.report;
showSuccessModal(`Dọn dẹp hoàn tất!\n- Scenes xóa: ${report.scenesDeleted}\n- Files xóa: ${report.filesRemoved}`);
} catch (e) { showNotification(e.message, 'error'); }
}
window.checkStrayFiles = async function() {
const token = localStorage.getItem('jwt');
try {
const res = await fetch(`${API_BASE_URL}/admin/maintenance/stray-files`, {
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
if (!res.ok) throw new Error(data.message);
if (data.count === 0) {
showSuccessModal("Tuyệt vời! Không tìm thấy tệp tin rác nào trong hệ thống.", '✨');
} else {
const modal = document.getElementById('maintenance-confirm-modal');
document.getElementById('maintenance-confirm-title').innerText = "Phát hiện tệp tin rác";
document.getElementById('maintenance-confirm-desc').innerText = `Tìm thấy ${data.count} file trong thư mục uploads không có bản ghi trong Database. Bạn có muốn xóa chúng để tiết kiệm dung lượng?`;
document.getElementById('maintenance-action-type').value = 'stray';
document.getElementById('maintenance-confirm-btn').onclick = deleteStrayFiles;
modal.style.display = 'flex';
}
} catch (e) { showNotification(e.message, 'error'); }
};
async function deleteStrayFiles() {
const token = localStorage.getItem('jwt');
closeMaintenanceConfirm();
try {
const res = await fetch(`${API_BASE_URL}/admin/maintenance/cleanup?deleteStray=true`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` }
});
const data = await res.json();
if (!res.ok) throw new Error(data.message);
showSuccessModal(`Đã dọn dẹp sạch sẽ ${data.report.filesRemoved} tệp tin rác khỏi máy chủ.`);
loadMediaStats(); // Cập nhật lại dung lượng hiển thị
} catch (e) { showNotification(e.message, 'error'); }
}
/**
* Tải và hiển thị kho ảnh/media của người dùng
*/
@@ -2171,6 +2247,35 @@ async function handleRestore(input) {
}
}
/**
* Cập nhật cấu hình hệ thống
*/
async function updateSystemSettings(e) {
e.preventDefault();
const token = localStorage.getItem('jwt');
const timezone = document.getElementById('sys-timezone').value;
const language = document.getElementById('sys-language').value;
try {
const res = await fetch(`${API_BASE_URL}/system/settings`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ timezone, language })
});
if (res.ok) {
showNotification("Cấu hình hệ thống đã được lưu!", "success");
// Tải lại cài đặt để áp dụng ngôn ngữ mới ngay lập tức
fetchSystemSettings();
}
} catch (err) {
showNotification("Lỗi lưu cấu hình: " + err.message, "error");
}
}
/**
* Opens a specific tab within the dashboard.
* @param {string} tabName - The ID of the tab pane to open (e.g., 'profile', 'my-scenes').