Skip to content

Commit 395403d

Browse files
Ensure new claims have clean urls, Fixes: #390
1 parent e630916 commit 395403d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

routes/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
6969

7070
du.createClaim(
7171
req.user.usergithub.username,
72-
req.body.issue_url,
73-
req.body.pull_url,
72+
du.generateGenericUrl(req.body.issue_url),
73+
du.generateGenericUrl(req.body.pull_url),
7474
req.body.bounty,
7575
config.CLAIM_STATUS.CLAIMED
7676
)

routes/root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ route.post('/claims/add', auth.ensureLoggedInGithub, (req, res) => {
248248

249249
du.createClaim(
250250
req.user.usergithub.username, // github username already valid
251-
req.body.issue_url,
252-
req.body.pull_url,
251+
du.generateGenericUrl(req.body.issue_url),
252+
du.generateGenericUrl(req.body.pull_url),
253253
req.body.bounty,
254254
config.CLAIM_STATUS.CLAIMED
255255
)

utils/datautils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const db = require('./db')
55
const fs = require('fs')
66
const consts = require('./consts')
77

8+
function generateGenericUrl(url) {
9+
const extractSingleUrl = url.trim().split(' ')[0].split('#')[0]
10+
const genericUrl = new URL(extractSingleUrl).pathname.replace(/\/+$/, '')
11+
return `https://github.com${genericUrl}`
12+
}
13+
814
function getContestPeriod(year) {
915
if (year)
1016
return {
@@ -180,5 +186,6 @@ module.exports = {
180186
getLoggedInUserStats,
181187
getClaimById,
182188
updateClaim,
189+
generateGenericUrl,
183190
getCounts
184191
}

0 commit comments

Comments
 (0)