Files
web2app/worker/src/services/version.ts
shumengya b69dfc4813 feat: migrate to Cloudflare Workers with icon and version upload
Replace Express/SQLite and web/ with frontend/, worker/, and wrangler deploy. Add optional app icon upload, date-based app_version, and build-app workflow input.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 13:30:16 +08:00

26 lines
849 B
TypeScript
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.
export class VersionValidationError extends Error {
constructor(message: string) {
super(message);
this.name = "VersionValidationError";
}
}
/** 当前日期版本,格式如 2026.5.29(月、日不补零) */
export function getDefaultAppVersion(date = new Date()): string {
return `${date.getFullYear()}.${date.getMonth() + 1}.${date.getDate()}`;
}
export function validateAppVersion(input: string): string {
const value = input.trim() || getDefaultAppVersion();
if (!/^\d{4}\.\d{1,2}\.\d{1,2}$/.test(value)) {
throw new VersionValidationError(
"版本号格式应为 YYYY.M.D例如 2026.5.29",
);
}
const [, month, day] = value.split(".").map(Number);
if (month < 1 || month > 12 || day < 1 || day > 31) {
throw new VersionValidationError("版本号中的月或日无效");
}
return value;
}