프로필 이미지 기능 수정
This commit is contained in:
@@ -1739,6 +1739,7 @@ export const getUserInfo = async (req: AuthenticatedRequest, res: Response) => {
|
||||
u.fax_no,
|
||||
u.partner_objid,
|
||||
u.rank,
|
||||
u.photo,
|
||||
u.locale,
|
||||
u.company_code,
|
||||
u.data_type,
|
||||
@@ -1791,6 +1792,9 @@ export const getUserInfo = async (req: AuthenticatedRequest, res: Response) => {
|
||||
faxNo: user.fax_no,
|
||||
partnerObjid: user.partner_objid,
|
||||
rank: user.rank,
|
||||
photo: user.photo
|
||||
? `data:image/jpeg;base64,${user.photo.toString("base64")}`
|
||||
: null,
|
||||
locale: user.locale,
|
||||
companyCode: user.company_code,
|
||||
dataType: user.data_type,
|
||||
@@ -2724,7 +2728,24 @@ export const updateProfile = async (
|
||||
if (email !== undefined) updateData.email = email;
|
||||
if (tel !== undefined) updateData.tel = tel;
|
||||
if (cellPhone !== undefined) updateData.cell_phone = cellPhone;
|
||||
if (photo !== undefined) updateData.photo = photo;
|
||||
|
||||
// photo 데이터 처리 (Base64를 Buffer로 변환하여 저장)
|
||||
if (photo !== undefined) {
|
||||
if (photo && typeof photo === "string") {
|
||||
try {
|
||||
// Base64 헤더 제거 (data:image/jpeg;base64, 등)
|
||||
const base64Data = photo.replace(/^data:image\/[a-z]+;base64,/, "");
|
||||
// Base64를 Buffer로 변환
|
||||
updateData.photo = Buffer.from(base64Data, "base64");
|
||||
} catch (error) {
|
||||
console.error("Base64 이미지 처리 오류:", error);
|
||||
updateData.photo = null;
|
||||
}
|
||||
} else {
|
||||
updateData.photo = null; // 빈 값이면 null로 설정
|
||||
}
|
||||
}
|
||||
|
||||
if (locale !== undefined) updateData.locale = locale;
|
||||
|
||||
// 업데이트할 데이터가 없으면 에러
|
||||
@@ -2767,10 +2788,18 @@ export const updateProfile = async (
|
||||
},
|
||||
});
|
||||
|
||||
// photo가 Buffer 타입인 경우 Base64로 변환
|
||||
const responseData = {
|
||||
...updatedUser,
|
||||
photo: updatedUser?.photo
|
||||
? `data:image/jpeg;base64,${updatedUser.photo.toString("base64")}`
|
||||
: null,
|
||||
};
|
||||
|
||||
res.json({
|
||||
result: true,
|
||||
message: "프로필이 성공적으로 업데이트되었습니다.",
|
||||
data: updatedUser,
|
||||
data: responseData,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("프로필 업데이트 오류:", error);
|
||||
|
||||
Reference in New Issue
Block a user