Added multi-key support
This commit is contained in:
@@ -15,6 +15,8 @@ const DEFAULT_TASKS = [
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
apiKey: "",
|
||||
apiKeys: [],
|
||||
activeApiKeyId: "",
|
||||
apiBaseUrl: "https://api.openai.com/v1",
|
||||
apiKeyHeader: "Authorization",
|
||||
apiKeyPrefix: "Bearer ",
|
||||
@@ -80,6 +82,17 @@ chrome.runtime.onInstalled.addListener(async () => {
|
||||
if (missing) updates[key] = value;
|
||||
}
|
||||
|
||||
const hasApiKeys =
|
||||
Array.isArray(stored.apiKeys) && stored.apiKeys.length > 0;
|
||||
|
||||
if (!hasApiKeys && stored.apiKey) {
|
||||
const id = crypto?.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: `key-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`;
|
||||
updates.apiKeys = [{ id, name: "Default", key: stored.apiKey }];
|
||||
updates.activeApiKeyId = id;
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length) {
|
||||
await chrome.storage.local.set(updates);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user