mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 01:14:10 +05:30
feat: separate subscription base url
This commit is contained in:
@@ -132,7 +132,7 @@ async function buildActionUrl(pathname: string, token: string, options: { header
|
||||
allowRequestFallback: true,
|
||||
});
|
||||
if (!baseUrl) {
|
||||
throw new Error("请先在系统设置中填写站点域名");
|
||||
throw new Error("请先在系统设置中填写网站 URL");
|
||||
}
|
||||
|
||||
const url = new URL(pathname, baseUrl);
|
||||
|
||||
@@ -18,14 +18,14 @@ export function normalizeSiteUrl(raw: string | null | undefined): string | null
|
||||
try {
|
||||
url = new URL(withProtocol);
|
||||
} catch {
|
||||
throw new Error("站点域名格式不正确,请填写 https://example.com");
|
||||
throw new Error("URL 格式不正确,请填写 https://example.com");
|
||||
}
|
||||
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
||||
throw new Error("站点域名仅支持 http:// 或 https://");
|
||||
throw new Error("URL 仅支持 http:// 或 https://");
|
||||
}
|
||||
if (!url.hostname) {
|
||||
throw new Error("站点域名不能为空");
|
||||
throw new Error("URL 主机不能为空");
|
||||
}
|
||||
|
||||
url.search = "";
|
||||
@@ -79,6 +79,14 @@ export async function getConfiguredSiteUrl(db: DbClient = prisma): Promise<strin
|
||||
return safeNormalizeSiteUrl(config.siteUrl) ?? safeNormalizeSiteUrl(process.env.NEXTAUTH_URL);
|
||||
}
|
||||
|
||||
export async function getConfiguredSubscriptionUrl(db: DbClient = prisma): Promise<string | null> {
|
||||
const config = await getAppConfig(db);
|
||||
return safeNormalizeSiteUrl(config.subscriptionUrl)
|
||||
?? safeNormalizeSiteUrl(process.env.SUBSCRIPTION_URL)
|
||||
?? safeNormalizeSiteUrl(config.siteUrl)
|
||||
?? safeNormalizeSiteUrl(process.env.NEXTAUTH_URL);
|
||||
}
|
||||
|
||||
export async function getSiteBaseUrl(options: {
|
||||
headers?: Headers;
|
||||
requestUrl?: string;
|
||||
@@ -93,3 +101,18 @@ export async function getSiteBaseUrl(options: {
|
||||
options.headers ? getForwardedSiteUrl(options.headers) : null
|
||||
) ?? getRequestOriginUrl(options.requestUrl) ?? "";
|
||||
}
|
||||
|
||||
export async function getSubscriptionBaseUrl(options: {
|
||||
headers?: Headers;
|
||||
requestUrl?: string;
|
||||
db?: DbClient;
|
||||
allowRequestFallback?: boolean;
|
||||
} = {}): Promise<string> {
|
||||
const configured = await getConfiguredSubscriptionUrl(options.db ?? prisma);
|
||||
if (configured) return configured;
|
||||
if (!options.allowRequestFallback) return "";
|
||||
|
||||
return (
|
||||
options.headers ? getForwardedSiteUrl(options.headers) : null
|
||||
) ?? getRequestOriginUrl(options.requestUrl) ?? "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user