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