Commit
·
7458b22
1
Parent(s):
1a0ede6
fixed API Key import
Browse files
app/components/settings/data/DataTab.tsx
CHANGED
@@ -174,27 +174,41 @@ export default function DataTab() {
|
|
174 |
try {
|
175 |
const apiKeys = JSON.parse(e.target?.result as string);
|
176 |
let importedCount = 0;
|
|
|
177 |
|
178 |
API_KEY_PROVIDERS.forEach(provider => {
|
179 |
const keyName = `${provider}_API_KEY`;
|
180 |
if (apiKeys[keyName]) {
|
181 |
-
|
182 |
importedCount++;
|
183 |
}
|
184 |
});
|
185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
['OPENAI_LIKE_API_BASE_URL', 'LMSTUDIO_API_BASE_URL', 'OLLAMA_API_BASE_URL', 'TOGETHER_API_BASE_URL'].forEach(baseUrl => {
|
187 |
if (apiKeys[baseUrl]) {
|
188 |
Cookies.set(baseUrl, apiKeys[baseUrl]);
|
189 |
-
importedCount++;
|
190 |
}
|
191 |
});
|
192 |
|
193 |
-
if (importedCount > 0) {
|
194 |
-
toast.success(`Successfully imported ${importedCount} API keys/URLs`);
|
195 |
-
} else {
|
196 |
-
toast.warn('No valid API keys found in the file');
|
197 |
-
}
|
198 |
} catch (error) {
|
199 |
toast.error('Failed to import API keys. Make sure the file is a valid JSON file.');
|
200 |
console.error('Failed to import API keys:', error);
|
|
|
174 |
try {
|
175 |
const apiKeys = JSON.parse(e.target?.result as string);
|
176 |
let importedCount = 0;
|
177 |
+
const consolidatedKeys: Record<string, string> = {};
|
178 |
|
179 |
API_KEY_PROVIDERS.forEach(provider => {
|
180 |
const keyName = `${provider}_API_KEY`;
|
181 |
if (apiKeys[keyName]) {
|
182 |
+
consolidatedKeys[provider] = apiKeys[keyName];
|
183 |
importedCount++;
|
184 |
}
|
185 |
});
|
186 |
|
187 |
+
if (importedCount > 0) {
|
188 |
+
// Store all API keys in a single cookie as JSON
|
189 |
+
Cookies.set('apiKeys', JSON.stringify(consolidatedKeys));
|
190 |
+
|
191 |
+
// Also set individual cookies for backward compatibility
|
192 |
+
Object.entries(consolidatedKeys).forEach(([provider, key]) => {
|
193 |
+
Cookies.set(`${provider}_API_KEY`, key);
|
194 |
+
});
|
195 |
+
|
196 |
+
toast.success(`Successfully imported ${importedCount} API keys/URLs. Refreshing page to apply changes...`);
|
197 |
+
// Reload the page after a short delay to allow the toast to be seen
|
198 |
+
setTimeout(() => {
|
199 |
+
window.location.reload();
|
200 |
+
}, 1500);
|
201 |
+
} else {
|
202 |
+
toast.warn('No valid API keys found in the file');
|
203 |
+
}
|
204 |
+
|
205 |
+
// Set base URLs if they exist
|
206 |
['OPENAI_LIKE_API_BASE_URL', 'LMSTUDIO_API_BASE_URL', 'OLLAMA_API_BASE_URL', 'TOGETHER_API_BASE_URL'].forEach(baseUrl => {
|
207 |
if (apiKeys[baseUrl]) {
|
208 |
Cookies.set(baseUrl, apiKeys[baseUrl]);
|
|
|
209 |
}
|
210 |
});
|
211 |
|
|
|
|
|
|
|
|
|
|
|
212 |
} catch (error) {
|
213 |
toast.error('Failed to import API keys. Make sure the file is a valid JSON file.');
|
214 |
console.error('Failed to import API keys:', error);
|