mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-05-14 00:41:10 +03:00
Fix/fix version check (#278)
This commit is contained in:
3
fe-app-podkop/src/helpers/removeVersionPrefix.ts
Normal file
3
fe-app-podkop/src/helpers/removeVersionPrefix.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function removeVersionPrefix(version: string) {
|
||||||
|
return version.replace(/^v/, '');
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { normalizeCompiledVersion } from '../../../../helpers/normalizeCompiledVersion';
|
||||||
|
import { removeVersionPrefix } from '../../../../helpers/removeVersionPrefix';
|
||||||
|
import type { StoreType } from '../../../services/store.service';
|
||||||
|
import type { IRenderSystemInfoRow } from '../partials';
|
||||||
|
|
||||||
|
function isUnknownVersion(version?: string | null): boolean {
|
||||||
|
return version === 'unknown' || version === _('unknown');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPodkopVersionRow(
|
||||||
|
diagnosticsSystemInfo: StoreType['diagnosticsSystemInfo'],
|
||||||
|
): IRenderSystemInfoRow {
|
||||||
|
const loading = diagnosticsSystemInfo.loading;
|
||||||
|
const unknown = isUnknownVersion(diagnosticsSystemInfo.podkop_version);
|
||||||
|
const hasActualVersion =
|
||||||
|
Boolean(diagnosticsSystemInfo.podkop_latest_version) &&
|
||||||
|
!isUnknownVersion(diagnosticsSystemInfo.podkop_latest_version);
|
||||||
|
const version = normalizeCompiledVersion(
|
||||||
|
diagnosticsSystemInfo.podkop_version,
|
||||||
|
);
|
||||||
|
const isDevVersion = version === 'dev';
|
||||||
|
|
||||||
|
if (loading || unknown || !hasActualVersion || isDevVersion) {
|
||||||
|
return {
|
||||||
|
key: 'Podkop',
|
||||||
|
value: version,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
removeVersionPrefix(version) !==
|
||||||
|
removeVersionPrefix(diagnosticsSystemInfo.podkop_latest_version)
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
key: 'Podkop',
|
||||||
|
value: version,
|
||||||
|
tag: {
|
||||||
|
label: _('Outdated'),
|
||||||
|
kind: 'warning',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: 'Podkop',
|
||||||
|
value: version,
|
||||||
|
tag: {
|
||||||
|
label: _('Latest'),
|
||||||
|
kind: 'success',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import { runFakeIPCheck } from './checks/runFakeIPCheck';
|
|||||||
import { loadingDiagnosticsChecksStore } from './diagnostic.store';
|
import { loadingDiagnosticsChecksStore } from './diagnostic.store';
|
||||||
import { logger, store, StoreType } from '../../services';
|
import { logger, store, StoreType } from '../../services';
|
||||||
import {
|
import {
|
||||||
IRenderSystemInfoRow,
|
|
||||||
renderAvailableActions,
|
renderAvailableActions,
|
||||||
renderCheckSection,
|
renderCheckSection,
|
||||||
renderRunAction,
|
renderRunAction,
|
||||||
@@ -20,6 +19,7 @@ import { PODKOP_LUCI_APP_VERSION } from '../../../constants';
|
|||||||
import { showToast } from '../../../helpers/showToast';
|
import { showToast } from '../../../helpers/showToast';
|
||||||
import { renderWikiDisclaimer } from './partials/renderWikiDisclaimer';
|
import { renderWikiDisclaimer } from './partials/renderWikiDisclaimer';
|
||||||
import { runSectionsCheck } from './checks/runSectionsCheck';
|
import { runSectionsCheck } from './checks/runSectionsCheck';
|
||||||
|
import { getPodkopVersionRow } from './helpers/getPodkopVersionRow';
|
||||||
|
|
||||||
async function fetchSystemInfo() {
|
async function fetchSystemInfo() {
|
||||||
const systemInfo = await PodkopShellMethods.getSystemInfo();
|
const systemInfo = await PodkopShellMethods.getSystemInfo();
|
||||||
@@ -415,53 +415,9 @@ function renderDiagnosticSystemInfoWidget() {
|
|||||||
|
|
||||||
const container = document.getElementById('pdk_diagnostic-page-system-info');
|
const container = document.getElementById('pdk_diagnostic-page-system-info');
|
||||||
|
|
||||||
function getPodkopVersionRow(): IRenderSystemInfoRow {
|
|
||||||
const loading = diagnosticsSystemInfo.loading;
|
|
||||||
const unknown = diagnosticsSystemInfo.podkop_version === _('unknown');
|
|
||||||
const hasActualVersion =
|
|
||||||
Boolean(diagnosticsSystemInfo.podkop_latest_version) &&
|
|
||||||
diagnosticsSystemInfo.podkop_latest_version !== 'unknown';
|
|
||||||
const version = normalizeCompiledVersion(
|
|
||||||
diagnosticsSystemInfo.podkop_version,
|
|
||||||
);
|
|
||||||
const isDevVersion = version === 'dev';
|
|
||||||
|
|
||||||
if (loading || unknown || !hasActualVersion || isDevVersion) {
|
|
||||||
return {
|
|
||||||
key: 'Podkop',
|
|
||||||
value: version,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version !== diagnosticsSystemInfo.podkop_latest_version) {
|
|
||||||
logger.debug(
|
|
||||||
'[DIAGNOSTIC]',
|
|
||||||
'diagnosticsSystemInfo',
|
|
||||||
diagnosticsSystemInfo,
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
key: 'Podkop',
|
|
||||||
value: version,
|
|
||||||
tag: {
|
|
||||||
label: _('Outdated'),
|
|
||||||
kind: 'warning',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
key: 'Podkop',
|
|
||||||
value: version,
|
|
||||||
tag: {
|
|
||||||
label: _('Latest'),
|
|
||||||
kind: 'success',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderedSystemInfo = renderSystemInfo({
|
const renderedSystemInfo = renderSystemInfo({
|
||||||
items: [
|
items: [
|
||||||
getPodkopVersionRow(),
|
getPodkopVersionRow(diagnosticsSystemInfo),
|
||||||
{
|
{
|
||||||
key: 'Luci App',
|
key: 'Luci App',
|
||||||
value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION),
|
value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION),
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { getPodkopVersionRow } from '../helpers/getPodkopVersionRow';
|
||||||
|
import type { StoreType } from '../../../services/store.service';
|
||||||
|
|
||||||
|
function makeDiagnosticsSystemInfo(
|
||||||
|
patch: Partial<StoreType['diagnosticsSystemInfo']> = {},
|
||||||
|
): StoreType['diagnosticsSystemInfo'] {
|
||||||
|
return {
|
||||||
|
loading: false,
|
||||||
|
podkop_version: '1.2.3',
|
||||||
|
podkop_latest_version: '1.2.3',
|
||||||
|
luci_app_version: '1.0.0',
|
||||||
|
sing_box_version: '1.11.0',
|
||||||
|
openwrt_version: 'OpenWrt 25.12',
|
||||||
|
device_model: 'Test Router',
|
||||||
|
...patch,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('getPodkopVersionRow', () => {
|
||||||
|
it('returns Latest when versions differ only by leading v', () => {
|
||||||
|
const row = getPodkopVersionRow(
|
||||||
|
makeDiagnosticsSystemInfo({
|
||||||
|
podkop_version: 'v1.2.3',
|
||||||
|
podkop_latest_version: '1.2.3',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(row).toEqual({
|
||||||
|
key: 'Podkop',
|
||||||
|
value: 'v1.2.3',
|
||||||
|
tag: {
|
||||||
|
label: 'Latest',
|
||||||
|
kind: 'success',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns Outdated when versions differ', () => {
|
||||||
|
const row = getPodkopVersionRow(
|
||||||
|
makeDiagnosticsSystemInfo({
|
||||||
|
podkop_version: '1.2.2',
|
||||||
|
podkop_latest_version: '1.2.3',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(row).toEqual({
|
||||||
|
key: 'Podkop',
|
||||||
|
value: '1.2.2',
|
||||||
|
tag: {
|
||||||
|
label: 'Outdated',
|
||||||
|
kind: 'warning',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns plain row without tag for dev build', () => {
|
||||||
|
const row = getPodkopVersionRow(
|
||||||
|
makeDiagnosticsSystemInfo({
|
||||||
|
podkop_version: 'COMPILED_VERSION',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(row).toEqual({
|
||||||
|
key: 'Podkop',
|
||||||
|
value: 'dev',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -3925,6 +3925,49 @@ async function runSectionsCheck() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// src/helpers/removeVersionPrefix.ts
|
||||||
|
function removeVersionPrefix(version) {
|
||||||
|
return version.replace(/^v/, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// src/podkop/tabs/diagnostic/helpers/getPodkopVersionRow.ts
|
||||||
|
function isUnknownVersion(version) {
|
||||||
|
return version === "unknown" || version === _("unknown");
|
||||||
|
}
|
||||||
|
function getPodkopVersionRow(diagnosticsSystemInfo) {
|
||||||
|
const loading = diagnosticsSystemInfo.loading;
|
||||||
|
const unknown = isUnknownVersion(diagnosticsSystemInfo.podkop_version);
|
||||||
|
const hasActualVersion = Boolean(diagnosticsSystemInfo.podkop_latest_version) && !isUnknownVersion(diagnosticsSystemInfo.podkop_latest_version);
|
||||||
|
const version = normalizeCompiledVersion(
|
||||||
|
diagnosticsSystemInfo.podkop_version
|
||||||
|
);
|
||||||
|
const isDevVersion = version === "dev";
|
||||||
|
if (loading || unknown || !hasActualVersion || isDevVersion) {
|
||||||
|
return {
|
||||||
|
key: "Podkop",
|
||||||
|
value: version
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (removeVersionPrefix(version) !== removeVersionPrefix(diagnosticsSystemInfo.podkop_latest_version)) {
|
||||||
|
return {
|
||||||
|
key: "Podkop",
|
||||||
|
value: version,
|
||||||
|
tag: {
|
||||||
|
label: _("Outdated"),
|
||||||
|
kind: "warning"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
key: "Podkop",
|
||||||
|
value: version,
|
||||||
|
tag: {
|
||||||
|
label: _("Latest"),
|
||||||
|
kind: "success"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// src/podkop/tabs/diagnostic/initController.ts
|
// src/podkop/tabs/diagnostic/initController.ts
|
||||||
async function fetchSystemInfo() {
|
async function fetchSystemInfo() {
|
||||||
const systemInfo = await PodkopShellMethods.getSystemInfo();
|
const systemInfo = await PodkopShellMethods.getSystemInfo();
|
||||||
@@ -4272,47 +4315,9 @@ function renderDiagnosticSystemInfoWidget() {
|
|||||||
logger.debug("[DIAGNOSTIC]", "renderDiagnosticSystemInfoWidget");
|
logger.debug("[DIAGNOSTIC]", "renderDiagnosticSystemInfoWidget");
|
||||||
const diagnosticsSystemInfo = store.get().diagnosticsSystemInfo;
|
const diagnosticsSystemInfo = store.get().diagnosticsSystemInfo;
|
||||||
const container = document.getElementById("pdk_diagnostic-page-system-info");
|
const container = document.getElementById("pdk_diagnostic-page-system-info");
|
||||||
function getPodkopVersionRow() {
|
|
||||||
const loading = diagnosticsSystemInfo.loading;
|
|
||||||
const unknown = diagnosticsSystemInfo.podkop_version === _("unknown");
|
|
||||||
const hasActualVersion = Boolean(diagnosticsSystemInfo.podkop_latest_version) && diagnosticsSystemInfo.podkop_latest_version !== "unknown";
|
|
||||||
const version = normalizeCompiledVersion(
|
|
||||||
diagnosticsSystemInfo.podkop_version
|
|
||||||
);
|
|
||||||
const isDevVersion = version === "dev";
|
|
||||||
if (loading || unknown || !hasActualVersion || isDevVersion) {
|
|
||||||
return {
|
|
||||||
key: "Podkop",
|
|
||||||
value: version
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (version !== diagnosticsSystemInfo.podkop_latest_version) {
|
|
||||||
logger.debug(
|
|
||||||
"[DIAGNOSTIC]",
|
|
||||||
"diagnosticsSystemInfo",
|
|
||||||
diagnosticsSystemInfo
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
key: "Podkop",
|
|
||||||
value: version,
|
|
||||||
tag: {
|
|
||||||
label: _("Outdated"),
|
|
||||||
kind: "warning"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
key: "Podkop",
|
|
||||||
value: version,
|
|
||||||
tag: {
|
|
||||||
label: _("Latest"),
|
|
||||||
kind: "success"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const renderedSystemInfo = renderSystemInfo({
|
const renderedSystemInfo = renderSystemInfo({
|
||||||
items: [
|
items: [
|
||||||
getPodkopVersionRow(),
|
getPodkopVersionRow(diagnosticsSystemInfo),
|
||||||
{
|
{
|
||||||
key: "Luci App",
|
key: "Luci App",
|
||||||
value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION)
|
value: normalizeCompiledVersion(PODKOP_LUCI_APP_VERSION)
|
||||||
|
|||||||
Reference in New Issue
Block a user