You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.4 KiB
39 lines
1.4 KiB
import { updateProfile } from "#server/service/profile";
|
|
import { visibilitySchema } from "#server/constants/visibility";
|
|
import { isUniqueConstraintViolation } from "#server/utils/db-unique-constraint";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await event.context.auth.requireUser();
|
|
const body = await readBody<{
|
|
nickname?: string | null;
|
|
avatar?: string | null;
|
|
avatarVisibility?: string;
|
|
bioMarkdown?: string | null;
|
|
bioVisibility?: string;
|
|
socialLinks?: { label: string; url: string; visibility: string }[];
|
|
publicSlug?: string | null;
|
|
}>(event);
|
|
|
|
try {
|
|
const row = await updateProfile(user.id, {
|
|
nickname: body.nickname,
|
|
avatar: body.avatar,
|
|
avatarVisibility:
|
|
body.avatarVisibility !== undefined ? visibilitySchema.parse(body.avatarVisibility) : undefined,
|
|
bioMarkdown: body.bioMarkdown,
|
|
bioVisibility:
|
|
body.bioVisibility !== undefined ? visibilitySchema.parse(body.bioVisibility) : undefined,
|
|
socialLinks: body.socialLinks,
|
|
publicSlug: body.publicSlug,
|
|
});
|
|
if (!row) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
return R.success({ ok: true });
|
|
} catch (e) {
|
|
if (isUniqueConstraintViolation(e)) {
|
|
throw createError({ statusCode: 409, statusMessage: "公开链接 slug 已被占用" });
|
|
}
|
|
throw e;
|
|
}
|
|
});
|
|
|