Publish the latest Android version code (#2085)

* feat(website): publish latest Android version code

* fix(website): select latest Android APK release
This commit is contained in:
Mohamed Boudra
2026-07-15 21:38:52 +08:00
committed by GitHub
parent 4a5630bfce
commit 319d9017c2
9 changed files with 283 additions and 134 deletions
+24 -4
View File
@@ -1,10 +1,14 @@
import startEntry from "@tanstack/react-start/server-entry";
import { getAndroidVersionCode } from "~/android-version";
import { getDoc } from "~/docs";
import { getLatestAndroidVersion } from "~/latest-release";
import { buildLlmsTxt } from "~/llms";
const CANONICAL_HOST = "paseo.sh";
type FetchArgs = Parameters<typeof startEntry.fetch>;
interface WebsiteEnv {
WEBSITE_CACHE?: KVNamespace;
}
function markdownResponse(body: string): Response {
return new Response(body, {
@@ -15,6 +19,15 @@ function markdownResponse(body: string): Response {
});
}
function plainTextResponse(body: string): Response {
return new Response(body, {
headers: {
"content-type": "text/plain; charset=utf-8",
"cache-control": "public, max-age=300, s-maxage=300",
},
});
}
function docSlugFromMarkdownPath(pathname: string): string | null {
if (pathname === "/docs.md") return "";
const match = pathname.match(/^\/docs\/(.+)\.md$/);
@@ -22,8 +35,7 @@ function docSlugFromMarkdownPath(pathname: string): string | null {
}
export default {
async fetch(...args: FetchArgs): Promise<Response> {
const [request] = args;
async fetch(request: Request, env: WebsiteEnv, context: ExecutionContext): Promise<Response> {
const url = new URL(request.url);
const isLocal = url.hostname === "localhost" || url.hostname === "127.0.0.1";
@@ -43,6 +55,14 @@ export default {
return markdownResponse(buildLlmsTxt());
}
if (url.pathname === "/android-version.txt") {
const version = await getLatestAndroidVersion({
cache: env.WEBSITE_CACHE ?? null,
waitUntil: (promise) => context.waitUntil(promise),
});
return plainTextResponse(`${getAndroidVersionCode(version)}\n`);
}
const slug = docSlugFromMarkdownPath(url.pathname);
if (slug !== null) {
const doc = getDoc(slug);
@@ -50,6 +70,6 @@ export default {
return markdownResponse(doc.content);
}
return startEntry.fetch(...args);
return startEntry.fetch(request);
},
};