Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/getPluginsJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let cachedData: ExtendedPlugin[] = [];

export async function getPluginsJson() {
if (!cachedData?.length) {
const data: FlowPlugin[] = await fetch("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json").then(v => v.json());
const data: FlowPlugin[] = await fetch("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json").then(v => v.json());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Harden the manifest fetch (ok-check, timeout, and safe fallback).

If main/plugins.json isn’t live yet or GitHub responds non-200/transiently, .json() will throw and break the build. Add res.ok handling, a short timeout, and a fallback to the previous manifest path.

-    const data: FlowPlugin[] = await fetch("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json").then(v => v.json());
+    const urls = [
+      // Allow override via env during migration or local testing
+      (import.meta as any)?.env?.PLUGINS_MANIFEST_URL
+        ?? process.env.PLUGINS_MANIFEST_URL
+        ?? "https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json",
+      // Fallback to old location (remove once migration is fully done)
+      "https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json",
+    ].filter(Boolean) as string[];
+
+    const controller = new AbortController();
+    const timeout = setTimeout(() => controller.abort(), 10_000);
+    let data: FlowPlugin[] | undefined;
+    for (const url of urls) {
+      try {
+        const res = await fetch(url, {
+          signal: controller.signal,
+          headers: { accept: "application/json" },
+        });
+        if (!res.ok) continue;
+        data = await res.json();
+        break;
+      } catch {
+        // try next URL
+      }
+    }
+    clearTimeout(timeout);
+    if (!data) {
+      throw new Error("Failed to fetch plugins manifest from any known URL.");
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const data: FlowPlugin[] = await fetch("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json").then(v => v.json());
// Hardened manifest fetch: support env override, timeout, ok-check, and fallback URL
const urls = [
// Allow override via env during migration or local testing
(import.meta as any)?.env?.PLUGINS_MANIFEST_URL
?? process.env.PLUGINS_MANIFEST_URL
?? "https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json",
// Fallback to old location (remove once migration is fully done)
"https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/plugin_api_v2/plugins.json",
].filter(Boolean) as string[];
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 10_000);
let data: FlowPlugin[] | undefined;
for (const url of urls) {
try {
const res = await fetch(url, {
signal: controller.signal,
headers: { accept: "application/json" },
});
if (!res.ok) continue;
data = await res.json();
break;
} catch {
// try next URL on error (including timeout)
}
}
clearTimeout(timeout);
if (!data) {
throw new Error("Failed to fetch plugins manifest from any known URL.");
}
🤖 Prompt for AI Agents
In src/getPluginsJson.ts around line 26, the fetch call lacks ok-checks, a
timeout, and a fallback; update it to use an AbortController with a short
timeout (e.g., 3s), await fetch and verify res.ok before calling res.json(), and
if the first request fails (network error, non-ok, or timeout) attempt the
previous manifest URL (e.g., the same raw GitHub path but using the prior
branch/path such as "master/plugins.json"); if both attempts fail, handle
gracefully by returning an empty array (or a safe default) and log a warning
instead of letting .json() throw and break the build.

const plugins = await getCollection("plugins");

cachedData = data.map(v => {
Expand Down