添加html页面
This commit is contained in:
+17
-5
@@ -88,7 +88,7 @@ import {
|
||||
verifyCredentials
|
||||
} from "./mastodon";
|
||||
import { processOutgoingDeliveries } from "./federation";
|
||||
import { profilePage } from "./profile";
|
||||
import { homePage, objectPage, profilePage, statusPage } from "./profile";
|
||||
|
||||
export default {
|
||||
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
||||
@@ -117,7 +117,10 @@ async function route(request: Request, env: Env): Promise<Response> {
|
||||
const path = url.pathname.replace(/\/+$/, "") || "/";
|
||||
const method = request.method.toUpperCase();
|
||||
|
||||
if (method === "GET" && path === "/") return nodeInfo(env);
|
||||
if (method === "GET" && path === "/") {
|
||||
if (wantsHtmlDocument(request)) return homePage(env);
|
||||
return nodeInfo(env);
|
||||
}
|
||||
if (method === "GET" && path === "/avatar.png") return svgResponse(AVATAR_SVG);
|
||||
if (method === "GET" && path === "/header.png") return svgResponse(HEADER_SVG);
|
||||
|
||||
@@ -213,13 +216,18 @@ 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(/^\/@([^/]+)\/([^/]+)$/))) return statusPage(env, decodeURIComponent(m[1]), decodeURIComponent(m[2]));
|
||||
if (method === "GET" && (m = path.match(/^\/@([^/]+)$/))) return profilePage(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/web\/@([^/]+)\/([^/]+)$/))) return statusPage(env, decodeURIComponent(m[1]), decodeURIComponent(m[2]));
|
||||
if (method === "GET" && (m = path.match(/^\/web\/@([^/]+)$/))) return profilePage(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/web\/statuses\/([^/]+)$/))) return objectPage(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/statuses\/([^/]+)$/))) return objectPage(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\/([^/]+)\/statuses\/([^/]+)$/))) return statusPage(env, decodeURIComponent(m[1]), decodeURIComponent(m[2]));
|
||||
|
||||
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)$/))) {
|
||||
const username = decodeURIComponent(m[1]);
|
||||
if (wantsProfileHtml(request)) return profilePage(env, username);
|
||||
if (wantsHtmlDocument(request)) return profilePage(env, username);
|
||||
return actor(env, username);
|
||||
}
|
||||
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)\/outbox$/))) return outbox(request, env, decodeURIComponent(m[1]));
|
||||
@@ -227,12 +235,16 @@ async function route(request: Request, env: Env): Promise<Response> {
|
||||
if (method === "POST" && path === "/inbox") return inboxHandler(request, env, null);
|
||||
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)\/followers$/))) return followersCollection(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)\/following$/))) return followingCollection(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/objects\/([^/]+)$/))) return activityObject(env, decodeURIComponent(m[1]));
|
||||
if (method === "GET" && (m = path.match(/^\/objects\/([^/]+)$/))) {
|
||||
const objectId = decodeURIComponent(m[1]);
|
||||
if (wantsHtmlDocument(request)) return objectPage(env, objectId);
|
||||
return activityObject(env, objectId);
|
||||
}
|
||||
|
||||
return json({ error: "not_found" }, 404);
|
||||
}
|
||||
|
||||
function wantsProfileHtml(request: Request): boolean {
|
||||
function wantsHtmlDocument(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user