Upload src/lib/apiClient.ts with huggingface_hub
Browse files- src/lib/apiClient.ts +25 -0
src/lib/apiClient.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import axios from "axios";
|
| 2 |
+
|
| 3 |
+
export const apiClient = axios.create({
|
| 4 |
+
baseURL: "/api",
|
| 5 |
+
});
|
| 6 |
+
|
| 7 |
+
apiClient.interceptors.request.use((config) => {
|
| 8 |
+
// Read keys from localStorage to inject into request
|
| 9 |
+
const keysStr = localStorage.getItem("smartlead_api_keys");
|
| 10 |
+
const activeId = localStorage.getItem("smartlead_active_key_id");
|
| 11 |
+
|
| 12 |
+
if (keysStr && activeId) {
|
| 13 |
+
try {
|
| 14 |
+
const keys = JSON.parse(keysStr);
|
| 15 |
+
const activeKey = keys.find((k: any) => k.id === activeId)?.key;
|
| 16 |
+
if (activeKey) {
|
| 17 |
+
config.headers["x-api-key"] = activeKey;
|
| 18 |
+
}
|
| 19 |
+
} catch (e) {
|
| 20 |
+
console.error("Failed to parse API keys", e);
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
return config;
|
| 25 |
+
});
|