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 pathtukui.js
148 lines (129 loc) · 3.58 KB
/
tukui.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const _ = require('underscore')
const cfg = require('../lib/config')
const g = require('got')
const log = console.log
let api = {
$url: 'https://www.tukui.org',
$base: 'https://www.tukui.org/download.php',
$lcl: /\?id=(.*)$/,
$fcl: 'tukui',
$scl: 'tukui.com',
cfv: cfg.getClassicExp() === '[TBC]' ? 'classic-tbc-addons' : 'classic-addons',
info(ad, done) {
let id = ad.key.split('-')[0]
let mo = cfg.getMode()
let top = require('./')
if (mo === '_retail_' && ad.key.match(/0-.tukui|0-.elvui/i)) {
g(`${api.$base}?ui=${ad.key.match(/0-.tukui/i) ? 'tukui' : 'elvui'}`)
.then(res => {
let i = {
name: ad.key,
author: 'tukui.org',
download: 1000000,
version: [{}]
}
res.body
.replace(/\r/g, '')
.split('\n')
.forEach(line => {
if (line.match(/current version/i)) {
let d = line.replace(/</g, '>').split('>')
i.update = new Date(d[6]) / 1000
i.version[0].name = d[2]
}
if (line.match(/btn-mod/i)) {
i.version[0].link = api.$url + line.split('"')[1]
}
})
done(i)
})
.catch(x => done())
return
}
top.getDB('tukui', db => {
if (!db) return done()
let x = _.find(db, d => ad.key === d.key)
if (!x) return done()
done({
name: x.name,
author: x.author,
update: x.update,
download: x.download,
version: [{
name: x.version,
game: x.game,
link: `${api.$url}/${mo === '_retail_'
? 'addons' : api.cfv}.php?download=${x.id}`
}]
})
})
},
summary(done) {
// inject the base UI
let r = [
{
id: 0,
name: 'TukUI',
downloads: 1000000,
lastupdate: new Date().toDateString(),
small_desc: 'TukUI',
},
{
id: 0,
name: 'ElvUI',
downloads: 1000000,
lastupdate: new Date().toDateString(),
small_desc: 'ElvUI',
}
]
// get retail addon list
g(`${api.$url}/api.php?addons`).then(res => {
r = r.concat(JSON.parse(res.body))
r.forEach(x => x.mode = 1)
// get classic addon list
g(`${api.$url}/api.php?${api.cfv}`).then(res => {
r = r.concat(JSON.parse(res.body).map(x => {
x.mode = 2
return x
}))
done(r.map(x => {
return {
id: x.id,
name: x.name,
key: x.id + '-' + x.mode + x.name.replace(/[^a-zA-Z0-9]/g, ''),
mode: x.mode,
version: x.version,
update: new Date(x.lastupdate).valueOf() / 1000,
author: x.author,
download: x.downloads,
small_desc: x.small_desc,
source: 'tukui'
}
}))
})
}).catch(err => {
log('tukui summary failed', err)
done([])
})
},
search(ad, done) {
let mo = cfg.getMode() === '_retail_' ? 1 : 2
let top = require('./')
top.getDB('tukui', db => {
let res = _.filter(db, x => x.mode === mo && (
x.name.toLowerCase().search(ad.key.toLowerCase()) >= 0 ||
x.small_desc.toLowerCase().search(ad.key.toLowerCase()) >= 0
))
res.sort((a, b) => b.downloads - a.downloads)
res = res.slice(0, 15)
done(
res.map(x => {
x.page = `${api.$url}/${mo === 1
? 'addons' : api.cfv}.php?id=${x.id}`
return x
})
)
})
}
}
module.exports = api