mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-04-06 21:18:26 +03:00
29 lines
669 B
TypeScript
29 lines
669 B
TypeScript
interface GiteaUrlConfig {
|
|
url?: string | null;
|
|
externalUrl?: string | null;
|
|
}
|
|
|
|
export function getGiteaWebBaseUrl(
|
|
config?: GiteaUrlConfig | null
|
|
): string | null {
|
|
const rawBaseUrl = config?.externalUrl || config?.url;
|
|
if (!rawBaseUrl) {
|
|
return null;
|
|
}
|
|
|
|
return rawBaseUrl.endsWith("/") ? rawBaseUrl.slice(0, -1) : rawBaseUrl;
|
|
}
|
|
|
|
export function buildGiteaWebUrl(
|
|
config: GiteaUrlConfig | null | undefined,
|
|
path: string
|
|
): string | null {
|
|
const baseUrl = getGiteaWebBaseUrl(config);
|
|
if (!baseUrl) {
|
|
return null;
|
|
}
|
|
|
|
const normalizedPath = path.replace(/^\/+/, "");
|
|
return normalizedPath ? `${baseUrl}/${normalizedPath}` : baseUrl;
|
|
}
|