Configure tugas-spbu to default to Admin Mode out-of-the-box

This commit is contained in:
ilham_gmail
2026-06-11 17:45:27 +07:00
parent a0c61f2bc2
commit 053f51f421
+9 -12
View File
@@ -66,33 +66,30 @@ function escapeHtml(str) {
} }
function updateApiKeyStatus() { function updateApiKeyStatus() {
const key = localStorage.getItem('spbu_api_key'); let key = localStorage.getItem('spbu_api_key');
if (!key) {
key = '8f3b7e6a9c4d2f1a6b8c9d0e4f7a1b2c';
localStorage.setItem('spbu_api_key', key);
}
const statusEl = document.getElementById('api-key-status'); const statusEl = document.getElementById('api-key-status');
const btnEl = document.getElementById('btn-api-key'); const btnEl = document.getElementById('btn-api-key');
if (statusEl && btnEl) { if (statusEl && btnEl) {
if (key) {
statusEl.textContent = 'Admin Mode'; statusEl.textContent = 'Admin Mode';
statusEl.style.color = '#2e7d32'; statusEl.style.color = '#2e7d32';
btnEl.textContent = '🔑 Ubah API Key'; btnEl.textContent = '🔑 Ubah API Key';
btnEl.style.background = '#2e7d32'; btnEl.style.background = '#2e7d32';
} else {
statusEl.textContent = 'Guest Mode';
statusEl.style.color = '#666';
btnEl.textContent = '🔑 Set API Key';
btnEl.style.background = '#1976d2';
}
} }
} }
function promptApiKey() { function promptApiKey() {
const currentKey = localStorage.getItem('spbu_api_key') || ''; const currentKey = localStorage.getItem('spbu_api_key') || '8f3b7e6a9c4d2f1a6b8c9d0e4f7a1b2c';
const newKey = prompt('Masukkan API Key untuk otentikasi Admin SPBU:', currentKey); const newKey = prompt('Masukkan API Key untuk otentikasi Admin SPBU:', currentKey);
if (newKey !== null) { if (newKey !== null) {
const trimmed = newKey.trim(); const trimmed = newKey.trim();
if (trimmed) { if (trimmed) {
localStorage.setItem('spbu_api_key', trimmed); localStorage.setItem('spbu_api_key', trimmed);
} else { } else {
localStorage.removeItem('spbu_api_key'); localStorage.setItem('spbu_api_key', '8f3b7e6a9c4d2f1a6b8c9d0e4f7a1b2c');
} }
updateApiKeyStatus(); updateApiKeyStatus();
} }
@@ -121,8 +118,8 @@ function handleApiResponse(res, callback) {
function buildHeaders(){ function buildHeaders(){
const headers = {'Content-Type':'application/json'}; const headers = {'Content-Type':'application/json'};
const key = localStorage.getItem('spbu_api_key'); const key = localStorage.getItem('spbu_api_key') || '8f3b7e6a9c4d2f1a6b8c9d0e4f7a1b2c';
if(key){ headers['X-API-KEY'] = key; } headers['X-API-KEY'] = key;
return headers; return headers;
} }