修复个人资料

This commit is contained in:
浪子
2026-05-14 13:37:13 +08:00
parent 5b01f18719
commit 5a9acd60c5
7 changed files with 208 additions and 17 deletions
+33 -3
View File
@@ -8,6 +8,7 @@ import {
getStatus,
getStatusByObjectId,
getUserByUsername,
listProfileFields,
recordNotification,
upsertActorCache,
upsertCachedStatus
@@ -42,6 +43,7 @@ import {
clampLimit,
hostFromBaseUrl,
id,
mediaUrl,
objectUrl
} from "./util";
@@ -97,8 +99,22 @@ export async function actor(env: Env, username: string): Promise<Response> {
export async function actorDocument(env: Env, user: User): Promise<Json> {
const url = actorUrl(env, user);
const fields = await listProfileFields(env, user.id);
const avatarUrl = user.avatar_r2_key ? mediaUrl(env, user.avatar_r2_key) : `${baseUrl(env)}/avatar.png`;
const headerUrl = user.header_r2_key ? mediaUrl(env, user.header_r2_key) : `${baseUrl(env)}/header.png`;
const avatarMime = guessImageMime(user.avatar_r2_key);
const headerMime = guessImageMime(user.header_r2_key);
return {
"@context": [ACTIVITY_CONTEXT, SECURITY_CONTEXT, { manuallyApprovesFollowers: "as:manuallyApprovesFollowers" }],
"@context": [
ACTIVITY_CONTEXT,
SECURITY_CONTEXT,
{
manuallyApprovesFollowers: "as:manuallyApprovesFollowers",
schema: "http://schema.org#",
PropertyValue: "schema:PropertyValue",
value: "schema:value"
}
],
id: url,
type: "Person",
preferredUsername: user.username,
@@ -110,10 +126,11 @@ export async function actorDocument(env: Env, user: User): Promise<Json> {
followers: `${url}/followers`,
following: `${url}/following`,
endpoints: { sharedInbox: `${baseUrl(env)}/inbox` },
icon: { type: "Image", mediaType: "image/svg+xml", url: `${baseUrl(env)}/avatar.png` },
image: { type: "Image", mediaType: "image/svg+xml", url: `${baseUrl(env)}/header.png` },
icon: { type: "Image", mediaType: avatarMime, url: avatarUrl },
image: { type: "Image", mediaType: headerMime, url: headerUrl },
manuallyApprovesFollowers: false,
discoverable: true,
attachment: fields.map((field) => ({ type: "PropertyValue", name: field.name, value: field.value })),
publicKey: {
id: `${url}#main-key`,
owner: url,
@@ -122,6 +139,19 @@ export async function actorDocument(env: Env, user: User): Promise<Json> {
};
}
function guessImageMime(r2Key: string | null): string {
if (!r2Key) return "image/svg+xml";
const ext = r2Key.split(".").pop()?.toLowerCase();
switch (ext) {
case "jpg": case "jpeg": return "image/jpeg";
case "png": return "image/png";
case "gif": return "image/gif";
case "webp": return "image/webp";
case "avif": return "image/avif";
default: return "image/jpeg";
}
}
export async function outbox(request: Request, env: Env, username: string): Promise<Response> {
const user = await getUserByUsername(env, username);
if (!user) return json({ error: "not_found" }, 404);