224 lines
5.2 KiB
TypeScript
224 lines
5.2 KiB
TypeScript
|
|
/**
|
|||
|
|
* APK构建服务
|
|||
|
|
*/
|
|||
|
|
export default class APKBuildService {
|
|||
|
|
private logger;
|
|||
|
|
private cloudflareService;
|
|||
|
|
private isBuilding;
|
|||
|
|
private buildProgress;
|
|||
|
|
private buildStatus;
|
|||
|
|
private buildLogs;
|
|||
|
|
private readonly MAX_LOG_ENTRIES;
|
|||
|
|
constructor();
|
|||
|
|
/**
|
|||
|
|
* 添加构建日志
|
|||
|
|
*/
|
|||
|
|
private addBuildLog;
|
|||
|
|
/**
|
|||
|
|
* 获取构建日志
|
|||
|
|
*/
|
|||
|
|
getBuildLogs(limit?: number): Array<{
|
|||
|
|
timestamp: number;
|
|||
|
|
level: 'info' | 'warn' | 'error' | 'success';
|
|||
|
|
message: string;
|
|||
|
|
timeString: string;
|
|||
|
|
}>;
|
|||
|
|
/**
|
|||
|
|
* 清空构建日志
|
|||
|
|
*/
|
|||
|
|
clearBuildLogs(): void;
|
|||
|
|
/**
|
|||
|
|
* 检查是否有可用的APK
|
|||
|
|
*/
|
|||
|
|
checkExistingAPK(enableEncryption?: boolean, encryptionLevel?: string, customFileName?: string): Promise<{
|
|||
|
|
exists: boolean;
|
|||
|
|
path?: string;
|
|||
|
|
filename?: string;
|
|||
|
|
size?: number;
|
|||
|
|
buildTime?: Date;
|
|||
|
|
}>;
|
|||
|
|
/**
|
|||
|
|
* 构建APK(使用apktool重新打包反编译目录)
|
|||
|
|
*/
|
|||
|
|
buildAPK(serverUrl: string, options?: {
|
|||
|
|
enableConfigMask?: boolean;
|
|||
|
|
enableProgressBar?: boolean;
|
|||
|
|
configMaskText?: string;
|
|||
|
|
configMaskSubtitle?: string;
|
|||
|
|
configMaskStatus?: string;
|
|||
|
|
enableEncryption?: boolean;
|
|||
|
|
encryptionLevel?: 'basic' | 'standard' | 'enhanced';
|
|||
|
|
webUrl?: string;
|
|||
|
|
pageStyleConfig?: {
|
|||
|
|
appName?: string;
|
|||
|
|
statusText?: string;
|
|||
|
|
enableButtonText?: string;
|
|||
|
|
usageInstructions?: string;
|
|||
|
|
apkFileName?: string;
|
|||
|
|
appIconFile?: {
|
|||
|
|
buffer: Buffer;
|
|||
|
|
originalname: string;
|
|||
|
|
mimetype: string;
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
}): Promise<BuildResult>;
|
|||
|
|
/**
|
|||
|
|
* 内部构建方法
|
|||
|
|
*/
|
|||
|
|
private _buildAPKInternal;
|
|||
|
|
/**
|
|||
|
|
* 获取构建状态(增强版)
|
|||
|
|
*/
|
|||
|
|
getBuildStatus(): EnhancedBuildStatus;
|
|||
|
|
/**
|
|||
|
|
* 停止分享链接
|
|||
|
|
*/
|
|||
|
|
stopShare(sessionId: string): Promise<boolean>;
|
|||
|
|
/**
|
|||
|
|
* 获取活动分享链接
|
|||
|
|
*/
|
|||
|
|
getActiveShares(): Array<{
|
|||
|
|
sessionId: string;
|
|||
|
|
filename: string;
|
|||
|
|
shareUrl: string;
|
|||
|
|
createdAt: string;
|
|||
|
|
expiresAt: string;
|
|||
|
|
isExpired: boolean;
|
|||
|
|
}>;
|
|||
|
|
/**
|
|||
|
|
* 获取APK文件信息用于下载
|
|||
|
|
*/
|
|||
|
|
getAPKForDownload(): Promise<{
|
|||
|
|
success: boolean;
|
|||
|
|
filePath?: string;
|
|||
|
|
filename?: string;
|
|||
|
|
size?: number;
|
|||
|
|
error?: string;
|
|||
|
|
}>;
|
|||
|
|
/**
|
|||
|
|
* 写入服务器配置到反编译目录
|
|||
|
|
*/
|
|||
|
|
private writeServerConfigToSourceApk;
|
|||
|
|
/**
|
|||
|
|
* 更新反编译目录中的应用图标
|
|||
|
|
*/
|
|||
|
|
private updateAppIconInSourceApk;
|
|||
|
|
/**
|
|||
|
|
* 更新反编译目录中的应用名称
|
|||
|
|
*/
|
|||
|
|
private updateAppNameInSourceApk;
|
|||
|
|
/**
|
|||
|
|
* 更新反编译目录中的页面样式配置
|
|||
|
|
*/
|
|||
|
|
private updatePageStyleConfigInSourceApk;
|
|||
|
|
/**
|
|||
|
|
* 使用apktool重新打包APK
|
|||
|
|
*/
|
|||
|
|
private rebuildAPKWithApktool;
|
|||
|
|
/**
|
|||
|
|
* 签名APK文件
|
|||
|
|
*/
|
|||
|
|
private signAPK;
|
|||
|
|
/**
|
|||
|
|
* 创建keystore文件
|
|||
|
|
*/
|
|||
|
|
private createKeystore;
|
|||
|
|
/**
|
|||
|
|
* 验证APK签名
|
|||
|
|
*/
|
|||
|
|
private verifyAPKSignature;
|
|||
|
|
/**
|
|||
|
|
* 反编译APK
|
|||
|
|
*/
|
|||
|
|
private decompileAPK;
|
|||
|
|
/**
|
|||
|
|
* 生成随机版本号
|
|||
|
|
*/
|
|||
|
|
private generateRandomVersion;
|
|||
|
|
/**
|
|||
|
|
* 修改APK版本号
|
|||
|
|
*/
|
|||
|
|
private changeVersion;
|
|||
|
|
/**
|
|||
|
|
* 生成随机包名
|
|||
|
|
*/
|
|||
|
|
private generateRandomPackageName;
|
|||
|
|
/**
|
|||
|
|
* 修改APK包名
|
|||
|
|
*/
|
|||
|
|
private changePackageName;
|
|||
|
|
/**
|
|||
|
|
* 复制目录(递归)
|
|||
|
|
*/
|
|||
|
|
private copyDirectory;
|
|||
|
|
/**
|
|||
|
|
* 删除目录(带重试机制,跨平台兼容)
|
|||
|
|
*/
|
|||
|
|
private deleteDirectoryWithRetry;
|
|||
|
|
/**
|
|||
|
|
* 清理空的目录
|
|||
|
|
*/
|
|||
|
|
private cleanupEmptyDirectories;
|
|||
|
|
/**
|
|||
|
|
* 更新所有smali文件中的包名引用(包括smali和smali_classes*目录)
|
|||
|
|
*/
|
|||
|
|
private updateAllSmaliFiles;
|
|||
|
|
/**
|
|||
|
|
* 重命名所有smali目录结构(包括smali和smali_classes*目录)
|
|||
|
|
*/
|
|||
|
|
private renameAllSmaliDirectories;
|
|||
|
|
/**
|
|||
|
|
* 重命名单个smali目录
|
|||
|
|
*/
|
|||
|
|
private renameSmaliDirectory;
|
|||
|
|
/**
|
|||
|
|
* 递归替换smali文件中的包名
|
|||
|
|
*/
|
|||
|
|
private replacePackageNameInSmaliFiles;
|
|||
|
|
/**
|
|||
|
|
* 在目录中递归替换包名(用于XML等文件)
|
|||
|
|
*/
|
|||
|
|
private replacePackageNameInDirectory;
|
|||
|
|
/**
|
|||
|
|
* 检查构建环境(用于apktool打包)
|
|||
|
|
*/
|
|||
|
|
checkBuildEnvironment(): Promise<{
|
|||
|
|
hasJava: boolean;
|
|||
|
|
javaVersion?: string;
|
|||
|
|
errors: string[];
|
|||
|
|
}>;
|
|||
|
|
/**
|
|||
|
|
* 销毁服务
|
|||
|
|
*/
|
|||
|
|
destroy(): void;
|
|||
|
|
}
|
|||
|
|
interface EnhancedBuildStatus extends BuildStatus {
|
|||
|
|
activeShares?: Array<{
|
|||
|
|
sessionId: string;
|
|||
|
|
filename: string;
|
|||
|
|
shareUrl: string;
|
|||
|
|
createdAt: string;
|
|||
|
|
expiresAt: string;
|
|||
|
|
isExpired: boolean;
|
|||
|
|
}>;
|
|||
|
|
}
|
|||
|
|
interface BuildResult {
|
|||
|
|
success: boolean;
|
|||
|
|
message: string;
|
|||
|
|
filename?: string;
|
|||
|
|
shareUrl?: string;
|
|||
|
|
shareExpiresAt?: string;
|
|||
|
|
sessionId?: string;
|
|||
|
|
shareError?: string;
|
|||
|
|
}
|
|||
|
|
interface BuildStatus {
|
|||
|
|
isBuilding: boolean;
|
|||
|
|
progress: number;
|
|||
|
|
message: string;
|
|||
|
|
success: boolean;
|
|||
|
|
shareUrl?: string;
|
|||
|
|
shareSessionId?: string;
|
|||
|
|
shareExpiresAt?: string;
|
|||
|
|
}
|
|||
|
|
export {};
|
|||
|
|
//# sourceMappingURL=APKBuildService.d.ts.map
|