AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(plugins): fall back to v-prefixed GitHub plugin release tags
tianma-if5260fca9ae82
diff --git a/apps/api/src/plugin-distribution-routes.test.mjs b/apps/api/src/plugin-distribution-routes.test.mjsindex 21807a79..69a9c699 100644--- a/apps/api/src/plugin-distribution-routes.test.mjs+++ b/apps/api/src/plugin-distribution-routes.test.mjs@@ -54,6 +54,71 @@ describe("GitHub plugin release asset proxy", () => {]);});+ test("downloads a v-prefixed public release when the unprefixed tag is missing", async () => {+ const calls = [];+ const buffer = await downloadGithubReleaseAssetByTag({+ owner: "example",+ repository: "edgeever-plugin",+ releaseTag: "0.5.6",+ assetName: "manifest.json",+ request: async (input) => {+ const url = String(input);+ calls.push(url);+ if (url === "https://github.com/example/edgeever-plugin/releases/download/0.5.6/manifest.json") {+ return new Response("missing", { status: 404 });+ }+ if (url === "https://github.com/example/edgeever-plugin/releases/download/v0.5.6/manifest.json") {+ return new Response("{\"version\":\"0.5.6\"}", { headers: { "content-length": "19" } });+ }+ throw new Error(url);+ },+ });++ expect(new TextDecoder().decode(buffer)).toBe("{\"version\":\"0.5.6\"}");+ expect(calls).toEqual([+ "https://github.com/example/edgeever-plugin/releases/download/0.5.6/manifest.json",+ "https://github.com/example/edgeever-plugin/releases/download/v0.5.6/manifest.json",+ ]);+ });++ test("falls back to the v-prefixed GitHub API release when the unprefixed tag is missing", async () => {+ const calls = [];+ const buffer = await downloadGithubReleaseAssetByTag({+ owner: "example",+ repository: "edgeever-plugin",+ releaseTag: "0.5.6",+ assetName: "main.js",+ request: async (input) => {+ const url = String(input);+ calls.push(url);+ if (url.includes("/releases/download/")) return new Response("missing", { status: 404 });+ if (url.endsWith("/releases/tags/0.5.6")) return new Response("missing", { status: 404 });+ if (url.endsWith("/releases/tags/v0.5.6")) {+ return Response.json({+ tag_name: "v0.5.6",+ draft: false,+ assets: [{+ id: 42,+ name: "main.js",+ size: 18,+ url: "https://api.github.com/repos/example/edgeever-plugin/releases/assets/42",+ browser_download_url: "https://github.com/example/edgeever-plugin/releases/download/v0.5.6/main.js",+ }],+ });+ }+ if (url.endsWith("/releases/assets/42")) {+ return new Response("export default {};", { headers: { "content-length": "18" } });+ }+ throw new Error(url);+ },+ });++ expect(new TextDecoder().decode(buffer)).toBe("export default {};");+ expect(calls).toContain("https://api.github.com/repos/example/edgeever-plugin/releases/tags/0.5.6");+ expect(calls).toContain("https://api.github.com/repos/example/edgeever-plugin/releases/tags/v0.5.6");+ expect(calls).toContain("https://api.github.com/repos/example/edgeever-plugin/releases/assets/42");+ });+test("falls back to the GitHub API asset endpoint when the public download URL fails", async () => {const calls = [];const buffer = await downloadGithubReleaseAssetByTag({diff --git a/apps/api/src/plugin-distribution-routes.ts b/apps/api/src/plugin-distribution-routes.tsindex 703c85d2..ca1b509c 100644--- a/apps/api/src/plugin-distribution-routes.ts+++ b/apps/api/src/plugin-distribution-routes.ts@@ -257,6 +257,18 @@ const githubUpstreamError = (context: Parameters<typeof apiError>[0], error: unk);};+const alternateGithubReleaseTag = (releaseTag: string) => {+ if (releaseTag.startsWith("v") && RELEASE_TAG_PATTERN.test(releaseTag.slice(1))) return releaseTag.slice(1);+ const prefixed = `v${releaseTag}`;+ if (!releaseTag.startsWith("v") && RELEASE_TAG_PATTERN.test(prefixed)) return prefixed;+ return null;+};++const githubReleaseTagCandidates = (releaseTag: string) => {+ const alternate = alternateGithubReleaseTag(releaseTag);+ return alternate && alternate !== releaseTag ? [releaseTag, alternate] : [releaseTag];+};+export const downloadGithubReleaseAssetByTag = async ({owner,repository,@@ -273,29 +285,46 @@ export const downloadGithubReleaseAssetByTag = async ({if (!hasValidRepositoryCoordinates(owner, repository) || !RELEASE_TAG_PATTERN.test(releaseTag)) {throw new Error("Invalid GitHub release coordinates.");}- const url = `https://github.com/${owner}/${repository}/releases/download/${releaseTag}/${assetName}`;- try {- const response = await request(url, {- redirect: "follow",- headers: { "User-Agent": "EdgeEver" },- });- return await readBoundedAsset(response, assetName);- } catch (error) {- const release = await readGithubReleaseByTag({ owner, repository, releaseTag, request });- const asset = release.assets.find((candidate) => candidate.name === assetName);- if (!asset) {- const missing = new GithubUpstreamError(`GitHub Release ${releaseTag} is missing ${assetName}.`, 404);- missing.cause = error;- throw missing;+ const tags = githubReleaseTagCandidates(releaseTag);+ let lastError: unknown;+ for (const tag of tags) {+ const url = `https://github.com/${owner}/${repository}/releases/download/${tag}/${assetName}`;+ try {+ const response = await request(url, {+ redirect: "follow",+ headers: { "User-Agent": "EdgeEver" },+ });+ return await readBoundedAsset(response, assetName);+ } catch (error) {+ lastError = error;+ if (error instanceof Error && error.message.includes("exceeds the allowed package size")) throw error;+ }+ }++ for (const tag of tags) {+ try {+ const release = await readGithubReleaseByTag({ owner, repository, releaseTag: tag, request });+ const asset = release.assets.find((candidate) => candidate.name === assetName);+ if (!asset) {+ lastError = new GithubUpstreamError(`GitHub Release ${tag} is missing ${assetName}.`, 404);+ continue;+ }+ return downloadGithubReleaseAsset({+ owner,+ repository,+ assetId: String(asset.id),+ assetName,+ request,+ });+ } catch (error) {+ lastError = error;+ if (!(error instanceof GithubUpstreamError && error.status === 404)) throw error;}- return downloadGithubReleaseAsset({- owner,- repository,- assetId: String(asset.id),- assetName,- request,- });}++ throw lastError instanceof Error+ ? lastError+ : new GithubUpstreamError(`GitHub Release ${releaseTag} is missing ${assetName}.`, 404);};const PLUGIN_MANIFEST_CACHE_TTL_MS = 300_000;@@ -403,6 +432,9 @@ export const registerPluginDistributionRoutes = (app: Hono<AppEnv>) => {"Content-Type": "application/octet-stream",});} catch (error) {+ if (error instanceof GithubUpstreamError && error.status === 404) {+ return githubUpstreamError(context, error);+ }return apiError(context,"github_asset_download_failed",diff --git a/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs b/apps/web/src/lib/plugins/github-plugin-distribution.test.mjsindex 0946f20e..0ea3831f 100644--- a/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs+++ b/apps/web/src/lib/plugins/github-plugin-distribution.test.mjs@@ -223,6 +223,29 @@ describe("GitHub plugin distribution", () => {expect(calls).toContainEqual(["1.2.3", "styles.css"]);});+ test("falls back to a v-prefixed marketplace release tag when the instance reports the GitHub release was not found", async () => {+ const calls = [];+ const assets = {+ "manifest.json": new TextEncoder().encode(JSON.stringify(manifest)).buffer,+ "main.js": new TextEncoder().encode("export default { activate() {} };").buffer,+ };+ const downloadAsset = async (_coordinates, releaseTag, asset) => {+ calls.push([releaseTag, asset.name]);+ if (releaseTag === "1.2.3") throw new Error("GitHub release was not found.");+ const buffer = assets[asset.name];+ if (!buffer) throw new Error(`GitHub asset ${asset.name} failed with HTTP 404.`);+ return buffer;+ };++ const downloaded = await downloadPinnedGithubExtension("https://github.com/example/edgeever-plugin", "1.2.3", {+ downloadAssetBytes: downloadAsset,+ });++ expect(downloaded.releaseTag).toBe("v1.2.3");+ expect(calls[0]).toEqual(["1.2.3", "manifest.json"]);+ expect(calls).toContainEqual(["v1.2.3", "main.js"]);+ });+test("falls back to a v-prefixed marketplace release tag when the unprefixed tag is missing", async () => {const calls = [];const assets = {diff --git a/apps/web/src/lib/plugins/github-plugin-distribution.ts b/apps/web/src/lib/plugins/github-plugin-distribution.tsindex beb47f22..38d42be4 100644--- a/apps/web/src/lib/plugins/github-plugin-distribution.ts+++ b/apps/web/src/lib/plugins/github-plugin-distribution.ts@@ -76,8 +76,11 @@ const isGithubUnreachableError = (error: unknown) => {const isGithubRateLimitedStatus = (status: number) => status === 403 || status === 429;const isMissingGithubAssetError = (error: unknown) => {+ if (error instanceof ApiRequestError && error.status === 404) return true;const message = error instanceof Error ? error.message : String(error);- return /HTTP 404/i.test(message);+ return /HTTP 404/i.test(message)+ || /GitHub release was not found/i.test(message)+ || /GitHub Release .+ (was not found|is missing )/i.test(message);};const fetchGithubMetadataThroughInstance = async (url: string): Promise<Response> => {