v1.0.0-alpha4: Add Redis/Valkey caching and search with principal agent auth for global settings

This commit is contained in:
2026-01-01 23:58:00 +00:00
parent f98ff8fcec
commit 71e5070e6c
10 changed files with 1012 additions and 6 deletions
+31 -1
View File
@@ -223,10 +223,30 @@
syncColumnOrderNumbers();
console.log('Saving columns with orders:', currentSettings.columns.map(c => ({ name: c.name, order: c.order, visible: c.visible })).slice(0, 5));
const jsonString = JSON.stringify(currentSettings);
await pb.collection('app_preferences_settings').update(settingsRecordId, {
// Authenticate as principal agent for settings updates
const agentAuth = await fetch('/api/admin/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: await getEnvVar('PB_AGENT_EMAIL'),
password: await getEnvVar('PB_AGENT_PASSWORD')
})
}).then(r => r.json());
if (!agentAuth.ok || !agentAuth.token) {
throw new Error('Failed to authenticate as principal agent');
}
// Use agent token to update settings
const tempPb = new PocketBase('https://pocketbase.ccllc.pro');
tempPb.authStore.save(agentAuth.token, null);
await tempPb.collection('app_preferences_settings').update(settingsRecordId, {
app_json_prefs: jsonString,
app_txt_prefs: `Updated on ${new Date().toISOString()}`
});
console.log('Settings saved to PocketBase successfully');
if (!isAuto) {
alert('Settings saved successfully!');
@@ -238,6 +258,16 @@
}
}
}
// Helper to get env vars from server
async function getEnvVar(key) {
// Since we can't access env directly from browser, we'll need server endpoint
// For now, hardcode getting them via backend
const response = await fetch('/api/admin/env?key=' + key);
if (!response.ok) throw new Error('Failed to get env var');
const data = await response.json();
return data.value;
}
function queueAutosave() {
if (autosaveTimer) {