mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 22:31:11 +10:00
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import bytes from "bytes";
|
|
import { castToBoolean } from "@/lib/utils.tsx";
|
|
|
|
declare global {
|
|
interface Window {
|
|
CONFIG?: Record<string, string>;
|
|
}
|
|
}
|
|
|
|
export function getAppName(): string {
|
|
return "Docmost";
|
|
}
|
|
|
|
export function getAppUrl(): string {
|
|
return `${window.location.protocol}//${window.location.host}`;
|
|
}
|
|
|
|
export function getServerAppUrl(): string {
|
|
return getConfigValue("APP_URL");
|
|
}
|
|
|
|
export function getBackendUrl(): string {
|
|
return getAppUrl() + "/api";
|
|
}
|
|
|
|
export function getCollaborationUrl(): string {
|
|
const baseUrl =
|
|
getConfigValue("COLLAB_URL") ||
|
|
(import.meta.env.DEV ? process.env.APP_URL : getAppUrl());
|
|
|
|
const collabUrl = new URL("/collab", baseUrl);
|
|
collabUrl.protocol = collabUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
return collabUrl.toString();
|
|
}
|
|
|
|
export function getSubdomainHost(): string {
|
|
return getConfigValue("SUBDOMAIN_HOST");
|
|
}
|
|
|
|
export function isCloud(): boolean {
|
|
return castToBoolean(getConfigValue("CLOUD"));
|
|
}
|
|
|
|
export function getAvatarUrl(avatarUrl: string) {
|
|
if (!avatarUrl) return null;
|
|
if (avatarUrl?.startsWith("http")) return avatarUrl;
|
|
|
|
return getBackendUrl() + "/attachments/img/avatar/" + avatarUrl;
|
|
}
|
|
|
|
export function getSpaceUrl(spaceSlug: string) {
|
|
return "/s/" + spaceSlug;
|
|
}
|
|
|
|
export function getFileUrl(src: string) {
|
|
if (!src) return src;
|
|
if (src.startsWith("http")) return src;
|
|
if (src.startsWith("/api/")) {
|
|
// Remove the '/api' prefix
|
|
return getBackendUrl() + src.substring(4);
|
|
}
|
|
if (src.startsWith("/files/")) {
|
|
return getBackendUrl() + src;
|
|
}
|
|
return src;
|
|
}
|
|
|
|
export function getFileUploadSizeLimit() {
|
|
const limit = getConfigValue("FILE_UPLOAD_SIZE_LIMIT", "50mb");
|
|
return bytes(limit);
|
|
}
|
|
|
|
export function getDrawioUrl() {
|
|
return getConfigValue("DRAWIO_URL", "https://embed.diagrams.net");
|
|
}
|
|
|
|
function getConfigValue(key: string, defaultValue: string = undefined): string {
|
|
const rawValue = import.meta.env.DEV
|
|
? process?.env?.[key]
|
|
: window?.CONFIG?.[key];
|
|
return rawValue ?? defaultValue;
|
|
}
|