mirror of
https://github.com/kuaifan/dootask.git
synced 2026-05-31 20:58:29 +00:00
替换 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>
47 lines
1.7 KiB
JavaScript
Vendored
47 lines
1.7 KiB
JavaScript
Vendored
// 仅这些扩展名进入下载索引(排除 .zip:mac 自动更新增量包,非下载按钮目标)
|
||
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 };
|