updated the API to support the new calendar service and added a smoke test for the API.
This commit is contained in:
+18
-11
@@ -1,7 +1,6 @@
|
||||
(function () {
|
||||
const apiBaseUrlStorageKey = "tarot-time-api-base-url";
|
||||
const apiKeyStorageKey = "tarot-time-api-key";
|
||||
const defaultApiBaseUrl = "";
|
||||
|
||||
function normalizeBaseUrl(value) {
|
||||
return String(value || "")
|
||||
@@ -20,22 +19,33 @@
|
||||
};
|
||||
}
|
||||
|
||||
function stripLegacyCredentialParams() {
|
||||
try {
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const hadApiKeyParam = currentUrl.searchParams.has("apiKey") || currentUrl.searchParams.has("api_key");
|
||||
if (!hadApiKeyParam) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentUrl.searchParams.delete("apiKey");
|
||||
currentUrl.searchParams.delete("api_key");
|
||||
const nextUrl = `${currentUrl.pathname}${currentUrl.search}${currentUrl.hash}`;
|
||||
window.history.replaceState(window.history.state, "", nextUrl);
|
||||
} catch (_error) {
|
||||
}
|
||||
}
|
||||
|
||||
function persistConnectionSettings(settings) {
|
||||
let didPersist = true;
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search || "");
|
||||
const queryValue = String(params.get("apiBaseUrl") || "").trim();
|
||||
const queryApiKey = String(params.get("apiKey") || params.get("api_key") || "").trim();
|
||||
|
||||
if (queryValue) {
|
||||
window.localStorage.setItem(apiBaseUrlStorageKey, normalizeBaseUrl(queryValue));
|
||||
}
|
||||
|
||||
if (queryApiKey) {
|
||||
window.localStorage.setItem(apiKeyStorageKey, normalizeApiKey(queryApiKey));
|
||||
}
|
||||
|
||||
if (settings.apiBaseUrl) {
|
||||
window.localStorage.setItem(apiBaseUrlStorageKey, settings.apiBaseUrl);
|
||||
} else {
|
||||
@@ -58,16 +68,11 @@
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search || "");
|
||||
const queryValue = String(params.get("apiBaseUrl") || "").trim();
|
||||
const queryApiKey = String(params.get("apiKey") || params.get("api_key") || "").trim();
|
||||
|
||||
if (queryValue) {
|
||||
window.localStorage.setItem(apiBaseUrlStorageKey, normalizeBaseUrl(queryValue));
|
||||
}
|
||||
|
||||
if (queryApiKey) {
|
||||
window.localStorage.setItem(apiKeyStorageKey, normalizeApiKey(queryApiKey));
|
||||
}
|
||||
|
||||
const storedBaseUrl = String(window.localStorage.getItem(apiBaseUrlStorageKey) || "").trim();
|
||||
const storedApiKey = String(window.localStorage.getItem(apiKeyStorageKey) || "").trim();
|
||||
return normalizeConnectionSettings({
|
||||
@@ -82,6 +87,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
stripLegacyCredentialParams();
|
||||
|
||||
const initialConnectionSettings = readConfiguredConnectionSettings();
|
||||
|
||||
window.TarotAppConfig = {
|
||||
|
||||
+1
-12
@@ -192,11 +192,6 @@
|
||||
url.searchParams.set(key, normalizedValue);
|
||||
});
|
||||
|
||||
const apiKey = getApiKey();
|
||||
if (apiKey && !url.searchParams.has("api_key")) {
|
||||
url.searchParams.set("api_key", apiKey);
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
@@ -211,13 +206,7 @@
|
||||
return "";
|
||||
}
|
||||
|
||||
const url = new URL(`/api/v1/assets/${encodePathSegments(normalizedAssetPath)}`, `${apiBaseUrl}/`);
|
||||
const apiKey = getApiKey();
|
||||
if (apiKey) {
|
||||
url.searchParams.set("api_key", apiKey);
|
||||
}
|
||||
|
||||
return url.toString();
|
||||
return new URL(`/api/v1/assets/${encodePathSegments(normalizedAssetPath)}`, `${apiBaseUrl}/`).toString();
|
||||
}
|
||||
|
||||
function resetCaches() {
|
||||
|
||||
Reference in New Issue
Block a user