-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
61 lines (52 loc) · 1.63 KB
/
app.ts
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
// Bind environment variables from .env to process.env
require('dotenv').config();
import Auth from './classes/Auth';
import Downloader from './classes/Downloader';
import Api from './classes/Api';
import Osu from './classes/Osu';
import Config from './classes/Config';
import Setup from './classes/Setup';
function getBeatmapIds() {
const api = new Api();
const osu = new Osu();
const config = new Config();
return Promise.all([
api.getNewBeatmapIds(),
osu.getInstalledBeatmapIds(),
config.getFailedBeatmapIds()
])
.then(results => filterIds(results));
}
function initDownloader(): Promise<Downloader> {
const auth = new Auth();
return new Promise((resolve, reject) => {
auth.login()
.then(() =>
resolve(new Downloader(auth)))
.catch(reject);
});
}
function filterIds([newBeatmapIds, installedBeatmapIds, failedBeatmapIds]: [string[], string[], string[]]) {
return Promise.resolve(
newBeatmapIds.filter(beatmapId =>
installedBeatmapIds.indexOf(beatmapId) < 0
&& failedBeatmapIds.indexOf(beatmapId) < 0));
}
function init() {
const setup = new Setup();
setup.checkRequiredFiles()
.then(() => Promise.all([
initDownloader(),
getBeatmapIds(),
]))
.then(([downloader, beatmapIds]) => {
if (beatmapIds.length > 0) {
return downloader.get(beatmapIds);
} else {
return Promise.resolve('No beatmaps to download');
}
})
.then(console.info)
.catch(console.error);
}
init();