76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
const baseUrl = window.location.origin;
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.getElementById('baseUrl').textContent = baseUrl;
|
|
document.querySelectorAll('[id^="curlUrl"]').forEach(element => {
|
|
element.textContent = baseUrl;
|
|
});
|
|
});
|
|
|
|
function toggleEndpoint(id) {
|
|
const element = document.getElementById(id);
|
|
const bsCollapse = new bootstrap.Collapse(element, {
|
|
toggle: true
|
|
});
|
|
}
|
|
|
|
function tryEndpoint(endpoint, method = 'GET') {
|
|
const url = baseUrl + '/api/' + endpoint;
|
|
const responseId = 'response-' + endpoint.replace(/\//g, '-');
|
|
const responseDiv = document.getElementById(responseId);
|
|
const responseBody = document.getElementById(responseId + '-body');
|
|
|
|
responseDiv.style.display = 'block';
|
|
responseBody.textContent = 'Loading...';
|
|
|
|
const options = {
|
|
method: method,
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
};
|
|
|
|
fetch(url, options)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
responseBody.textContent = JSON.stringify(data, null, 2);
|
|
})
|
|
.catch(error => {
|
|
responseBody.textContent = 'Error: ' + error.message;
|
|
});
|
|
}
|
|
|
|
function tryInvalidateCountry() {
|
|
const countryInput = document.getElementById('invalidateCountry');
|
|
const country = countryInput.value.trim().toUpperCase();
|
|
|
|
if (!country || country.length !== 2) {
|
|
alert('Please enter a valid 2-letter country code (e.g., CN, RU, US)');
|
|
return;
|
|
}
|
|
|
|
const url = baseUrl + '/api/cache/invalidate/' + country;
|
|
const responseDiv = document.getElementById('response-cache-invalidate');
|
|
const responseBody = document.getElementById('response-cache-invalidate-body');
|
|
|
|
responseDiv.style.display = 'block';
|
|
responseBody.textContent = 'Loading...';
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
responseBody.textContent = JSON.stringify(data, null, 2);
|
|
if (data.success) {
|
|
countryInput.value = '';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
responseBody.textContent = 'Error: ' + error.message;
|
|
});
|
|
}
|