Compare commits

...
3 Commits
Author SHA1 Message Date
Илья Глазунов 7e1846276e Update API URL in version fetcher and enhance logging
Deploy to Production / deploy (push) Successful in 5s
2025-12-07 23:10:01 +03:00
Илья Глазунов 769a5e0a43 Fix comment in version fetcher to clarify source as Gitea releases API
Deploy to Production / deploy (push) Successful in 5s
2025-12-07 23:04:10 +03:00
Илья Глазунов 898c7b6a7a Refactor version fetcher to use Gitea API for fetching latest version 2025-12-07 23:03:58 +03:00
2 changed files with 26 additions and 25 deletions
+10
View File
@@ -21,10 +21,20 @@ extensions:
- type: routing - type: routing
config: config:
regex_locations: regex_locations:
"=/api/version":
proxy_pass: "https://git.pyserve.org/api/v1/repos/Shifty/pyserveX/releases/latest"
headers:
- "X-Forwarded-For: $remote_addr"
- "X-Real-IP: $remote_addr"
"~*\\.(css)$": "~*\\.(css)$":
root: "./docs" root: "./docs"
cache_control: "public, max-age=3600" cache_control: "public, max-age=3600"
"~*\\.(js)$":
root: "./docs"
cache_control: "public, max-age=1800"
"__default__": "__default__":
root: "./docs" root: "./docs"
index_file: "index.html" index_file: "index.html"
+14 -23
View File
@@ -1,53 +1,44 @@
/** /**
* Version Fetcher - Automatically fetches and displays latest pyserveX version * Version Fetcher - Automatically fetches and displays latest pyserveX version
* from Gitea releases page * from Gitea releases API.
*/ */
(function() { (function() {
'use strict'; 'use strict';
const RELEASES_URL = 'https://git.pyserve.org/Shifty/pyserveX/releases/latest';
const API_URL = '/api/version';
const VERSION_ELEMENT_ID = 'current-version'; const VERSION_ELEMENT_ID = 'current-version';
const CACHE_KEY = 'pyserve_version_cache'; const CACHE_KEY = 'pyserve_version_cache';
const CACHE_DURATION = 3600000; // 1 hour const CACHE_DURATION = 3600000; // 1 hour
const FALLBACK_VERSION = 'offline'; const FALLBACK_VERSION = '0.9.10';
async function fetchLatestVersion() { async function fetchLatestVersion() {
try { try {
const response = await fetch(RELEASES_URL, { const response = await fetch(API_URL, {
method: 'GET', method: 'GET',
mode: 'cors',
headers: { headers: {
'Accept': 'text/html' 'Accept': 'application/json'
} }
}); });
if (!response.ok) { if (!response.ok) {
console.warn(`Failed to fetch: ${response.status}`); console.warn(`API request failed: ${response.status}`);
return null; return null;
} }
const html = await response.text(); const data = await response.json();
const patterns = [ if (data.tag_name) {
/<title>PyServeX\s+v([\d.]+)/i, const version = data.tag_name.replace(/^v/, '');
/releases\/tag\/v([\d.]+)/, console.log(`✓ Version fetched from API: ${version}`);
/aria-label="PyServeX\s+v([\d.]+)/i, return version;
/<h4[^>]*>.*?v([\d.]+).*?<\/h4>/i
];
for (const pattern of patterns) {
const match = html.match(pattern);
if (match && match[1]) {
console.log(`✓ Version found: ${match[1]}`);
return match[1];
}
} }
console.warn('Version not found in HTML'); console.warn('tag_name not found in API response');
return null; return null;
} catch (error) { } catch (error) {
console.warn('Fetch error:', error.message); console.error('API fetch error:', error.message);
return null; return null;
} }
} }