Files
cnpmcore/app/common/adapter/binary/ElectronBinary.ts
fengmk2 ffe723e65f refactor: use oxlint instead of eslint (#772)
say goodbye to eslint
2025-03-13 23:31:13 +08:00

55 lines
1.5 KiB
TypeScript

import { SingletonProto } from '@eggjs/tegg';
import type { BinaryName } from '../../../../config/binaries.js';
import binaries from '../../../../config/binaries.js';
import { BinaryType } from '../../enum/Binary.js';
import type { BinaryItem, FetchResult } from './AbstractBinary.js';
import { BinaryAdapter } 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 };
}
}