';
loadCleanupPage();
}
function loadCleanupPage(){
Promise.all([
api('/api/admin/cloud-configs').catch(function(){ return []; }),
api('/api/admin/verify/status').catch(function(){ return {}; }),
api('/api/admin/system-configs').catch(function(){ return {}; })
]).then(function(res){
var accounts = res[0] || [];
var vStatus = res[1] || {};
var configs = res[2] || {};
renderCleanupPage(accounts, vStatus, configs);
});
}
function renderCleanupPage(accounts, vStatus, configs){
var lastVerify = vStatus.last_run ? new Date(vStatus.last_run).toLocaleString() : 'never';
var lastCleanup = configs.cleanup_last_run || 'never';
var h = '';
h += '
Storage Cleanup & Management
';
h += '
Cloud verification, space refresh, scheduled cleanup
';
// Quick Actions
h += '
Quick Actions
';
h += '
';
h += '';
h += '';
h += '';
h += '';
h += '
';
h += '';
h += '
Last verify: ' + lastVerify + ' | Last cleanup: ' + lastCleanup + '
';
// Account Table
h += '
Account Verification
';
h += '
';
h += '
';
h += '
Type
Nickname
';
h += '
Status
Space
';
h += '
Action
';
accounts.forEach(function(cfg){
var v = cfg.verification_status;
var vIcon = v==='valid'?'OK':(v==='invalid'?'FAIL':'PENDING');
var space = cfg.storage_used ? (cfg.storage_used + ' / ' + (cfg.storage_total||'?')) : '-';
h += '
';
h += '
' + (cfg.cloud_type||'?') + '
';
h += '
' + (cfg.nickname||'-') + '
';
h += '
' + vIcon + '
';
h += '
' + space + '
';
h += '
';
});
if(accounts.length===0){
h += '
No accounts found
';
}
h += '
';
// Cleanup Config
h += '
Cleanup Config
';
h += '
';
h += cfgRow('Cleanup Enabled', 'cleanup_enabled', configs, 'checkbox');
h += cfgRow('File Retention (days)', 'cleanup_file_retention_days', configs, 'number', '7');
h += cfgRow('Log Retention (days)', 'cleanup_log_retention_days', configs, 'number', '30');
h += cfgRow('Empty Trash After', 'cleanup_empty_trash', configs, 'checkbox');
h += cfgRow('Space Threshold Cleanup', 'cleanup_space_threshold_enabled', configs, 'checkbox');
h += cfgRow('Threshold %', 'cleanup_space_threshold_percent', configs, 'number', '90');
h += cfgRow('Delete %', 'cleanup_space_threshold_delete_percent', configs, 'number', '10');
h += '
';
h += '
';
document.getElementById('cleanupRoot').innerHTML = h;
}
function cfgRow(label, key, configs, type, placeholder){
var val = configs[key] || '';
if(type==='checkbox'){
var chk = val==='true'?'checked':'';
return '';
}
return '';
}
function runVerifyAll(){
var el = document.getElementById('actionStatus');
el.innerHTML = 'Verifying all accounts...';
api('/api/admin/verify/run', {method:'POST'}).then(function(r){
el.innerHTML = 'Done: '+(r.ok||0)+'/'+r.total+' OK, '+r.failed+' failed';
setTimeout(loadCleanupPage, 2000);
}).catch(function(e){
el.innerHTML = 'Verify failed: '+(e.message||'network error');
});
}
function runSingleVerify(id, btn){
btn.disabled = true; btn.textContent = '...';
api('/api/admin/verify/single/'+id, {method:'POST'}).then(function(r){
btn.textContent = r.success ? 'OK' : 'FAIL';
}).catch(function(){ btn.textContent = 'ERR'; })
.finally(function(){ setTimeout(loadCleanupPage, 1500); });
}
function runStorageRefresh(){
var el = document.getElementById('actionStatus');
el.innerHTML = 'Refreshing space info...';
api('/api/admin/storage/refresh', {method:'POST'}).then(function(){
el.innerHTML = 'Space refreshed';
setTimeout(loadCleanupPage, 2000);
}).catch(function(e){
el.innerHTML = 'Refresh failed: '+(e.message||'network error');
});
}
function runFullCleanup(){
var el = document.getElementById('actionStatus');
el.innerHTML = 'Running full cleanup...';
api('/api/admin/cleanup/run', {method:'POST'}).then(function(r){
el.innerHTML = (r.message||'Cleanup done');
setTimeout(loadCleanupPage, 2000);
}).catch(function(e){
el.innerHTML = 'Cleanup failed: '+(e.message||'network error');
});
}
function runEmptyTrash(){
var el = document.getElementById('actionStatus');
if(!confirm('Empty all trash? This cannot be undone.')) return;
el.innerHTML = 'Emptying trash...';
api('/api/admin/cleanup/empty-trash', {method:'POST'}).then(function(r){
el.innerHTML = r.emptied ? 'Trash emptied' : (r.message||'Done');
}).catch(function(e){
el.innerHTML = 'Failed: '+(e.message||'network error');
});
}
function saveCleanupConfig(){
var entries = [];
document.querySelectorAll('.cleanupCfg').forEach(function(el){
var key = el.dataset.key;
var val = el.type==='checkbox' ? (el.checked?'true':'false') : el.value.trim();
entries.push({key:key, value:val});
});
api('/api/admin/system-configs', {
method:'PUT', headers:{'Content-Type':'application/json'},
body:JSON.stringify({entries:entries})
}).then(function(){
toast('Config saved');
}).catch(function(e){
toast('Save failed: '+(e.message||''));
});
}