프로필 썸네일 해제 시 메타 분리 통일·미디어 모달 다운로드(v0.0.92)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { createError, readBody } from 'h3'
|
||||
import { z } from 'zod'
|
||||
import { getUserById, isUsernameTaken, updateMemberProfile } from '../../repositories/member-repository'
|
||||
import { requireMemberSession } from '../../utils/member-auth'
|
||||
import { isManagedAvatarUrl, removeManagedAvatarAsset } from '../../utils/member-avatar'
|
||||
|
||||
const updateProfileSchema = z.object({
|
||||
username: z.string().trim().min(1).max(30),
|
||||
@@ -36,10 +37,26 @@ export default defineEventHandler(async (event) => {
|
||||
})
|
||||
}
|
||||
|
||||
const existing = await getUserById(session.userId)
|
||||
|
||||
if (!existing) {
|
||||
throw createError({
|
||||
statusCode: 404,
|
||||
message: '회원 정보를 찾을 수 없습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
const previousAvatarUrl = existing.avatarUrl || ''
|
||||
const nextAvatarUrl = parsedBody.data.avatarUrl || ''
|
||||
|
||||
if (previousAvatarUrl && previousAvatarUrl !== nextAvatarUrl && isManagedAvatarUrl(previousAvatarUrl)) {
|
||||
await removeManagedAvatarAsset(previousAvatarUrl)
|
||||
}
|
||||
|
||||
const updated = await updateMemberProfile({
|
||||
userId: session.userId,
|
||||
username: parsedBody.data.username,
|
||||
avatarUrl: parsedBody.data.avatarUrl
|
||||
avatarUrl: nextAvatarUrl
|
||||
})
|
||||
|
||||
if (!updated) {
|
||||
|
||||
Reference in New Issue
Block a user