feat(storage): add getApiKey/setApiKey/clearApiKey/getApiModel/setApiModel for OpenRouter integration

This commit is contained in:
Kenearos 2026-05-12 00:13:20 +02:00
parent e58a2488bb
commit f7e8ccb5b6
2 changed files with 124 additions and 0 deletions

View file

@ -6,6 +6,9 @@ class DataStorage {
constructor() {
this.STORAGE_KEY_EMPLOYEES = 'dienstplan_employees';
this.STORAGE_KEY_DUTIES = 'dienstplan_duties';
this.STORAGE_KEY_OPENROUTER_KEY = 'dienstplan_openrouter_key';
this.STORAGE_KEY_OPENROUTER_MODEL = 'dienstplan_openrouter_model';
this.DEFAULT_MODEL = 'anthropic/claude-sonnet-4.6';
}
/**
@ -307,6 +310,67 @@ class DataStorage {
return false;
}
}
// ============================================================
// API Key / Model (Feature A: Bild-Import)
// Device-local config — NOT included in exportData/clearAll.
// ============================================================
/**
* @returns {string|null}
*/
getApiKey() {
try {
return localStorage.getItem(this.STORAGE_KEY_OPENROUTER_KEY) || null;
} catch (e) {
console.error('Fehler beim Laden des API-Keys:', e);
return null;
}
}
/**
* @param {string} key
*/
setApiKey(key) {
try {
localStorage.setItem(this.STORAGE_KEY_OPENROUTER_KEY, String(key));
} catch (e) {
console.error('Fehler beim Speichern des API-Keys:', e);
throw e;
}
}
clearApiKey() {
try {
localStorage.removeItem(this.STORAGE_KEY_OPENROUTER_KEY);
} catch (e) {
console.error('Fehler beim Loeschen des API-Keys:', e);
}
}
/**
* @returns {string}
*/
getApiModel() {
try {
return localStorage.getItem(this.STORAGE_KEY_OPENROUTER_MODEL) || this.DEFAULT_MODEL;
} catch (e) {
console.error('Fehler beim Laden des Modells:', e);
return this.DEFAULT_MODEL;
}
}
/**
* @param {string} modelId
*/
setApiModel(modelId) {
try {
localStorage.setItem(this.STORAGE_KEY_OPENROUTER_MODEL, String(modelId));
} catch (e) {
console.error('Fehler beim Speichern des Modells:', e);
throw e;
}
}
}
// Make it available globally