Skip to content

Commit

Permalink
Merge pull request #248 from hyeeyoung/dev-mod-parsing
Browse files Browse the repository at this point in the history
[add] 서울스토어 가격 파싱 추가
  • Loading branch information
hyejungg authored Mar 8, 2023
2 parents 0d07023 + 4b1691c commit e69ed44
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module.exports = {
},
refreshToken: async function (req, res, next) {
try {
if (!req.body.accessToken && !req.body.refreshToken) {
if (!req.body.refreshToken) {
throw new BadRequest(ErrorMessage.tokenBadRequest);
}

Expand Down
34 changes: 34 additions & 0 deletions src/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,37 @@ const parsingForGmarket = async (url) => {
return { item_img: itemImg, item_name: itemName, item_price: itemPrice };
};

/* Seoul store */
const parsingForSeoulStore = async (url) => {
let itemImg;
let itemName;
let itemPrice;
await getHtml(url).then((html) => {
if (html.status == 200) {
const $ = cheerio.load(html.data);
$('meta').each((_, el) => {
const tag = $(el).attr('property')?.split(':')[1];
if (tag) {
const value = $(el).attr('content');
switch (tag) {
case 'title':
itemName = value;
itemPrice = value.split('|').reverse()[1];
break;
case 'image':
if (!itemImg) {
itemImg = value;
}
break;
}
}
});
}
});
itemPrice = itemPrice ? getPriceWithoutString(itemPrice) : undefined;
return { item_img: itemImg, item_name: itemName, item_price: itemPrice };
};

const getPriceWithoutString = (itemPrice) => {
return String(itemPrice).replace(/[^0-9]/g, '');
};
Expand All @@ -251,6 +282,9 @@ module.exports = {
) {
return await parsingForMusinsa(site);
}
if (site.startsWith('https://www.seoulstore.com/')) {
return await parsingForSeoulStore(site);
}
if (
site.startsWith('https://m.wconcept.co.kr/') ||
site.startsWith('https://www.wconcept.co.kr/')
Expand Down
10 changes: 3 additions & 7 deletions src/utils/jwtUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const createJwt = async (userId) => {
algorithm: ALGORITHM,
expiresIn: ACCESS_TOKEN_EXPIRES_TIME,
});
const refreshToken = jwt.sign({}, jwtSecret, {
const refreshToken = jwt.sign({ data: userId }, jwtSecret, {
algorithm: ALGORITHM,
expiresIn: REFRESH_TOKEN_EXPIRES_TIME,
});
Expand All @@ -38,12 +38,8 @@ const createJwt = async (userId) => {

const verifyRefresh = async (req, res, next) => {
try {
const reqAccessToken = req.body.accessToken;
const reqRefreshToken = req.body.refreshToken;
const jwtVerify = jwt.verify(reqAccessToken, jwtSecret);

// access token 값으로 존재하는 유저인지 확인
await User.selectUser(jwtVerify.data);
const jwtVerify = jwt.verify(reqRefreshToken, jwtSecret);

const redisRefreshToken = await getRedisClient().get(jwtVerify.data);

Expand All @@ -61,7 +57,7 @@ const verifyRefresh = async (req, res, next) => {

return token;
} catch (err) {
throw new Unauthorized(ErrorMessage.expireToken);
throw new Unauthorized(ErrorMessage.unValidateToken);
}
};

Expand Down

0 comments on commit e69ed44

Please sign in to comment.