add more details to sharp + hopefully let me know if it's broken for people on linux.
This commit is contained in:
@@ -4,12 +4,14 @@ import { digestData } from "./utils.js";
|
|||||||
const POLL_INTERVAL_MS = 5000;
|
const POLL_INTERVAL_MS = 5000;
|
||||||
const FALLBACK_POLL_MS = 30000;
|
const FALLBACK_POLL_MS = 30000;
|
||||||
const PREF_REFRESH_KEY = "overlord_refresh_interval_seconds";
|
const PREF_REFRESH_KEY = "overlord_refresh_interval_seconds";
|
||||||
|
const THUMBNAIL_COOLDOWN_MS = 60000;
|
||||||
let pollTimer = null;
|
let pollTimer = null;
|
||||||
let render = () => {};
|
let render = () => {};
|
||||||
let dashboardWs = null;
|
let dashboardWs = null;
|
||||||
let dashboardWsConnected = false;
|
let dashboardWsConnected = false;
|
||||||
let wsReconnectTimer = null;
|
let wsReconnectTimer = null;
|
||||||
const manuallyDisconnecting = new Set();
|
const manuallyDisconnecting = new Set();
|
||||||
|
const thumbnailRequestedAt = new Map();
|
||||||
|
|
||||||
function moveClientCardImmediately(msg) {
|
function moveClientCardImmediately(msg) {
|
||||||
const clientId = typeof msg?.clientId === "string" ? msg.clientId : "";
|
const clientId = typeof msg?.clientId === "string" ? msg.clientId : "";
|
||||||
@@ -74,10 +76,7 @@ export async function loadWithOptions(options = {}) {
|
|||||||
const pag = document.getElementById("pagination");
|
const pag = document.getElementById("pagination");
|
||||||
if (pag) pag.style.visibility = "";
|
if (pag) pag.style.visibility = "";
|
||||||
|
|
||||||
if (!state.thumbnailsRequested) {
|
requestThumbnailsForClients(data.items);
|
||||||
state.thumbnailsRequested = true;
|
|
||||||
requestThumbnailsForClients(data.items);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("load clients", err);
|
console.error("load clients", err);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -93,8 +92,14 @@ export async function loadWithOptions(options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function requestThumbnailsForClients(items) {
|
async function requestThumbnailsForClients(items) {
|
||||||
const onlineClientsWithoutThumbnail = items.filter(c => c.online && !c.thumbnail);
|
const now = Date.now();
|
||||||
|
const onlineClientsWithoutThumbnail = items.filter(c => {
|
||||||
|
if (!c.online || c.thumbnail) return false;
|
||||||
|
const last = thumbnailRequestedAt.get(c.id);
|
||||||
|
return !last || now - last > THUMBNAIL_COOLDOWN_MS;
|
||||||
|
});
|
||||||
for (const client of onlineClientsWithoutThumbnail) {
|
for (const client of onlineClientsWithoutThumbnail) {
|
||||||
|
thumbnailRequestedAt.set(client.id, now);
|
||||||
await requestThumbnail(client.id);
|
await requestThumbnail(client.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,6 +181,7 @@ function connectDashboardWs() {
|
|||||||
console.warn("[dashboard] ws closed");
|
console.warn("[dashboard] ws closed");
|
||||||
dashboardWs = null;
|
dashboardWs = null;
|
||||||
dashboardWsConnected = false;
|
dashboardWsConnected = false;
|
||||||
|
thumbnailRequestedAt.clear();
|
||||||
adjustPollingForWs();
|
adjustPollingForWs();
|
||||||
scheduleDashboardReconnect();
|
scheduleDashboardReconnect();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,5 +11,4 @@ export const state = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
pendingForce: false,
|
pendingForce: false,
|
||||||
pendingReorder: false,
|
pendingReorder: false,
|
||||||
thumbnailsRequested: false,
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
let _sharp: typeof import("sharp") extends { default: infer D } ? D : never;
|
let _sharp: (typeof import("sharp") extends { default: infer D } ? D : never) | null = null;
|
||||||
async function getSharp() {
|
let _sharpLoadAttempted = false;
|
||||||
if (!_sharp) {
|
|
||||||
_sharp = (await import("sharp")).default;
|
async function getSharp(): Promise<typeof import("sharp") extends { default: infer D } ? D : never> {
|
||||||
|
if (_sharp) return _sharp;
|
||||||
|
if (_sharpLoadAttempted) throw new Error("sharp module unavailable");
|
||||||
|
_sharpLoadAttempted = true;
|
||||||
|
try {
|
||||||
|
_sharp = (await import("sharp")).default as any;
|
||||||
|
return _sharp!;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("[thumbnails] Failed to load sharp module. Thumbnails will be unavailable.", err);
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
return _sharp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const THUMBNAIL_WIDTH = Math.max(64, Number(process.env.OVERLORD_THUMBNAIL_WIDTH || 640));
|
const THUMBNAIL_WIDTH = Math.max(64, Number(process.env.OVERLORD_THUMBNAIL_WIDTH || 640));
|
||||||
@@ -80,7 +88,8 @@ export async function generateThumbnail(id: string): Promise<boolean> {
|
|||||||
thumbnails.set(id, dataUrl);
|
thumbnails.set(id, dataUrl);
|
||||||
latestFrames.delete(id);
|
latestFrames.delete(id);
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error(`[thumbnails] Failed to generate thumbnail for client ${id}:`, err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user