Skip to content

Commit b1c57dc

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

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/routes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ routes.post('/apps', async (req, res) => {
222222
returnResult(result, req, res);
223223
});
224224

225+
routes.get('/app/:applink', async (req, res) => {
226+
const {applink} = req.params;
227+
returnResult(await AppService.findApp(applink), req, res);
228+
});
229+
225230

226231

227232

src/services/AppService.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,52 @@ export default class AppService {
3838
});
3939
}
4040

41+
static async findApp(origin){
42+
const emptyResult = {
43+
applink:origin,
44+
type:'',
45+
name:origin,
46+
description:'',
47+
logo:'',
48+
url:'',
49+
};
50+
51+
const dappData = await AppService.getFlatApps();
52+
let found = dappData[origin];
53+
54+
if(!found){
55+
(() => {
56+
// Checking subdomains
57+
if(origin.split('.').length < 2) return;
58+
const [subdomain, domain, suffix] = origin.split('.');
59+
Object.keys(dappData).map(applink => {
60+
if(origin.indexOf(applink) === -1) return;
61+
const dapp = dappData[applink];
62+
if(!dapp.hasOwnProperty('subdomains') || !dapp.subdomains.length) return;
63+
// Checking wildcards
64+
if(dapp.subdomains.find(x => x === '*')){
65+
if(`*.${applink}` === `*.${domain}.${suffix}`) return found = dapp;
66+
}
67+
// Checking hardcoded domains
68+
else {
69+
dapp.subdomains.map(sub => {
70+
if(`${sub}.${applink}` === origin) return found = dapp;
71+
})
72+
}
73+
})
74+
})();
75+
}
76+
77+
if(!found) return emptyResult;
78+
79+
const maxDescriptionLength = 70;
80+
if(found.description.length > maxDescriptionLength){
81+
found.description = `${found.description.substr(0,70)}${found.description.length > 70 ? '...':''}`
82+
}
83+
84+
return found;
85+
}
86+
4187
static async watch(){
4288
clearInterval(interval);
4389
return new Promise(async resolve => {

0 commit comments

Comments
 (0)