UNPKG

2.53 kBJavaScriptView Raw
1const _ = require('underscore')
2const g = require('got')
3const cfg = require('../lib/config')
4const log = console.log
5
6let api = {
7 $url: 'https://api.mmoui.com/v3/game/WOW',
8 $web: 'https://wowinterface.com',
9
10 $lcl: /\/info(.*)\.html/,
11 $scl: 'wowinterface.com##mmoui.com',
12
13 info(ad, done) {
14 let id = ad.key.split('-')[0]
15
16 // log('getting', `${api.$url}/filedetails/${id}.json`)
17 g(`${api.$url}/filedetails/${id}.json`)
18 .then(res => {
19 let x = JSON.parse(res.body)[0]
20
21 ad.key = id + '-' + x.UIName.replace(/[^a-zA-Z0-9]/g, '')
22
23 done({
24 name: x.UIName,
25 author: x.UIAuthorName,
26 update: x.UIDate / 1000,
27 download: x.UIHitCount,
28 version: [{ link: x.UIDownload, name: x.UIVersion }]
29 })
30 })
31 .catch(x => done())
32 },
33
34 summary(done) {
35 g(`${api.$url}/filelist.json`)
36 .then(res => {
37 let r = JSON.parse(res.body)
38
39 // log(r[0])
40 done(
41 r.map(x => {
42 return {
43 id: x.UID,
44 name: x.UIName,
45 key: x.UID + '-' + x.UIName.replace(/[^a-zA-Z0-9]/g, ''),
46 mode: x.UICATID === '160' ? '_classic_' : '_retail_',
47 cat: x.UICATID,
48 version: x.UIVersion,
49 update: x.UIDate / 1000,
50 author: x.UIAuthorName,
51 download: x.UIDownloadTotal,
52 game: x.UICompatibility
53 ? _.uniq(x.UICompatibility.map(c => c.version))
54 : null,
55 dir: x.UIDir,
56 source: 'mmoui'
57 }
58 })
59 )
60 })
61 .catch(err => {
62 log('mmoui summary failed', err)
63 })
64 },
65
66 search(ad, done) {
67 let mo = cfg.getMode()
68
69 let top = require('./index')
70 top.getDB('mmoui', db => {
71 if (!db) return done()
72
73 if (!ad.anyway) db = _.filter(db, d => mo === d.mode)
74
75 // log(mo)
76
77 let res = _.filter(
78 db,
79 d =>
80 d.name.toLowerCase().search(ad.key.toLowerCase()) >= 0 ||
81 d.dir[0].toLowerCase().search(ad.key.toLowerCase()) >= 0
82 )
83
84 res.sort((a, b) => b.download - a.download)
85 res = res.slice(0, 15)
86
87 // log(res)
88 done(
89 res.map(x => {
90 return {
91 name: x.name,
92 key: x.key,
93 download: parseInt(x.download),
94 update: x.update,
95 page: `${api.$web}/downloads/info${x.key}.html`
96 }
97 })
98 )
99 })
100 }
101}
102
103module.exports = api