Enhance API key handling in settings and vocab services: Update key retrieval logic to improve validation and status reporting. Introduce new localization strings for key status messages in English, German, and Spanish. Update LanguageAssistantView to display key status dynamically, enhancing user feedback on API key management.

This commit is contained in:
Torsten Schulz (local)
2026-03-25 17:46:18 +01:00
parent 6d166e8bcc
commit 6cfd4eb8d9
6 changed files with 44 additions and 9 deletions

View File

@@ -428,14 +428,16 @@ class SettingsService extends BaseService{
}
}
const hasKey = Boolean(keyRow && keyRow.value && String(keyRow.value).trim());
const hasStoredKey = Boolean(keyRow && keyRow.getDataValue('value') && String(keyRow.getDataValue('value')).trim());
const hasReadableKey = Boolean(keyRow && keyRow.value && String(keyRow.value).trim());
return {
enabled: parsed.enabled !== false,
baseUrl: parsed.baseUrl || '',
model: parsed.model || 'gpt-4o-mini',
hasKey,
keyLast4: parsed.keyLast4 || null
hasKey: hasStoredKey,
keyLast4: parsed.keyLast4 || null,
keyStatus: hasStoredKey ? (hasReadableKey ? 'stored' : 'invalid') : 'missing'
};
}

View File

@@ -12,7 +12,6 @@ import UserParam from '../models/community/user_param.js';
import { sequelize } from '../utils/sequelize.js';
import { notifyUser } from '../utils/socket.js';
import { Op } from 'sequelize';
import { decrypt } from '../utils/encryption.js';
export default class VocabService {
async _getUserByHashedId(hashedUserId) {
@@ -56,7 +55,7 @@ export default class VocabService {
}
}
const decryptedKey = keyRow?.value ? decrypt(keyRow.value) : null;
const decryptedKey = keyRow?.value ? String(keyRow.value).trim() : null;
const hasKey = Boolean(decryptedKey && String(decryptedKey).trim());
const enabled = parsed.enabled !== false;
const baseUrl = String(parsed.baseUrl || '').trim();