mirror of
https://github.com/9technologygroup/patchmon.net.git
synced 2025-11-05 06:23:22 +00:00
Fix hardcoded 1.2.4 values - make frontend load current version from API on mount and update User-Agent dynamically
This commit is contained in:
@@ -202,11 +202,22 @@ class UpdateScheduler {
|
|||||||
try {
|
try {
|
||||||
const httpsRepoUrl = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
const httpsRepoUrl = `https://api.github.com/repos/${owner}/${repo}/releases/latest`;
|
||||||
|
|
||||||
|
// Get current version for User-Agent
|
||||||
|
let currentVersion = '1.2.5'; // fallback
|
||||||
|
try {
|
||||||
|
const packageJson = require('../../package.json');
|
||||||
|
if (packageJson && packageJson.version) {
|
||||||
|
currentVersion = packageJson.version;
|
||||||
|
}
|
||||||
|
} catch (packageError) {
|
||||||
|
console.warn('Could not read version from package.json for User-Agent, using fallback:', packageError.message);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(httpsRepoUrl, {
|
const response = await fetch(httpsRepoUrl, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Accept': 'application/vnd.github.v3+json',
|
'Accept': 'application/vnd.github.v3+json',
|
||||||
'User-Agent': 'PatchMon-Server/1.2.4'
|
'User-Agent': `PatchMon-Server/${currentVersion}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const Settings = () => {
|
|||||||
|
|
||||||
// Version checking state
|
// Version checking state
|
||||||
const [versionInfo, setVersionInfo] = useState({
|
const [versionInfo, setVersionInfo] = useState({
|
||||||
currentVersion: '1.2.4',
|
currentVersion: null, // Will be loaded from API
|
||||||
latestVersion: null,
|
latestVersion: null,
|
||||||
isUpdateAvailable: false,
|
isUpdateAvailable: false,
|
||||||
checking: false,
|
checking: false,
|
||||||
@@ -153,6 +153,24 @@ const Settings = () => {
|
|||||||
console.log('Agent versions error:', agentVersionsError);
|
console.log('Agent versions error:', agentVersionsError);
|
||||||
}, [agentVersions, agentVersionsLoading, agentVersionsError]);
|
}, [agentVersions, agentVersionsLoading, agentVersionsError]);
|
||||||
|
|
||||||
|
// Load current version on component mount
|
||||||
|
useEffect(() => {
|
||||||
|
const loadCurrentVersion = async () => {
|
||||||
|
try {
|
||||||
|
const response = await versionAPI.getCurrent();
|
||||||
|
const data = response.data;
|
||||||
|
setVersionInfo(prev => ({
|
||||||
|
...prev,
|
||||||
|
currentVersion: data.version
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading current version:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadCurrentVersion();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const createAgentVersionMutation = useMutation({
|
const createAgentVersionMutation = useMutation({
|
||||||
mutationFn: (data) => agentVersionAPI.create(data).then(res => res.data),
|
mutationFn: (data) => agentVersionAPI.create(data).then(res => res.data),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user