🚧 New version popup

This commit is contained in:
Fred KISSIE
2025-11-05 06:55:08 +01:00
parent a26a441d56
commit 2f1abfbef8
7 changed files with 247 additions and 17 deletions

View File

@@ -51,6 +51,15 @@ export const internal = axios.create({
}
});
export const remote = axios.create({
baseURL: `${process.env.NEXT_PUBLIC_FOSSORIAL_REMOTE_API_URL}/api/v1`,
timeout: 10000,
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": "x-csrf-protection"
}
});
export const priv = axios.create({
baseURL: `http://localhost:${process.env.SERVER_INTERNAL_PORT}/api/v1`,
timeout: 10000,
@@ -60,4 +69,3 @@ export const priv = axios.create({
});
export * from "./formatAxiosError";

13
src/lib/durationToMs.ts Normal file
View File

@@ -0,0 +1,13 @@
export function durationToMs(
value: number,
unit: "seconds" | "minutes" | "hours" | "days" | "weeks"
): number {
const multipliers = {
seconds: 1000,
minutes: 60 * 1000,
hours: 60 * 60 * 1000,
days: 24 * 60 * 60 * 1000,
weeks: 7 * 24 * 60 * 60 * 1000
};
return value * multipliers[unit];
}

38
src/lib/queries.ts Normal file
View File

@@ -0,0 +1,38 @@
import {
type InfiniteData,
type QueryClient,
keepPreviousData,
queryOptions,
type skipToken
} from "@tanstack/react-query";
import { durationToMs } from "./durationToMs";
import { build } from "@server/build";
import { remote } from "./api";
import type ResponseT from "@server/types/Response";
export const versionsQueries = {
latestVersion: () =>
queryOptions({
queryKey: ["LATEST_VERSION"] as const,
queryFn: async ({ signal }) => {
const data = await remote.get<
ResponseT<{
pangolin: {
latestVersion: string;
releaseNotes: string;
};
}>
>("/latest-version");
return data.data;
},
placeholderData: keepPreviousData,
refetchInterval: (query) => {
if (query.state.data) {
return durationToMs(30, "minutes");
}
return false;
},
enabled: build === "oss" || build === "enterprise" // disabled in cloud version
// because we don't need to listen for new versions there
})
};