dootask/electron/lib/release-index.js
kuaifan b1d5652bc7 refactor(electron): 发布存储从自建服务迁移到 Cloudflare R2
替换 UPLOAD_TOKEN/UPLOAD_URL 为 R2(S3 兼容)对象存储:
- 新增 r2.js 封装上传/复制/删除/列举等操作
- 新增 release-index.js 从文件名解析平台/架构生成下载索引
- CI 环境变量同步切换为 R2_* 系列

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 10:31:46 +00:00

47 lines
1.7 KiB
JavaScript
Vendored
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 仅这些扩展名进入下载索引(排除 .zipmac 自动更新增量包,非下载按钮目标)
const DOWNLOAD_EXTS = ['.dmg', '.exe', '.msi', '.appimage', '.deb', '.rpm', '.apk', '.pkg'];
/**
* 从文件名解析 platform/arch与官网 storage.ts 规则保持一致)
* @returns {{platform: string, arch: string|null}|null}
*/
function parseFilename(filename) {
const lower = filename.toLowerCase();
if (lower.endsWith('.apk')) {
return { platform: 'android', arch: null };
}
if (!DOWNLOAD_EXTS.some((ext) => lower.endsWith(ext))) {
return null;
}
let platform = null;
if (/-mac-/i.test(filename) || lower.endsWith('.dmg') || lower.endsWith('.pkg')) {
platform = 'mac';
} else if (/-win-/i.test(filename) || /-win\./i.test(filename) || lower.endsWith('.msi')) {
platform = 'win';
} else if (/-linux-/i.test(filename) || lower.endsWith('.appimage') || lower.endsWith('.deb') || lower.endsWith('.rpm')) {
platform = 'linux';
}
if (!platform) return null;
let arch = null;
if (/-arm64[.-]/i.test(filename)) arch = 'arm64';
else if (/-x64[.-]/i.test(filename)) arch = 'x64';
return { platform, arch };
}
/**
* 生成下载索引:{ "<platform>": { "<arch|default>": filename } }
*/
function buildReleaseIndex(filenames) {
const index = {};
for (const filename of filenames) {
const parsed = parseFilename(filename);
if (!parsed) continue;
const archKey = parsed.arch || 'default';
index[parsed.platform] = index[parsed.platform] || {};
index[parsed.platform][archKey] = filename;
}
return index;
}
module.exports = { parseFilename, buildReleaseIndex, DOWNLOAD_EXTS };