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