Add webapp release
Some checks failed
Queue Release Build / prepare (push) Successful in 50s
Queue Release Build / build-windows (push) Has been cancelled
Queue Release Build / finalize (push) Has been cancelled
Queue Release Build / build-linux (push) Has been cancelled
Deploy Web Apps / deploy (push) Has been cancelled
Some checks failed
Queue Release Build / prepare (push) Successful in 50s
Queue Release Build / build-windows (push) Has been cancelled
Queue Release Build / finalize (push) Has been cancelled
Queue Release Build / build-linux (push) Has been cancelled
Deploy Web Apps / deploy (push) Has been cancelled
This commit is contained in:
@@ -55,6 +55,8 @@ const ARCHIVE_SUFFIXES = [
|
||||
'.7z',
|
||||
'.rar'
|
||||
];
|
||||
const DIRECT_RELEASES_API_URL = 'https://git.azaaxin.com/api/v1/repos/myxelium/Toju/releases';
|
||||
const PROXY_RELEASES_API_URL = '/api/releases';
|
||||
|
||||
function matchesAssetPattern(name: string, suffixes: string[], hints: string[] = []): boolean {
|
||||
if (suffixes.some((suffix) => name.endsWith(suffix))) {
|
||||
@@ -205,15 +207,7 @@ export class ReleaseService {
|
||||
|
||||
private async fetchReleasesInternal(): Promise<Release[]> {
|
||||
try {
|
||||
const response = await fetch('/api/releases', {
|
||||
headers: { Accept: 'application/json' }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const data = await this.fetchReleasesFromAvailableEndpoints();
|
||||
|
||||
this.cachedReleases = Array.isArray(data) ? data : [data];
|
||||
|
||||
@@ -226,4 +220,41 @@ export class ReleaseService {
|
||||
this.fetchPromise = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchReleasesFromAvailableEndpoints(): Promise<Release[] | Release> {
|
||||
let lastError: unknown = null;
|
||||
|
||||
for (const endpoint of this.getReleaseEndpoints()) {
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
headers: { Accept: 'application/json' }
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
}
|
||||
|
||||
throw lastError instanceof Error
|
||||
? lastError
|
||||
: new Error('Failed to fetch releases from all configured endpoints.');
|
||||
}
|
||||
|
||||
private getReleaseEndpoints(): string[] {
|
||||
if (!isPlatformBrowser(this.platformId)) {
|
||||
return [PROXY_RELEASES_API_URL, DIRECT_RELEASES_API_URL];
|
||||
}
|
||||
|
||||
const hostname = window.location.hostname;
|
||||
const isLocalHost = hostname === 'localhost' || hostname === '127.0.0.1';
|
||||
|
||||
return isLocalHost
|
||||
? [PROXY_RELEASES_API_URL, DIRECT_RELEASES_API_URL]
|
||||
: [DIRECT_RELEASES_API_URL, PROXY_RELEASES_API_URL];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user