버전 관리 시스템 최종 안정화: 비교 로직 강화 및 히스토리 필터링 정상화
This commit is contained in:
parent
3ba4139eb6
commit
c91a286ffe
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "smartims",
|
||||
"private": true,
|
||||
"version": "0.4.0",
|
||||
"version": "0.3.5",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "server",
|
||||
"version": "0.4.0",
|
||||
"version": "0.3.5",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@ -467,7 +467,7 @@ router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res
|
||||
try {
|
||||
const packageJsonPath = path.join(__dirname, '../package.json');
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
const currentVersion = packageJson.version;
|
||||
const currentVersion = packageJson.version.replace(/^v/, '');
|
||||
|
||||
// Prepare git fetch command with auth if available
|
||||
const auth = await getGiteaAuth();
|
||||
@ -530,30 +530,30 @@ router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res
|
||||
};
|
||||
}).filter(Boolean);
|
||||
|
||||
// Version Comparison Helper
|
||||
const compareVersions = (v1, v2) => {
|
||||
const parts1 = v1.split('.').map(Number);
|
||||
const parts2 = v2.split('.').map(Number);
|
||||
const parseV = (v) => (v || '').replace(/^v/, '').split('.').map(n => parseInt(n) || 0);
|
||||
const compare = (v1, v2) => {
|
||||
const p1 = parseV(v1);
|
||||
const p2 = parseV(v2);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (parts1[i] > parts2[i]) return 1;
|
||||
if (parts1[i] < parts2[i]) return -1;
|
||||
const n1 = p1[i] || 0;
|
||||
const n2 = p2[i] || 0;
|
||||
if (n1 > n2) return 1;
|
||||
if (n1 < n2) return -1;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
// Filter 1: History is ONLY versions <= current
|
||||
const history = allTags.filter(t => compareVersions(t.version, currentVersion) <= 0);
|
||||
|
||||
// Filter 2: Latest is the absolute newest tag available (could be > current)
|
||||
const history = allTags.filter(t => compare(t.version, currentVersion) <= 0);
|
||||
const latestFromRemote = allTags[0] || null;
|
||||
const needsUpdate = latestFromRemote ? (compareVersions(latestFromRemote.version, currentVersion) > 0) : false;
|
||||
const needsUpdate = latestFromRemote ? (compare(latestFromRemote.version, currentVersion) > 0) : false;
|
||||
|
||||
res.json({
|
||||
current: currentVersion,
|
||||
latest: latestFromRemote ? `v${latestFromRemote.version}` : null,
|
||||
needsUpdate: needsUpdate,
|
||||
latestInfo: needsUpdate ? latestFromRemote : null,
|
||||
history: history
|
||||
history: history,
|
||||
debug: { path: packageJsonPath }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -114,7 +114,7 @@ export function VersionPage() {
|
||||
const buildDate = '2026-01-25';
|
||||
|
||||
// Check if update is needed based on API-supplied needsUpdate flag
|
||||
const needsUpdate = remoteInfo?.needsUpdate || false;
|
||||
const needsUpdate = !!remoteInfo?.needsUpdate;
|
||||
|
||||
return (
|
||||
<div className="page-container p-6 max-w-4xl mx-auto">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user