Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthlogic committed Mar 30, 2024
1 parent b151841 commit 1efba13
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ const toList = (apps) => ({ results: apps });
router.use((req, res, next) => {

if (!req.query.country) {
req.query.country = process.env.COUNTRY_OF_QUERY || 'US';;
req.query.country = process.env.COUNTRY_OF_QUERY || 'US';
}

if (process.env.LOGGING || false) {
console.log("GPlayAPI", req.url, req.baseUrl, req.params, "Status: ", res.statusCode)
console.log("GPlayAPI", req.url, req.baseUrl, req.params, "Status: ", res.statusCode);
}

next();
});


const cleanUrls = (req) => (app) => Object.assign({}, app, {
playstoreUrl: app.url,
url: buildUrl(req, 'apps/' + app.appId),
Expand Down Expand Up @@ -75,7 +74,7 @@ router.get('/apps/', function (req, res, next) {

/* App list */
router.get('/apps/', function (req, res, next) {
function paginate(apps) {
function paginate (apps) {
const num = parseInt(req.query.num || '60');
const start = parseInt(req.query.start || '0');

Expand Down Expand Up @@ -140,13 +139,13 @@ router.get('/apps/:appId/permissions', function (req, res, next) {
router.get('/apps/:appId/reviews', function (req, res, next) {
const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query);
const includeUserData = req.query.userdata === 'true';
const includeReplies = req.query.replies == 'true'
const includeReplies = req.query.replies === 'true';

const processReviews = (reviews, includeUserData, includeReplies) => {
const sanitizeReplyText = (text, userName) => {
const userNameParts = userName.split(' ');

function escapeRegExp(string) {
function escapeRegExp (string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

Expand Down Expand Up @@ -259,12 +258,12 @@ router.get('/collections/', async (req, res, next) => {
}
});

function anonymizeReplyText(replyText, userName) {
function anonymizeReplyText (replyText, userName) {
const userPlaceholder = '<<USER>>';
return replyText.replace(new RegExp(userName, 'g'), userPlaceholder);
}

function errorHandler(err, req, res, next) {
function errorHandler (err, req, res, next) {
if (!res.headersSent) {
const status = err.message === "App not found (404)" ? 404 : 400;
res.status(status).json({ error: status === 404 ? "App not found" : "Bad Request", message: err.message, url: req.url });
Expand All @@ -274,4 +273,4 @@ function errorHandler(err, req, res, next) {

router.use(errorHandler);

export default router;
export default router;

0 comments on commit 1efba13

Please sign in to comment.