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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user