版控体系重构(13 文件):
- 移除 build.mjs --personal/--enterprise 参数和 EDITION 环境变量
- 统一安装包文件名:船长-HeiXiu-{os}-{版本号}-Setup.{ext}
- 简化 package.json 构建脚本,移除 :enterprise 变体
- scripts/*.mjs 不再接受 edition 参数
- 移除 shared/constants/app.ts 的 parseEdition()
窗口标题动态版控:
- 新格式:船长-HeiXiu-{os}-{版本号}(登录前)/ ·{版控} 后缀(登录后)
- 链路:AppProvider(account_type) → useEffect → appRuntime IPC → main process
- 移除 updater.ts 更新检查 API 的 edition 查询参数
本地存储生命周期修正:
- 退出登录不再自动清空缓存(user_id 隔离,重新登录命中缓存)
- clearUserStorage 添加 isOpen() 竞态守卫
- 移除 closeDatabase() 避免退出→重新登录后数据库不可用
- 手动「清理缓存」按钮保留
文档:
- CHANGELOG.md 新增 0.0.24 条目
- TODO.md 新增已完成项
248 lines
9.3 KiB
JavaScript
248 lines
9.3 KiB
JavaScript
// ============================================================
|
||
// 上传安装包 + blockmap 文件到阿里云 OSS
|
||
//
|
||
// 用法:
|
||
// node scripts/upload-oss.mjs <platform> [version]
|
||
//
|
||
// 环境变量(使用 Node.js 直传时需要):
|
||
// OSS_ENDPOINT — OSS endpoint(如 oss-cn-hangzhou.aliyuncs.com)
|
||
// OSS_BUCKET — Bucket 名称
|
||
// OSS_ACCESS_KEY_ID — AccessKey ID
|
||
// OSS_ACCESS_KEY_SECRET — AccessKey Secret
|
||
// OSS_BASE_PATH — Bucket 内基路径,默认 releases
|
||
//
|
||
// 不传 OSS 环境变量时 → 打印手动上传命令(ossutil / 控制台)
|
||
//
|
||
// 示例:
|
||
// # 仅打印上传命令
|
||
// node scripts/upload-oss.mjs win32 0.1.0
|
||
//
|
||
// # 直接上传
|
||
// OSS_BUCKET=heixiu OSS_ENDPOINT=oss-cn-hangzhou.aliyuncs.com \
|
||
// OSS_ACCESS_KEY_ID=xxx OSS_ACCESS_KEY_SECRET=xxx \
|
||
// node scripts/upload-oss.mjs win32 0.1.0
|
||
// ============================================================
|
||
|
||
import {readFileSync, readdirSync} from 'node:fs';
|
||
import {join, dirname} from 'node:path';
|
||
import {fileURLToPath} from 'node:url';
|
||
import {createHmac} from 'node:crypto';
|
||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||
const ROOT = join(__dirname, '..');
|
||
|
||
// ---------- 参数 ----------
|
||
|
||
const platform = process.argv[2];
|
||
|
||
if (!platform) {
|
||
console.error('用法: node scripts/upload-oss.mjs <platform> [version]');
|
||
console.error('示例: node scripts/upload-oss.mjs win32 0.1.0');
|
||
process.exit(1);
|
||
}
|
||
|
||
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'));
|
||
const version = process.argv[3] || pkg.version;
|
||
|
||
// ---------- 查找安装包 ----------
|
||
|
||
const releaseDir = join(ROOT, 'release', version);
|
||
|
||
let installerName;
|
||
try {
|
||
const all = readdirSync(releaseDir);
|
||
const exts = platform === 'win32' ? ['.exe'] : platform === 'darwin' ? ['.dmg'] : ['.AppImage'];
|
||
installerName = all.find((f) => exts.some((e) => f.endsWith(e)));
|
||
if (!installerName) {
|
||
console.error(`错误: ${releaseDir} — 未找到安装包`);
|
||
process.exit(1);
|
||
}
|
||
} catch (err) {
|
||
console.error(`错误: ${releaseDir} — ${err.message}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
const installerPath = join(releaseDir, installerName);
|
||
|
||
// ---------- 查找 blockmap 文件 ----------
|
||
|
||
let blockmapName = null;
|
||
let blockmapPath = null;
|
||
try {
|
||
const all = readdirSync(releaseDir);
|
||
blockmapName = all.find((f) => f.endsWith('.blockmap'));
|
||
if (blockmapName) {
|
||
blockmapPath = join(releaseDir, blockmapName);
|
||
}
|
||
} catch {
|
||
// blockmap 不存在不影响主流程
|
||
}
|
||
|
||
// ---------- OSS 配置 ----------
|
||
|
||
const {
|
||
OSS_ENDPOINT,
|
||
OSS_BUCKET,
|
||
OSS_ACCESS_KEY_ID,
|
||
OSS_ACCESS_KEY_SECRET,
|
||
} = process.env;
|
||
|
||
const basePath = (process.env.OSS_BASE_PATH || 'releases').replace(/^\/+|\/+$/g, '');
|
||
const objectKey = `${basePath}/${version}/${installerName}`;
|
||
|
||
// ============================================================
|
||
// 模式 A:无 OSS 配置 → 打印手动命令
|
||
// ============================================================
|
||
|
||
if (!OSS_ENDPOINT || !OSS_BUCKET || !OSS_ACCESS_KEY_ID) {
|
||
const exampleBucket = OSS_BUCKET || '<bucket>';
|
||
const exampleEndpoint = OSS_ENDPOINT || '<endpoint>';
|
||
const downloadUrl = `https://${exampleBucket}.${exampleEndpoint}/${objectKey}`;
|
||
|
||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||
console.log('📦 上传安装包 + blockmap(手动)');
|
||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||
console.log(`文件: ${installerPath}`);
|
||
console.log(`大小: ${(readFileSync(installerPath).length / 1024 / 1024).toFixed(2)} MB\n`);
|
||
|
||
if (blockmapPath) {
|
||
console.log(`Blockmap: ${blockmapPath}`);
|
||
console.log(`Blockmap 大小: ${(readFileSync(blockmapPath).length / 1024).toFixed(2)} KB\n`);
|
||
}
|
||
|
||
console.log('方式 1 — ossutil CLI(推荐):');
|
||
console.log(` ossutil cp "${installerPath}" oss://${exampleBucket}/${objectKey}`);
|
||
if (blockmapPath) {
|
||
const blockmapKey = `${basePath}/${version}/${blockmapName}`;
|
||
console.log(` ossutil cp "${blockmapPath}" oss://${exampleBucket}/${blockmapKey}`);
|
||
}
|
||
console.log('');
|
||
|
||
console.log('方式 2 — 阿里云控制台:');
|
||
console.log(` 登录 OSS 控制台 → ${exampleBucket} → 上传 → 目标路径: ${objectKey}`);
|
||
if (blockmapPath) {
|
||
console.log(` 同时上传 ${blockmapName} 到相同目录`);
|
||
}
|
||
console.log('');
|
||
|
||
const blockmapUrl = blockmapPath
|
||
? `https://${exampleBucket}.${exampleEndpoint}/${basePath}/${version}/${blockmapName}`
|
||
: '';
|
||
|
||
console.log('上传后执行以下命令,用实际 URL 重新生成 info:');
|
||
if (blockmapUrl) {
|
||
console.log(` node scripts/generate-update-info.mjs ${platform} ${version} --url "${downloadUrl}" --blockmap-url "${blockmapUrl}"`);
|
||
console.log('');
|
||
console.log('或直接发布到后端 API:');
|
||
console.log(` node scripts/publish-release.mjs ${platform} ${version} --url "${downloadUrl}" --blockmap-url "${blockmapUrl}"`);
|
||
} else {
|
||
console.log(` node scripts/generate-update-info.mjs ${platform} ${version} --url "${downloadUrl}"`);
|
||
console.log('');
|
||
console.log('或直接发布到后端 API:');
|
||
console.log(` node scripts/publish-release.mjs ${platform} ${version} --url "${downloadUrl}"`);
|
||
}
|
||
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
||
process.exit(0);
|
||
}
|
||
|
||
// ============================================================
|
||
// 模式 B:Node.js 直传 OSS(安装包 + blockmap)
|
||
// ============================================================
|
||
|
||
const fileBuffer = readFileSync(installerPath);
|
||
const contentType = platform === 'win32'
|
||
? 'application/vnd.microsoft.portable-executable'
|
||
: 'application/octet-stream';
|
||
|
||
// 上传安装包
|
||
const date = new Date().toUTCString();
|
||
const stringToSign = [
|
||
'PUT', '', contentType, date, `/${OSS_BUCKET}/${objectKey}`,
|
||
].join('\n');
|
||
const signature = createHmac('sha1', OSS_ACCESS_KEY_SECRET)
|
||
.update(stringToSign)
|
||
.digest('base64');
|
||
const authHeader = `OSS ${OSS_ACCESS_KEY_ID}:${signature}`;
|
||
const downloadUrl = `https://${OSS_BUCKET}.${OSS_ENDPOINT}/${objectKey}`;
|
||
|
||
console.log(`上传中: ${installerName} (${(fileBuffer.length / 1024 / 1024).toFixed(2)} MB)`);
|
||
console.log(`目标: oss://${OSS_BUCKET}/${objectKey}`);
|
||
|
||
try {
|
||
const response = await fetch(downloadUrl, {
|
||
method: 'PUT',
|
||
headers: {
|
||
'Content-Type': contentType,
|
||
'Content-Length': String(fileBuffer.length),
|
||
'Date': date,
|
||
'Authorization': authHeader,
|
||
},
|
||
body: fileBuffer,
|
||
});
|
||
|
||
if (!response.ok) {
|
||
const body = await response.text();
|
||
console.error(`❌ 安装包上传失败 HTTP ${response.status}: ${body}`);
|
||
process.exit(1);
|
||
}
|
||
console.log(`✅ 安装包上传成功`);
|
||
console.log(`下载 URL: ${downloadUrl}`);
|
||
} catch (err) {
|
||
console.error(`❌ 安装包上传失败: ${err.message}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
// 上传 blockmap 文件(如果存在)
|
||
let blockmapUrl = null;
|
||
if (blockmapPath) {
|
||
const blockmapBuffer = readFileSync(blockmapPath);
|
||
const blockmapKey = `${basePath}/${version}/${blockmapName}`;
|
||
blockmapUrl = `https://${OSS_BUCKET}.${OSS_ENDPOINT}/${blockmapKey}`;
|
||
|
||
const bmDate = new Date().toUTCString();
|
||
const bmStringToSign = [
|
||
'PUT', '', 'application/octet-stream', bmDate, `/${OSS_BUCKET}/${blockmapKey}`,
|
||
].join('\n');
|
||
const bmSignature = createHmac('sha1', OSS_ACCESS_KEY_SECRET)
|
||
.update(bmStringToSign)
|
||
.digest('base64');
|
||
|
||
console.log(`\n上传 blockmap: ${blockmapName} (${(blockmapBuffer.length / 1024).toFixed(2)} KB)`);
|
||
|
||
try {
|
||
const bmResponse = await fetch(blockmapUrl, {
|
||
method: 'PUT',
|
||
headers: {
|
||
'Content-Type': 'application/octet-stream',
|
||
'Content-Length': String(blockmapBuffer.length),
|
||
'Date': bmDate,
|
||
'Authorization': `OSS ${OSS_ACCESS_KEY_ID}:${bmSignature}`,
|
||
},
|
||
body: blockmapBuffer,
|
||
});
|
||
|
||
if (bmResponse.ok) {
|
||
console.log(`✅ Blockmap 上传成功`);
|
||
console.log(`Blockmap URL: ${blockmapUrl}`);
|
||
} else {
|
||
console.warn(`⚠️ Blockmap 上传失败(不影响主流程),HTTP ${bmResponse.status}`);
|
||
blockmapUrl = null;
|
||
}
|
||
} catch (err) {
|
||
console.warn(`⚠️ Blockmap 上传失败(不影响主流程): ${err.message}`);
|
||
blockmapUrl = null;
|
||
}
|
||
}
|
||
|
||
// 后续步骤提示
|
||
console.log('\n接下来 — 重新生成 update-info.json:');
|
||
if (blockmapUrl) {
|
||
console.log(` node scripts/generate-update-info.mjs ${platform} ${version} --url "${downloadUrl}" --blockmap-url "${blockmapUrl}"`);
|
||
console.log('\n或直接发布到后端 API:');
|
||
console.log(` node scripts/publish-release.mjs ${platform} ${version} --url "${downloadUrl}" --blockmap-url "${blockmapUrl}"`);
|
||
} else {
|
||
console.log(` node scripts/generate-update-info.mjs ${platform} ${version} --url "${downloadUrl}"`);
|
||
console.log('\n或直接发布到后端 API:');
|
||
console.log(` node scripts/publish-release.mjs ${platform} ${version} --url "${downloadUrl}"`);
|
||
}
|