-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into #539-방-생성시-어뷰징-사전검증-처리-방식-개선
- Loading branch information
Showing
12 changed files
with
223 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { validateServiceBanRecord } = require("../modules/ban"); | ||
|
||
const serviceMapper = new Map([ | ||
["/rooms/create", "service"], | ||
["/rooms/join", "service"], | ||
]); | ||
|
||
const banMiddleware = async (req, res, next) => { | ||
const banErrorMessage = await validateServiceBanRecord( | ||
req, | ||
serviceMapper.get(req.originalUrl) | ||
); | ||
if (banErrorMessage !== undefined) { | ||
return res.status(400).json({ error: banErrorMessage }); | ||
} | ||
next(); | ||
}; | ||
|
||
module.exports = banMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const logger = require("./logger"); | ||
const { banModel } = require("./stores/mongo"); | ||
|
||
/** | ||
* @param {*} req | ||
* @param {String} service | ||
*/ | ||
const validateServiceBanRecord = async (req, service) => { | ||
let banRecord = undefined; | ||
|
||
try { | ||
// 현재 시각이 expireAt 보다 작고, 본인인 경우(ban의 userId가 userId랑 같은 경우) 중 serviceName이 "service"인 record를 모두 가져옴 | ||
const bans = await banModel | ||
.find({ | ||
userSid: req.session.loginInfo.sid, | ||
expireAt: { | ||
$gte: req.timestamp, | ||
}, | ||
serviceName: service, | ||
}) | ||
.sort({ expireAt: -1 }); | ||
if (bans.length > 0) { | ||
// 가장 expireAt이 큰 정지 기록만 반환함. | ||
banRecord = bans[0]; | ||
} | ||
} catch (err) { | ||
logger.error( | ||
"Error occured while validateServiceBanRecord: " + err.message | ||
); | ||
return; | ||
} | ||
if (banRecord !== undefined) { | ||
const formattedExpireAt = banRecord.expireAt | ||
.toISOString() | ||
.replace("T", " ") | ||
.split(".")[0]; | ||
const banErrorMessage = `${req.originalUrl} : user ${req.userId} (${req.session.loginInfo.sid}) is temporarily restricted from service until ${formattedExpireAt}.`; | ||
return banErrorMessage; | ||
} | ||
return; | ||
}; | ||
|
||
module.exports = { | ||
validateServiceBanRecord, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.