Implement HTTPS redirection for certificate trust issues in LuxsinAPI and update image paths in Home component to use BASE_URL for consistency.

This commit is contained in:
yangy
2026-04-21 16:10:12 +08:00
parent 060258ea2d
commit 24278c263f
2 changed files with 26 additions and 7 deletions
+21 -4
View File
@@ -188,11 +188,28 @@ export class LuxsinAPI {
this.baseUrl = `${protocol}://${host}`;
}
private maybeRedirectForHttpsCert(error: unknown) {
// On HTTPS pages, first-time device access may fail before user trusts the cert.
if (typeof window === "undefined") return;
if (window.location.protocol !== "https:") return;
if (!(error instanceof Error)) return;
// fetch network failure is typically reported as TypeError/Failed to fetch.
const msg = (error.message || "").toLowerCase();
if (error.name === "TypeError" || msg.includes("failed to fetch") || msg.includes("networkerror")) {
window.location.href = this.baseUrl;
}
}
async getDeviceState(): Promise<DeviceState> {
const response = await fetch(`${this.baseUrl}/dev/info.cgi?action=syncData`);
const text = await response.text();
const decoded = decodeCustomBase64(text.trim());
return JSON.parse(decoded) as DeviceState;
try {
const response = await fetch(`${this.baseUrl}/dev/info.cgi?action=syncData`);
const text = await response.text();
const decoded = decodeCustomBase64(text.trim());
return JSON.parse(decoded) as DeviceState;
} catch (error) {
this.maybeRedirectForHttpsCert(error);
throw error;
}
}
async getMsgCount(): Promise<number> {