v1.0.6: fetch timeouts and project pagination
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const CURRENT_VERSION = "1.0.5";
|
||||
const CURRENT_VERSION = "1.0.6";
|
||||
const GITEA_BASE = "http://100.120.125.113:3000/pdm/stream_deck_notion_timer/raw/branch/master";
|
||||
const SIGNING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
||||
MCowBQYDK2VwAyEAN7ko8TUpuPzPAJuKAZCRjV0c4ZSlou5d9pUAF6o12b4=
|
||||
@@ -13,17 +13,23 @@ function isNewerVersion(remote: string, current: string): boolean {
|
||||
return rPat > cPat;
|
||||
}
|
||||
|
||||
function fetchWithTimeout(url: string): Promise<Response> {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), 10_000);
|
||||
return fetch(url, { signal: controller.signal }).finally(() => clearTimeout(timer));
|
||||
}
|
||||
|
||||
async function checkForUpdates(): Promise<void> {
|
||||
try {
|
||||
const resp = await fetch(`${GITEA_BASE}/version.json`);
|
||||
const resp = await fetchWithTimeout(`${GITEA_BASE}/version.json`);
|
||||
if (!resp.ok) return;
|
||||
const { version } = await resp.json() as { version: string };
|
||||
if (!/^\d+\.\d+\.\d+$/.test(version)) return;
|
||||
if (!isNewerVersion(version, CURRENT_VERSION)) return;
|
||||
|
||||
const [pluginResp, sigResp] = await Promise.all([
|
||||
fetch(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`),
|
||||
fetch(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`),
|
||||
fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js`),
|
||||
fetchWithTimeout(`${GITEA_BASE}/com.pdma.notion-timer.sdPlugin/bin/plugin.js.sig`),
|
||||
]);
|
||||
if (!pluginResp.ok || !sigResp.ok) return;
|
||||
|
||||
@@ -113,11 +119,14 @@ class TimerToggle extends SingletonAction<TimerSettings> {
|
||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: "Configure Notion credentials in plugin settings first.", version: CURRENT_VERSION });
|
||||
return;
|
||||
}
|
||||
const [projects, users] = await Promise.all([
|
||||
const [projects, usersResult] = await Promise.all([
|
||||
fetchProjects(global.notionToken, global.projectsDbId),
|
||||
fetchUsers(global.notionToken),
|
||||
fetchUsers(global.notionToken).catch((err) => {
|
||||
streamDeck.logger.error("Failed to fetch users:", err);
|
||||
return [];
|
||||
}),
|
||||
]);
|
||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users, version: CURRENT_VERSION });
|
||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: projects, users: usersResult, version: CURRENT_VERSION });
|
||||
} catch (err) {
|
||||
streamDeck.logger.error("Failed to fetch projects:", err);
|
||||
await streamDeck.ui.sendToPropertyInspector({ event: "projects", data: [], error: String(err), version: CURRENT_VERSION });
|
||||
|
||||
Reference in New Issue
Block a user