添加html页面
This commit is contained in:
+3
-2
@@ -44,7 +44,8 @@ import {
|
|||||||
id,
|
id,
|
||||||
mediaUrl,
|
mediaUrl,
|
||||||
objectUrl,
|
objectUrl,
|
||||||
profileUrl
|
profileUrl,
|
||||||
|
statusUrl
|
||||||
} from "./util";
|
} from "./util";
|
||||||
|
|
||||||
export async function webFinger(request: Request, env: Env): Promise<Response> {
|
export async function webFinger(request: Request, env: Env): Promise<Response> {
|
||||||
@@ -746,7 +747,7 @@ export function noteObject(env: Env, user: User, status: Status, opts: { to?: st
|
|||||||
attributedTo: actorUrl(env, user),
|
attributedTo: actorUrl(env, user),
|
||||||
content: status.content,
|
content: status.content,
|
||||||
published: status.created_at,
|
published: status.created_at,
|
||||||
url: status.url,
|
url: statusUrl(env, user, status.id),
|
||||||
to: opts.to ?? audience.to,
|
to: opts.to ?? audience.to,
|
||||||
cc: opts.cc ?? audience.cc,
|
cc: opts.cc ?? audience.cc,
|
||||||
attachment: opts.attachments ?? [],
|
attachment: opts.attachments ?? [],
|
||||||
|
|||||||
+17
-5
@@ -88,7 +88,7 @@ import {
|
|||||||
verifyCredentials
|
verifyCredentials
|
||||||
} from "./mastodon";
|
} from "./mastodon";
|
||||||
import { processOutgoingDeliveries } from "./federation";
|
import { processOutgoingDeliveries } from "./federation";
|
||||||
import { profilePage } from "./profile";
|
import { homePage, objectPage, profilePage, statusPage } from "./profile";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
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 path = url.pathname.replace(/\/+$/, "") || "/";
|
||||||
const method = request.method.toUpperCase();
|
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 === "/avatar.png") return svgResponse(AVATAR_SVG);
|
||||||
if (method === "GET" && path === "/header.png") return svgResponse(HEADER_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(/^\/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(/^\/@([^/]+)$/))) 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\/@([^/]+)$/))) 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(/^\/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\/([^/]+)$/))) {
|
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)$/))) {
|
||||||
const username = decodeURIComponent(m[1]);
|
const username = decodeURIComponent(m[1]);
|
||||||
if (wantsProfileHtml(request)) return profilePage(env, username);
|
if (wantsHtmlDocument(request)) return profilePage(env, username);
|
||||||
return actor(env, username);
|
return actor(env, username);
|
||||||
}
|
}
|
||||||
if (method === "GET" && (m = path.match(/^\/users\/([^/]+)\/outbox$/))) return outbox(request, env, decodeURIComponent(m[1]));
|
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 === "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\/([^/]+)\/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(/^\/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);
|
return json({ error: "not_found" }, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wantsProfileHtml(request: Request): boolean {
|
function wantsHtmlDocument(request: Request): boolean {
|
||||||
const accept = request.headers.get("accept") ?? "";
|
const accept = request.headers.get("accept") ?? "";
|
||||||
return /\btext\/html\b/i.test(accept) && !/(application\/activity\+json|application\/ld\+json)/i.test(accept);
|
return /\btext\/html\b/i.test(accept) && !/(application\/activity\+json|application\/ld\+json)/i.test(accept);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -96,6 +96,7 @@ import {
|
|||||||
objectUrl,
|
objectUrl,
|
||||||
profileUrl,
|
profileUrl,
|
||||||
safeFileName,
|
safeFileName,
|
||||||
|
statusUrl,
|
||||||
tokenString
|
tokenString
|
||||||
} from "./util";
|
} from "./util";
|
||||||
|
|
||||||
@@ -626,7 +627,7 @@ async function publishStatus(env: Env, user: User, input: StatusCreateInput): Pr
|
|||||||
activityId,
|
activityId,
|
||||||
objectId,
|
objectId,
|
||||||
now,
|
now,
|
||||||
objectId
|
statusUrl(env, user, statusId)
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@@ -959,7 +960,7 @@ export async function deleteStatusEndpoint(request: Request, env: Env, statusId:
|
|||||||
|
|
||||||
await env.DB.prepare(
|
await env.DB.prepare(
|
||||||
"INSERT INTO deleted_statuses (id, user_id, object_id, url, deleted_at) VALUES (?, ?, ?, ?, ?)"
|
"INSERT INTO deleted_statuses (id, user_id, object_id, url, deleted_at) VALUES (?, ?, ?, ?, ?)"
|
||||||
).bind(status.id, user.id, status.object_id, status.url, new Date().toISOString()).run();
|
).bind(status.id, user.id, status.object_id, statusUrl(env, user, status.id), new Date().toISOString()).run();
|
||||||
await env.DB.prepare("DELETE FROM statuses WHERE id = ?").bind(status.id).run();
|
await env.DB.prepare("DELETE FROM statuses WHERE id = ?").bind(status.id).run();
|
||||||
await env.DB.prepare("DELETE FROM media WHERE status_id = ?").bind(status.id).run();
|
await env.DB.prepare("DELETE FROM media WHERE status_id = ?").bind(status.id).run();
|
||||||
await env.DB.prepare("DELETE FROM mentions WHERE status_id = ?").bind(status.id).run();
|
await env.DB.prepare("DELETE FROM mentions WHERE status_id = ?").bind(status.id).run();
|
||||||
@@ -1885,7 +1886,7 @@ function statusRecord(env: Env, status: Status, user: User, context: StatusSeria
|
|||||||
return {
|
return {
|
||||||
id: status.id,
|
id: status.id,
|
||||||
uri: status.object_id,
|
uri: status.object_id,
|
||||||
url: status.url,
|
url: statusUrl(env, user, status.id),
|
||||||
account: context.accountByUserId.get(user.id) ?? {
|
account: context.accountByUserId.get(user.id) ?? {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
|
|||||||
+712
-176
File diff suppressed because it is too large
Load Diff
@@ -99,6 +99,10 @@ export function profileUrl(env: Env, user: User): string {
|
|||||||
return `${baseUrl(env)}/@${encodeURIComponent(user.username)}`;
|
return `${baseUrl(env)}/@${encodeURIComponent(user.username)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function statusUrl(env: Env, user: User, statusId: string): string {
|
||||||
|
return `${profileUrl(env, user)}/${encodeURIComponent(statusId)}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function objectUrl(env: Env, statusId: string): string {
|
export function objectUrl(env: Env, statusId: string): string {
|
||||||
return `${baseUrl(env)}/objects/${statusId}`;
|
return `${baseUrl(env)}/objects/${statusId}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user