refactor: add timeout to gh release fetch
This commit is contained in:
parent
96231b2e82
commit
66dccf76cc
1 changed files with 7 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import { config } from "../../core/config";
|
||||||
import type { UpdateInfoDto } from "./system.dto";
|
import type { UpdateInfoDto } from "./system.dto";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import { cache } from "../../utils/cache";
|
import { cache } from "../../utils/cache";
|
||||||
|
import { logger } from "~/server/utils/logger";
|
||||||
|
|
||||||
const CACHE_TTL = 60 * 60;
|
const CACHE_TTL = 60 * 60;
|
||||||
|
|
||||||
|
|
@ -28,11 +29,16 @@ const getUpdates = async (): Promise<UpdateInfoDto> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
||||||
|
|
||||||
const response = await fetch("https://api.github.com/repos/nicotsx/zerobyte/releases", {
|
const response = await fetch("https://api.github.com/repos/nicotsx/zerobyte/releases", {
|
||||||
|
signal: controller.signal,
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": "zerobyte-app",
|
"User-Agent": "zerobyte-app",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`GitHub API returned ${response.status}`);
|
throw new Error(`GitHub API returned ${response.status}`);
|
||||||
|
|
@ -74,7 +80,7 @@ const getUpdates = async (): Promise<UpdateInfoDto> => {
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch updates from GitHub:", error);
|
logger.error("Failed to fetch updates from GitHub:", error);
|
||||||
return {
|
return {
|
||||||
currentVersion: config.appVersion,
|
currentVersion: config.appVersion,
|
||||||
latestVersion: config.appVersion,
|
latestVersion: config.appVersion,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue