-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathElectronBinary.ts
46 lines (43 loc) · 1.41 KB
/
ElectronBinary.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
import { SingletonProto } from '@eggjs/tegg';
import binaries, { BinaryName } from '../../../../config/binaries.js';
import { BinaryType } from '../../enum/Binary.js';
import { BinaryAdapter, BinaryItem, FetchResult } from './AbstractBinary.js';
import { GithubBinary } from './GithubBinary.js';
@SingletonProto()
@BinaryAdapter(BinaryType.Electron)
export class ElectronBinary extends GithubBinary {
async fetch(dir: string, binaryName: BinaryName = 'electron'): Promise<FetchResult | undefined> {
const releases = await this.initReleases(binaryName, binaries.electron);
if (!releases) return;
let items: BinaryItem[] = [];
if (dir === '/') {
for (const item of releases) {
items.push({
name: `${item.tag_name}/`,
isDir: true,
url: item.url,
size: '-',
date: item.published_at,
});
// v14.2.6 => 14.2.6
if (/^v\d+?\./.test(item.tag_name)) {
items.push({
name: `${item.tag_name.substring(1)}/`,
isDir: true,
url: item.url,
size: '-',
date: item.published_at,
});
}
}
} else {
for (const item of releases) {
if (dir === `/${item.tag_name}/` || dir === `/${item.tag_name.substring(1)}/`) {
items = this.formatItems(item, binaries.electron);
break;
}
}
}
return { items };
}
}