完善账号html

This commit is contained in:
浪子
2026-05-16 09:20:00 +08:00
parent 3065049aaf
commit 6c104b9db3
6 changed files with 466 additions and 12 deletions
+15 -1
View File
@@ -88,6 +88,7 @@ import {
verifyCredentials
} from "./mastodon";
import { processOutgoingDeliveries } from "./federation";
import { profilePage } from "./profile";
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
@@ -212,7 +213,15 @@ async function route(request: Request, env: Env): Promise<Response> {
if (method === "GET" && (m = path.match(/^\/media\/(.+)$/))) return serveMedia(env, m[1]);
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)$/))) return actor(env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/@([^/]+)$/))) return profilePage(env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/web\/@([^/]+)$/))) return profilePage(env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/web\/accounts\/([^/]+)$/))) return profilePage(env, decodeURIComponent(m[1]));
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)$/))) {
const username = decodeURIComponent(m[1]);
if (wantsProfileHtml(request)) return profilePage(env, username);
return actor(env, username);
}
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)\/outbox$/))) return outbox(request, env, decodeURIComponent(m[1]));
if (method === "POST" && (m = path.match(/^\/users\/([^/]+)\/inbox$/))) return inboxHandler(request, env, decodeURIComponent(m[1]));
if (method === "POST" && path === "/inbox") return inboxHandler(request, env, null);
@@ -222,3 +231,8 @@ async function route(request: Request, env: Env): Promise<Response> {
return json({ error: "not_found" }, 404);
}
function wantsProfileHtml(request: Request): boolean {
const accept = request.headers.get("accept") ?? "";
return /\btext\/html\b/i.test(accept) && !/(application\/activity\+json|application\/ld\+json)/i.test(accept);
}