Skip to content

Commit f6a4bc6

Browse files
committed
πŸ› Fix: μˆ˜μ • νšŒμ›κ°€μž… (RegisterUser.js)
- νšŒμ›κ°€μž… μ‹œ 사진이 undefined에 μ €μž₯λ˜λŠ” 문제 μˆ˜μ •
1 parent 28f6302 commit f6a4bc6

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

Diff for: β€Žsrc/main.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const aiAPI = process.env.AI_API
1818

1919
const allowedOrigins = [
2020
'http://localhost:3000',
21+
'http://localhost:3001',
2122
'http://www.model-fit.kro.kr',
2223
aiAPI,
2324
]
@@ -73,9 +74,7 @@ const infoRouter = require('./routes/UserInfo')
7374
app.use('/userInfo', infoRouter)
7475

7576
const fittingRouter = require('./routes/FittingImage')
76-
const clothUploadRouter = require('./routes/UploadClothImage')
7777
app.use('/api', fittingRouter)
78-
app.use('/api', clothUploadRouter)
7978

8079
const clothRouter = require('./routes/Clothes')
8180
app.use('/cloth', clothRouter)

Diff for: β€Žsrc/routes/ImageUploader.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const aws = require('@aws-sdk/client-s3')
22
const multer = require('multer')
33
const multers3 = require('multer-s3')
44
const path = require('path')
5+
const { ObjectId } = require('mongodb')
56

67
const { S3Client, PutObjectCommand } = aws
78

@@ -26,7 +27,14 @@ const ImageUploader = multer({
2627
s3: s3,
2728
bucket: 'bigprogect-bucket',
2829
key: (req, file, callback) => {
29-
const userId = req.body.userId || req.query.userId
30+
/*
31+
νšŒμ›κ°€μž… μ‹œ 신체 이미지 μ—…λ‘œλ“œ ν•˜λ©΄ 아직 DB에 컬럼이 μ—†μŒ.
32+
=> userId ν•„λ“œλŠ” 무쑰건 undefinedκ°€ 됨.
33+
=> s3/undefined/에 이미지가 μ €μž₯ 됨
34+
=> idλ₯Ό 생성할 수 있게 [ ?? new ObjectId().toString() ] μΆ”κ°€
35+
*/
36+
const userId =
37+
(req.body.userId || req.query.userId) ?? new ObjectId().toString()
3038
const uploadDirectory = req.query.directory ?? userId
3139
const extension = path.extname(file.originalname)
3240
if (!allowedExtensions.includes(extension)) {

Diff for: β€Žsrc/routes/RegisterUser.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ router.post(
2727
favoriteStyle,
2828
} = req.body
2929
const file = req.file ? req.file.location : undefined
30+
// μ €μž₯ν•œ 파일 κ²½λ‘œμ—μ„œ userID μΆ”μΆœ
31+
const userId = req.file.key.split('/')[0]
3032

3133
try {
3234
const userExists = await User.findOne({ email: userEmail })
@@ -40,6 +42,7 @@ router.post(
4042

4143
// μƒˆλ‘œμš΄ μ‚¬μš©μž 생성 및 μ €μž₯
4244
const newUser = new User({
45+
_id: userId,
4346
email: userEmail,
4447
name,
4548
phoneNumber,
@@ -63,9 +66,8 @@ router.post(
6366
}
6467

6568
// μ‚¬μ΄μ¦ˆ λ°›μ•„μ˜€κΈ°
66-
const responseFromAIApi = await axios.post(aiApiEndpoint, {
67-
height,
68-
weight,
69+
const responseFromAIApi = await axios.get(aiApiEndpoint, {
70+
params: { height: height, weight: weight },
6971
})
7072

7173
if (responseFromAIApi.data.error) {

0 commit comments

Comments
Β (0)