diff --git a/lib/index.js b/lib/index.js index d2a7e8d..8a26ada 100644 --- a/lib/index.js +++ b/lib/index.js @@ -10,19 +10,17 @@ const router = Express.Router(); 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), @@ -75,7 +73,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'); @@ -138,15 +136,16 @@ router.get('/apps/:appId/permissions', function (req, res, next) { /* App reviews */ router.get('/apps/:appId/reviews', function (req, res, next) { - const opts = Object.assign({ appId: req.params.appId, country: req.query.country }, req.query); + const opts = Object.assign({ appId: req.params.appId, country: req.query.country, num: parseInt(req.query.num) || 100 }, 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, '\\$&'); } @@ -178,8 +177,7 @@ router.get('/apps/:appId/reviews', function (req, res, next) { rest.date = rest.date.split('T')[0]; return rest; }); - } - else { + } else { reviews.data = reviews.data.map(review => { const { url, ...rest } = review; rest.date = rest.date.split('T')[0]; @@ -190,12 +188,6 @@ router.get('/apps/:appId/reviews', function (req, res, next) { return reviews; }; - // Check if nextPaginationToken is present and not null - if (req.query.nextPaginationToken !== null) { - opts.paginate = true; - opts.nextPaginationToken = req.query.nextPaginationToken; - } - // Sort criteria - Helpful, Most rated, and Newest reviews // https://github.com/facundoolano/google-play-scraper/blob/89202849f6054f6ac64790a385abc3c18ae98df1/lib/constants.js#L69C7-L69C7 opts.sort = req.query.sort === 'helpful' ? 1 : req.query.sort === 'rated' ? 3 : 2; @@ -259,12 +251,12 @@ router.get('/collections/', async (req, res, next) => { } }); -function anonymizeReplyText(replyText, userName) { +function anonymizeReplyText (replyText, userName) { const userPlaceholder = '<>'; 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 }); @@ -274,4 +266,4 @@ function errorHandler(err, req, res, next) { router.use(errorHandler); -export default router; \ No newline at end of file +export default router; diff --git a/package-lock.json b/package-lock.json index 7326e42..a2372a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "express": "^4.19.2", - "google-play-scraper": "^10.0.0", + "google-play-scraper": "https://github.com/srikanthlogic/google-play-scraper.git#c0bdceca9288165f9af625363c621b901f506390", "morgan": "^1.10.0", "postman-to-openapi": "^3.0.1", "swagger-ui-express": "^5.0.0" @@ -3485,14 +3485,14 @@ }, "node_modules/google-play-scraper": { "version": "10.0.0", - "resolved": "https://registry.npmjs.org/google-play-scraper/-/google-play-scraper-10.0.0.tgz", - "integrity": "sha512-iRVV6HlMYOToPNTA8pub/t8rmr9zhyuaomWIkK1Nck7hwcy8+OX5u7RB7fkf6YtOfBfIlFZ04Yf28Y67vXgNkQ==", + "resolved": "git+ssh://git@github.com/srikanthlogic/google-play-scraper.git#c0bdceca9288165f9af625363c621b901f506390", "dependencies": { "cheerio": "^1.0.0-rc.12", "debug": "^3.1.0", "got": "^11.8.6", "memoizee": "^0.4.14", - "ramda": "^0.29.0" + "ramda": "^0.29.0", + "tough-cookie": "^4.1.3" } }, "node_modules/google-play-scraper/node_modules/debug": { @@ -6711,8 +6711,7 @@ "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", - "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", - "dev": true + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" }, "node_modules/pump": { "version": "3.0.0", @@ -6727,7 +6726,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", - "dev": true, "engines": { "node": ">=6" } @@ -6764,8 +6762,7 @@ "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", - "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", - "dev": true + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" }, "node_modules/queue-microtask": { "version": "1.2.3", @@ -7078,8 +7075,7 @@ "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", - "dev": true + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" }, "node_modules/resolve": { "version": "1.22.8", @@ -7911,6 +7907,20 @@ "node": ">=0.6" } }, + "node_modules/tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "dependencies": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -8159,7 +8169,6 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", - "dev": true, "engines": { "node": ">= 4.0.0" } @@ -8249,7 +8258,6 @@ "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", - "dev": true, "dependencies": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" diff --git a/package.json b/package.json index 5da5460..1a53d0e 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "express": "^4.19.2", - "google-play-scraper": "^10.0.0", + "google-play-scraper": "https://github.com/srikanthlogic/google-play-scraper.git#c0bdceca9288165f9af625363c621b901f506390", "morgan": "^1.10.0", "postman-to-openapi": "^3.0.1", "swagger-ui-express": "^5.0.0"