Skip to content

Commit 3dc8deb

Browse files
committed
apps by search
1 parent e5ddc9e commit 3dc8deb

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/routes.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,7 @@ routes.get('/networks', async (req, res) => {
207207

208208
routes.get('/apps', async (req, res) => {
209209
const {flat} = req.query;
210-
let apps = await AppService.getApps();
211-
if(flat) {
212-
apps = flattenBlockchainObject(apps);
213-
apps = apps.map(app => {
214-
const a = JSON.parse(JSON.stringify(app));
215-
a.url = ReflinkService.withRefLink(a.url, a.applink);
216-
return a;
217-
});
218-
}
219-
220-
returnResult(apps, req, res);
210+
returnResult(flat ? await AppService.getFlatApps() : AppService.getApps(), req, res);
221211
});
222212

223213
routes.get('/apps/featured', async (req, res) => {
@@ -226,9 +216,9 @@ routes.get('/apps/featured', async (req, res) => {
226216

227217
routes.post('/apps', async (req, res) => {
228218
const {apps} = req.body;
229-
let allApps = await AppService.getApps();
219+
let allApps = await AppService.getFlatApps();
230220
if(!apps || !apps.length) return returnResult(allApps, req, res);
231-
const result = flattenBlockchainObject(allApps).filter(x => apps.includes(x.applink));
221+
const result = allApps.filter(x => apps.includes(x.applink));
232222
returnResult(result, req, res);
233223
});
234224

src/services/AppService.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import config from '../util/config'
33
import app from "../app";
44
import {flattenBlockchainObject} from "../util/blockchains";
55
import FeaturedApp from "../models/FeaturedApp";
6+
import ReflinkService from "./ReflinkService";
67

78
// Once every 30 minutes.
89
const intervalTime = 60000 * 30;
@@ -27,6 +28,16 @@ export default class AppService {
2728
return inRam;
2829
}
2930

31+
static async getFlatApps(){
32+
let apps = await AppService.getApps();
33+
apps = flattenBlockchainObject(apps);
34+
return apps.map(app => {
35+
const a = JSON.parse(JSON.stringify(app));
36+
a.url = ReflinkService.withRefLink(a.url, a.applink);
37+
return a;
38+
});
39+
}
40+
3041
static async watch(){
3142
clearInterval(interval);
3243
return new Promise(async resolve => {

0 commit comments

Comments
 (0)