feat(auth): implement basic authentication for cache server and update URL

This commit is contained in:
Ross
2026-07-16 23:16:46 +01:00
parent db4f5f1745
commit fd2766d0a9
2 changed files with 1032 additions and 9 deletions
+1009 -6
View File
File diff suppressed because it is too large Load Diff
+23 -3
View File
@@ -16,7 +16,21 @@
// CHANGE THIS URL to the IP address or hostname of your central cache server if running on remote machines // CHANGE THIS URL to the IP address or hostname of your central cache server if running on remote machines
// e.g., "http://192.168.1.50:8000" // e.g., "http://192.168.1.50:8000"
const CACHE_SERVER_URL = "http://localhost:8000"; const CACHE_SERVER_URL = "https://stat.xkjq.uk";
// Credentials for central cache server basic authentication
const CACHE_AUTH_USER = "admin";
const CACHE_AUTH_PASS = "statdx-secure-cache-2026";
// Helper: Generate Basic Auth header
function getAuthHeader() {
try {
const credentials = btoa(`${CACHE_AUTH_USER}:${CACHE_AUTH_PASS}`);
return `Basic ${credentials}`;
} catch (e) {
return "";
}
}
const capturedUrls = new Set(); const capturedUrls = new Set();
@@ -156,7 +170,10 @@
GM_xmlhttpRequest({ GM_xmlhttpRequest({
method: "POST", method: "POST",
url: `${CACHE_SERVER_URL}/api/check-hash`, url: `${CACHE_SERVER_URL}/api/check-hash`,
headers: { "Content-Type": "application/json" }, headers: {
"Content-Type": "application/json",
"Authorization": getAuthHeader()
},
data: JSON.stringify({ content_hash: contentHash }), data: JSON.stringify({ content_hash: contentHash }),
onload: function(res) { onload: function(res) {
if (res.status === 200) { if (res.status === 200) {
@@ -187,7 +204,10 @@
GM_xmlhttpRequest({ GM_xmlhttpRequest({
method: "POST", method: "POST",
url: `${CACHE_SERVER_URL}/api/capture`, url: `${CACHE_SERVER_URL}/api/capture`,
headers: { "Content-Type": "application/json" }, headers: {
"Content-Type": "application/json",
"Authorization": getAuthHeader()
},
data: JSON.stringify(payload), data: JSON.stringify(payload),
onload: function(res) { onload: function(res) {
if (res.status === 200) { if (res.status === 200) {