This commit enhances type safety and fixes type-related issues throughout the project including: - Updated type definitions in entities, repositories, and models - Improved type annotations in services and controllers - Fixed type issues in adapters and utilities - Enhanced test file type definitions - Added typings/index.d.ts for global type declarations 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
110 lines
3.4 KiB
TypeScript
110 lines
3.4 KiB
TypeScript
import { SingletonProto } from '@eggjs/tegg';
|
|
import binaries, { type BinaryName } from '../../../../config/binaries.ts';
|
|
import { BinaryType } from '../../enum/Binary.ts';
|
|
import {
|
|
AbstractBinary,
|
|
BinaryAdapter,
|
|
type BinaryItem,
|
|
type FetchResult,
|
|
} from './AbstractBinary.ts';
|
|
|
|
@SingletonProto()
|
|
@BinaryAdapter(BinaryType.Imagemin)
|
|
export class ImageminBinary extends AbstractBinary {
|
|
async initFetch() {
|
|
// do nothing
|
|
return;
|
|
}
|
|
|
|
async fetch(
|
|
dir: string,
|
|
binaryName: BinaryName
|
|
): Promise<FetchResult | undefined> {
|
|
const binaryConfig = binaries[binaryName];
|
|
const dirItems: {
|
|
[key: string]: BinaryItem[];
|
|
} = {};
|
|
const npmPackageName = binaryConfig.options?.npmPackageName ?? binaryName;
|
|
const pkgUrl = `https://registry.npmjs.com/${npmPackageName}`;
|
|
const data = await this.requestJSON(pkgUrl);
|
|
dirItems['/'] = [];
|
|
// mini version 4.0.0
|
|
// https://github.com/imagemin/jpegtran-bin/blob/v4.0.0/lib/index.js
|
|
// https://github.com/imagemin/pngquant-bin/blob/v4.0.0/lib/index.js
|
|
for (const version in data.versions) {
|
|
const major = Number.parseInt(version.split('.', 1)[0]);
|
|
if (major < 4) continue;
|
|
// >= 4.0.0
|
|
const date = data.time[version];
|
|
// https://raw.githubusercontent.com/imagemin/jpegtran-bin/v${pkg.version}/vendor/`
|
|
dirItems['/'].push({
|
|
name: `v${version}/`,
|
|
date,
|
|
size: '-',
|
|
isDir: true,
|
|
url: '',
|
|
});
|
|
const versionDir = `/v${version}/`;
|
|
dirItems[versionDir] = [];
|
|
dirItems[versionDir].push({
|
|
name: 'vendor/',
|
|
date,
|
|
size: '-',
|
|
isDir: true,
|
|
url: '',
|
|
});
|
|
const versionVendorDir = `/v${version}/vendor/`;
|
|
dirItems[versionVendorDir] = [];
|
|
for (const platform of binaryConfig.options?.nodePlatforms ?? []) {
|
|
dirItems[versionVendorDir].push({
|
|
name: `${platform}/`,
|
|
date,
|
|
size: '-',
|
|
isDir: true,
|
|
url: '',
|
|
});
|
|
const platformDir = `/v${version}/vendor/${platform}/`;
|
|
dirItems[platformDir] = [];
|
|
const archs = binaryConfig.options?.nodeArchs?.[platform] ?? [];
|
|
if (archs.length === 0) {
|
|
for (const name of binaryConfig.options?.binFiles?.[platform] ?? []) {
|
|
dirItems[platformDir].push({
|
|
name,
|
|
date,
|
|
size: '-',
|
|
isDir: false,
|
|
url: `${binaryConfig.distUrl}/${binaryConfig.repo}${platformDir}${name}`,
|
|
ignoreDownloadStatuses: [404],
|
|
});
|
|
}
|
|
} else {
|
|
for (const arch of archs) {
|
|
dirItems[platformDir].push({
|
|
name: `${arch}/`,
|
|
date,
|
|
size: '-',
|
|
isDir: true,
|
|
url: '',
|
|
});
|
|
const platformArchDir = `/v${version}/vendor/${platform}/${arch}/`;
|
|
dirItems[platformArchDir] = [];
|
|
|
|
for (const name of binaryConfig.options?.binFiles?.[platform] ??
|
|
[]) {
|
|
dirItems[platformArchDir].push({
|
|
name,
|
|
date,
|
|
size: '-',
|
|
isDir: false,
|
|
url: `${binaryConfig.distUrl}/${binaryConfig.repo}${platformArchDir}${name}`,
|
|
ignoreDownloadStatuses: [404],
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return { items: dirItems[dir] };
|
|
}
|
|
}
|