Browse Source

♻️

master
Tiana Lemesle 9 months ago
parent
commit
d388be720b
2 changed files with 11 additions and 24 deletions
  1. +0
    -18
      gplay.js
  2. +11
    -6
      index.js

+ 0
- 18
gplay.js View File

@ -1,18 +0,0 @@
const GPlay = require('google-play-scraper');
module.exports = {
/*
Google Play search using scraper API
*/
search: async query => {
const res = await GPlay.search({ term: query.name, num: query.number, price: query.price });
for(let i = 0; i < res.length; i++){
Object.assign(res[i], {
index: i,
... (await GPlay.app({ appId: res[i].appId })),
... { permissions: (await GPlay.permissions({ appId: res[i].appId })) }
})
}
return res;
}
};

+ 11
- 6
index.js View File

@ -1,18 +1,23 @@
const
Play = require('./gplay'),
GPlay = require('google-play-scraper'),
Analytics = require('anonymous-analytics');
const fastify = require('fastify')();
const searchAnalytics = new Analytics('search');
/*
Express server
*/
fastify.register(require('fastify-static'), { root: require('path').join(__dirname, 'public') });
fastify.post('/search', (request, reply) => {
fastify.post('/search', async (request, reply) => {
searchAnalytics.addFromFastify(request).catch(console.log);
Play.search(request.body).then(results => reply.send(results));
const res = await GPlay.search({ term: request.body.name, num: request.body.number, price: request.body.price });
for(let i = 0; i < res.length; i++){
Object.assign(res[i], {
index: i,
... (await GPlay.app({ appId: res[i].appId })),
... { permissions: (await GPlay.permissions({ appId: res[i].appId })) }
});
}
reply.send(res);
});
fastify.get('/stats', async (request, reply) => reply.send(await searchAnalytics.getStats(undefined, undefined, true)));
fastify.listen(3030).then(() => console.log('Server running'));

Loading…
Cancel
Save