mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
refactor: dedupe github latest release fetch wiring (#1704)
This commit is contained in:
12
api/_github-release.js
Normal file
12
api/_github-release.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const RELEASES_URL = 'https://api.github.com/repos/koala73/worldmonitor/releases/latest';
|
||||
|
||||
export async function fetchLatestRelease(userAgent) {
|
||||
const res = await fetch(RELEASES_URL, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'User-Agent': userAgent,
|
||||
},
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { fetchLatestRelease } from './_github-release.js';
|
||||
|
||||
// Non-sebuf: returns XML/HTML, stays as standalone Vercel function
|
||||
export const config = { runtime: 'edge' };
|
||||
|
||||
const RELEASES_URL = 'https://api.github.com/repos/koala73/worldmonitor/releases/latest';
|
||||
const RELEASES_PAGE = 'https://github.com/koala73/worldmonitor/releases/latest';
|
||||
|
||||
const PLATFORM_PATTERNS = {
|
||||
@@ -48,18 +49,10 @@ export default async function handler(req) {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(RELEASES_URL, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'User-Agent': 'WorldMonitor-Download-Redirect',
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const release = await fetchLatestRelease('WorldMonitor-Download-Redirect');
|
||||
if (!release) {
|
||||
return Response.redirect(RELEASES_PAGE, 302);
|
||||
}
|
||||
|
||||
const release = await res.json();
|
||||
const matcher = PLATFORM_PATTERNS[platform];
|
||||
const assets = Array.isArray(release.assets) ? release.assets : [];
|
||||
const asset = variant
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
import { fetchLatestRelease } from './_github-release.js';
|
||||
|
||||
// Non-sebuf: returns XML/HTML, stays as standalone Vercel function
|
||||
export const config = { runtime: 'edge' };
|
||||
|
||||
const RELEASES_URL = 'https://api.github.com/repos/koala73/worldmonitor/releases/latest';
|
||||
|
||||
export default async function handler() {
|
||||
try {
|
||||
const res = await fetch(RELEASES_URL, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github+json',
|
||||
'User-Agent': 'WorldMonitor-Version-Check',
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const release = await fetchLatestRelease('WorldMonitor-Version-Check');
|
||||
if (!release) {
|
||||
return new Response(JSON.stringify({ error: 'upstream' }), {
|
||||
status: 502,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
const release = await res.json();
|
||||
const tag = release.tag_name ?? '';
|
||||
const version = tag.replace(/^v/, '');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user