mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-07 21:46:38 +00:00
add server info endpoint
This commit is contained in:
@@ -18,6 +18,7 @@ import * as apiKeys from "./apiKeys";
|
||||
import * as logs from "./auditLogs";
|
||||
import * as newt from "./newt";
|
||||
import * as olm from "./olm";
|
||||
import * as serverInfo from "./serverInfo";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import {
|
||||
verifyAccessTokenAccess,
|
||||
@@ -712,6 +713,8 @@ authenticated.get(
|
||||
|
||||
authenticated.get(`/org/:orgId/overview`, verifyOrgAccess, org.getOrgOverview);
|
||||
|
||||
authenticated.get(`/server-info`, serverInfo.getServerInfo);
|
||||
|
||||
authenticated.post(
|
||||
`/supporter-key/validate`,
|
||||
supporterKey.validateSupporterKey
|
||||
|
||||
60
server/routers/serverInfo/getServerInfo.ts
Normal file
60
server/routers/serverInfo/getServerInfo.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
import createHttpError from "http-errors";
|
||||
import logger from "@server/logger";
|
||||
import { response as sendResponse } from "@server/lib/response";
|
||||
import config from "@server/lib/config";
|
||||
import { build } from "@server/build";
|
||||
import { APP_VERSION } from "@server/lib/consts";
|
||||
import license from "#dynamic/license/license";
|
||||
|
||||
export type GetServerInfoResponse = {
|
||||
version: string;
|
||||
supporterStatusValid: boolean;
|
||||
build: "oss" | "enterprise" | "saas";
|
||||
enterpriseLicenseValid: boolean;
|
||||
enterpriseLicenseType: string | null;
|
||||
};
|
||||
|
||||
export async function getServerInfo(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
): Promise<any> {
|
||||
try {
|
||||
const supporterData = config.getSupporterData();
|
||||
const supporterStatusValid = supporterData?.valid || false;
|
||||
|
||||
let enterpriseLicenseValid = false;
|
||||
let enterpriseLicenseType: string | null = null;
|
||||
|
||||
if (build === "enterprise") {
|
||||
try {
|
||||
const licenseStatus = await license.check();
|
||||
enterpriseLicenseValid = licenseStatus.isLicenseValid;
|
||||
enterpriseLicenseType = licenseStatus.tier || null;
|
||||
} catch (error) {
|
||||
logger.warn("Failed to check enterprise license status:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return sendResponse<GetServerInfoResponse>(res, {
|
||||
data: {
|
||||
version: APP_VERSION,
|
||||
supporterStatusValid,
|
||||
build,
|
||||
enterpriseLicenseValid,
|
||||
enterpriseLicenseType
|
||||
},
|
||||
success: true,
|
||||
error: false,
|
||||
message: "Server info retrieved",
|
||||
status: HttpCode.OK
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return next(
|
||||
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||
);
|
||||
}
|
||||
}
|
||||
1
server/routers/serverInfo/index.ts
Normal file
1
server/routers/serverInfo/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./getServerInfo";
|
||||
Reference in New Issue
Block a user