fix: return 410 for api/github (#45250)
This commit is contained in:
committed by
GitHub
parent
d501817207
commit
ce23dcb32c
@ -1,16 +1,10 @@
|
|||||||
import request from 'request';
|
|
||||||
|
|
||||||
import { gitHubUserAgent } from '../../../../config/misc';
|
|
||||||
import { getRedirectParams } from '../utils/redirection';
|
import { getRedirectParams } from '../utils/redirection';
|
||||||
|
|
||||||
const githubClient = process.env.GITHUB_ID;
|
|
||||||
const githubSecret = process.env.GITHUB_SECRET;
|
|
||||||
|
|
||||||
module.exports = function (app) {
|
module.exports = function (app) {
|
||||||
const router = app.loopback.Router();
|
const router = app.loopback.Router();
|
||||||
const User = app.models.User;
|
const User = app.models.User;
|
||||||
|
|
||||||
router.get('/api/github', githubCalls);
|
router.get('/api/github', gone);
|
||||||
router.get('/u/:email', unsubscribeDeprecated);
|
router.get('/u/:email', unsubscribeDeprecated);
|
||||||
router.get('/unsubscribe/:email', unsubscribeDeprecated);
|
router.get('/unsubscribe/:email', unsubscribeDeprecated);
|
||||||
router.get('/ue/:unsubscribeId', unsubscribeById);
|
router.get('/ue/:unsubscribeId', unsubscribeById);
|
||||||
@ -18,6 +12,15 @@ module.exports = function (app) {
|
|||||||
|
|
||||||
app.use(router);
|
app.use(router);
|
||||||
|
|
||||||
|
function gone(_, res) {
|
||||||
|
return res.status(410).json({
|
||||||
|
message: {
|
||||||
|
type: 'info',
|
||||||
|
message: 'Please reload the app, this feature is no longer available.'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function unsubscribeDeprecated(req, res) {
|
function unsubscribeDeprecated(req, res) {
|
||||||
req.flash(
|
req.flash(
|
||||||
'info',
|
'info',
|
||||||
@ -111,55 +114,4 @@ module.exports = function (app) {
|
|||||||
.catch(next);
|
.catch(next);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function githubCalls(req, res, next) {
|
|
||||||
var githubHeaders = {
|
|
||||||
headers: {
|
|
||||||
'User-Agent': gitHubUserAgent
|
|
||||||
},
|
|
||||||
port: 80
|
|
||||||
};
|
|
||||||
request(
|
|
||||||
[
|
|
||||||
'https://api.github.com/repos/freecodecamp/',
|
|
||||||
'freecodecamp/pulls?client_id=',
|
|
||||||
githubClient,
|
|
||||||
'&client_secret=',
|
|
||||||
githubSecret
|
|
||||||
].join(''),
|
|
||||||
githubHeaders,
|
|
||||||
function (err, status1, pulls) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
pulls = pulls
|
|
||||||
? Object.keys(JSON.parse(pulls)).length
|
|
||||||
: "Can't connect to github";
|
|
||||||
|
|
||||||
return request(
|
|
||||||
[
|
|
||||||
'https://api.github.com/repos/freecodecamp/',
|
|
||||||
'freecodecamp/issues?client_id=',
|
|
||||||
githubClient,
|
|
||||||
'&client_secret=',
|
|
||||||
githubSecret
|
|
||||||
].join(''),
|
|
||||||
githubHeaders,
|
|
||||||
function (err, status2, issues) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
issues =
|
|
||||||
pulls === parseInt(pulls, 10) && issues
|
|
||||||
? Object.keys(JSON.parse(issues)).length - pulls
|
|
||||||
: "Can't connect to GitHub";
|
|
||||||
return res.json({
|
|
||||||
issues: issues,
|
|
||||||
pulls: pulls
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1 @@
|
|||||||
exports.defaultUserImage = 'https://freecodecamp.com/sample-image.png';
|
exports.defaultUserImage = 'https://freecodecamp.com/sample-image.png';
|
||||||
exports.gitHubUserAgent =
|
|
||||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36';
|
|
||||||
|
Reference in New Issue
Block a user