Files
wrong-notebook/scripts/package/nas-version.mjs
margrop f2f0362a9d fix: 修复 NAS 套件版本号撞车并补齐群晖入口字段
- 群晖正式版补 -9999,严格大于同日预览版序号,避免套件中心拒绝升级
- 威联通 QPKG_VER 改为 YYMMDD.NNN 定长编码,不再截断撞车
- 群晖 INFO 补齐 adminprotocol/adminport/adminurl 打开入口
- 新增 nas-version 单测与 INFO 断言
2026-12-04 08:29:41 +08:00

39 lines
1.7 KiB
JavaScript
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.

/**
* NAS 套件的版本号规则。
*
* 输入是发布版本(可带前导 v),如 2026.10.22、2026.10.22-1。
* - 群晖 INFO 的 version 需满足 [主版本]-[build],build 为整数。预览版的 -n 直接作为 build;
* 正式版补 -9999,严格大于同日任意预览版序号,套件中心才会把正式版视为升级。
* - 威联通 QPKG_VER 最长 10 个字符。用 YYMMDD.序号 的定长格式:预览版序号原样补三位,
* 正式版补 999,避免截断后与 -1 撞车。
*/
const VERSION_PATTERN = /^(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?$/;
function parseVersion(value) {
const version = String(value).replace(/^v/, '');
const match = VERSION_PATTERN.exec(version);
if (!match) throw new Error(`无法识别的版本号:${version}`);
return {
year: match[1],
month: match[2].padStart(2, '0'),
day: match[3].padStart(2, '0'),
preview: match[4] ?? null,
};
}
/** 群晖套件 INFO version:预览版保留 -n,正式版补 -9999 */
export function synologyVersion(value) {
const { year, month, day, preview } = parseVersion(value);
const feature = `${year}.${Number(month)}.${Number(day)}`;
return `${feature}-${preview ?? '9999'}`;
}
/** 威联通 QPKG_VER:YYMMDD.NNN,正式版 NNN=999,预览版 NNN=n,总长 10 字符 */
export function qnapVersion(value) {
const { year, month, day, preview } = parseVersion(value);
const rank = preview === null ? 999 : Number(preview);
if (preview !== null && (rank < 1 || rank > 998)) throw new Error(`预览版序号超出 QPKG 版本范围:${value}`);
return `${year.slice(2)}${month}${day}.${String(rank).padStart(3, '0')}`;
}