update commit message
This commit is contained in:
+25
-5
@@ -168,6 +168,12 @@
|
||||
.trim();
|
||||
}
|
||||
|
||||
function hasAdminCapability(auth) {
|
||||
const roles = Array.isArray(auth?.roles) ? auth.roles.map((value) => String(value || "").trim()) : [];
|
||||
const scopes = Array.isArray(auth?.scopes) ? auth.scopes.map((value) => String(value || "").trim()) : [];
|
||||
return roles.includes("admin") || scopes.includes("api:admin");
|
||||
}
|
||||
|
||||
function isApiEnabled() {
|
||||
return Boolean(getApiBaseUrl());
|
||||
}
|
||||
@@ -614,7 +620,7 @@
|
||||
}
|
||||
|
||||
const health = await healthResponse.json().catch(() => null);
|
||||
const protectedResponse = await fetch(buildApiUrl("/api/v1/decks/options", {}, resolvedConnection), requestOptions);
|
||||
const protectedResponse = await fetch(buildApiUrl("/api/v1/astrology/planets", {}, resolvedConnection), requestOptions);
|
||||
|
||||
if (protectedResponse.status === 401 || protectedResponse.status === 403) {
|
||||
return {
|
||||
@@ -630,18 +636,32 @@
|
||||
return {
|
||||
ok: false,
|
||||
reason: "protected-route-failed",
|
||||
message: `The API responded with ${protectedResponse.status} when loading protected data.`
|
||||
message: `The API responded with ${protectedResponse.status} when loading connected data.`
|
||||
};
|
||||
}
|
||||
|
||||
const decksPayload = await protectedResponse.json().catch(() => null);
|
||||
let tarotAvailable = false;
|
||||
let deckCount = null;
|
||||
const tarotResponse = await fetch(buildApiUrl("/api/v1/decks/options", {}, resolvedConnection), requestOptions);
|
||||
if (tarotResponse.ok) {
|
||||
const decksPayload = await tarotResponse.json().catch(() => null);
|
||||
deckCount = Array.isArray(decksPayload?.decks) ? decksPayload.decks.length : null;
|
||||
tarotAvailable = true;
|
||||
} else if (tarotResponse.status !== 401 && tarotResponse.status !== 403) {
|
||||
deckCount = null;
|
||||
}
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
reason: "connected",
|
||||
message: "Connected.",
|
||||
message: tarotAvailable ? "Connected." : "Connected. Tarot features are unavailable for this API key.",
|
||||
health,
|
||||
auth: health?.auth || null,
|
||||
deckCount: Array.isArray(decksPayload?.decks) ? decksPayload.decks.length : null
|
||||
deckCount,
|
||||
capabilities: {
|
||||
tarot: tarotAvailable,
|
||||
adminApiManagement: hasAdminCapability(health?.auth)
|
||||
}
|
||||
};
|
||||
} catch (_error) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user