diff --git a/server/api/me/profile.get.ts b/server/api/me/profile.get.ts index 6b63d0e..fc74033 100644 --- a/server/api/me/profile.get.ts +++ b/server/api/me/profile.get.ts @@ -18,6 +18,9 @@ export default defineWrappedResponseHandler(async (event) => { bioVisibility: row.bioVisibility, socialLinks: parseSocialLinksJson(row.socialLinksJson), publicSlug: row.publicSlug, + discoverVisible: Boolean(row.discoverVisible), + discoverLocation: row.discoverLocation ?? null, + discoverShowLocation: Boolean(row.discoverShowLocation), role: row.role, status: row.status, }, diff --git a/server/api/me/profile.put.ts b/server/api/me/profile.put.ts index 34133a9..d821b36 100644 --- a/server/api/me/profile.put.ts +++ b/server/api/me/profile.put.ts @@ -12,6 +12,9 @@ export default defineWrappedResponseHandler(async (event) => { bioVisibility?: string; socialLinks?: { label: string; url: string; visibility: string; icon?: string }[]; publicSlug?: string | null; + discoverVisible?: boolean; + discoverLocation?: string | null; + discoverShowLocation?: boolean; }>(event); try { @@ -25,6 +28,9 @@ export default defineWrappedResponseHandler(async (event) => { body.bioVisibility !== undefined ? visibilitySchema.parse(body.bioVisibility) : undefined, socialLinks: body.socialLinks, publicSlug: body.publicSlug, + discoverVisible: body.discoverVisible, + discoverLocation: body.discoverLocation, + discoverShowLocation: body.discoverShowLocation, }); if (!row) { throw createError({ statusCode: 404, statusMessage: "未找到" }); diff --git a/server/service/profile/index.ts b/server/service/profile/index.ts index 0b44330..ad35279 100644 --- a/server/service/profile/index.ts +++ b/server/service/profile/index.ts @@ -34,6 +34,14 @@ const linkItemSchema = z.object({ icon: socialLinkIconSchema.optional(), }); +const discoverLocationPatchSchema = z.union([ + z.null(), + z.string().max(200).transform((s) => { + const t = s.trim(); + return t.length > 0 ? t : null; + }), +]); + export type SocialLinkItem = z.infer; export async function getProfileRow(userId: number) { @@ -51,6 +59,9 @@ export async function updateProfile( bioVisibility?: Visibility; socialLinks?: SocialLinkItem[]; publicSlug?: string | null; + discoverVisible?: boolean; + discoverLocation?: string | null; + discoverShowLocation?: boolean; }, ) { const updates: Record = {}; @@ -81,6 +92,15 @@ export async function updateProfile( updates.publicSlug = publicSlugValue.parse(patch.publicSlug.trim().toLowerCase()); } } + if (patch.discoverVisible !== undefined) { + updates.discoverVisible = patch.discoverVisible; + } + if (patch.discoverLocation !== undefined) { + updates.discoverLocation = discoverLocationPatchSchema.parse(patch.discoverLocation); + } + if (patch.discoverShowLocation !== undefined) { + updates.discoverShowLocation = patch.discoverShowLocation; + } if (Object.keys(updates).length === 0) { return getProfileRow(userId);