114 lines
3.2 KiB
TypeScript
114 lines
3.2 KiB
TypeScript
/**
|
||
* 服务配置 - PocketBase、支付、MinIO
|
||
* 域名更换:设置 ROOT_DOMAIN(如 nomadro.com)可推导默认 API 地址
|
||
*/
|
||
|
||
import {
|
||
DEFAULT_PAYMENT_API_URL,
|
||
DEFAULT_POCKETBASE_URL,
|
||
DEFAULT_MINIO_HOST,
|
||
resolvePaymentApiUrl,
|
||
} from "./domain.config";
|
||
|
||
export interface PocketBaseConfig {
|
||
enabled: boolean;
|
||
url: string;
|
||
usersCollection: string;
|
||
joinCollection: string;
|
||
}
|
||
|
||
export interface PaymentConfig {
|
||
enabled: boolean;
|
||
apiUrl: string;
|
||
provider: "zpay" | "xorpay";
|
||
defaultAmount: number;
|
||
defaultType: string;
|
||
zpaySubmitUrl: string;
|
||
}
|
||
|
||
export interface MinioConfig {
|
||
enabled: boolean;
|
||
endPoint: string;
|
||
port: number;
|
||
useSSL: boolean;
|
||
bucket: string;
|
||
accessKey: string;
|
||
secretKey: string;
|
||
region: string;
|
||
publicUrl: string;
|
||
uploadPrefix: string;
|
||
}
|
||
|
||
const isDev = process.env.NODE_ENV === "development";
|
||
const PAYJSAPI_PORT = process.env.PAYJSAPI_PORT || "8007";
|
||
|
||
/** 站点标识,用于 VIP 按站点隔离 */
|
||
export const SITE_ID = process.env.NEXT_PUBLIC_SITE_ID || "meetup";
|
||
|
||
/** meetup 加入游牧中国 价格(分),88元=8800 */
|
||
export const MEETUP_JOIN_AMOUNT = 8800;
|
||
|
||
export function getApiUrlFromRequest(hostHeader: string | null): string | null {
|
||
if (!hostHeader) return null;
|
||
if (!isDev) return resolvePaymentApiUrl();
|
||
const hostname = hostHeader.split(":")[0];
|
||
return `http://${hostname}:${PAYJSAPI_PORT}`;
|
||
}
|
||
|
||
export function getPocketBaseConfig(): PocketBaseConfig {
|
||
return {
|
||
enabled: true,
|
||
url:
|
||
process.env.NEXT_PUBLIC_POCKETBASE_URL ||
|
||
process.env.POCKETBASE_URL ||
|
||
DEFAULT_POCKETBASE_URL,
|
||
usersCollection: "users",
|
||
joinCollection: process.env.POCKETBASE_JOIN_COLLECTION || "solan",
|
||
};
|
||
}
|
||
|
||
export function getPaymentConfig(): PaymentConfig {
|
||
return {
|
||
enabled: true,
|
||
apiUrl: resolvePaymentApiUrl(),
|
||
provider: (process.env.PAYMENT_PROVIDER as "zpay" | "xorpay") || "zpay",
|
||
defaultAmount: Number(process.env.PAYMENT_DEFAULT_AMOUNT) || 8800,
|
||
defaultType: process.env.PAYMENT_DEFAULT_TYPE || "meetup",
|
||
zpaySubmitUrl: process.env.ZPAY_SUBMIT_URL || "https://zpayz.cn/submit.php",
|
||
};
|
||
}
|
||
|
||
/** 获取「加入」场景的支付配置 */
|
||
export function getJoinPaymentConfig(): { amount: number; type: string } {
|
||
return {
|
||
amount: Number(process.env.PAYMENT_JOIN_AMOUNT) || MEETUP_JOIN_AMOUNT,
|
||
type: process.env.PAYMENT_JOIN_TYPE || "meetup",
|
||
};
|
||
}
|
||
|
||
export function getMinioConfig(themeOverride?: {
|
||
bucket?: string;
|
||
uploadPrefix?: string;
|
||
}): MinioConfig {
|
||
const endPoint = process.env.MINIO_ENDPOINT || DEFAULT_MINIO_HOST;
|
||
const port = parseInt(process.env.MINIO_PORT || "9035", 10);
|
||
const bucket = themeOverride?.bucket || process.env.MINIO_BUCKET || "hackrobot";
|
||
const publicUrl =
|
||
process.env.MINIO_PUBLIC_URL || `https://${endPoint}/${bucket}`;
|
||
const uploadPrefix =
|
||
themeOverride?.uploadPrefix || process.env.MINIO_UPLOAD_PREFIX || "joins";
|
||
|
||
return {
|
||
enabled: true,
|
||
endPoint,
|
||
port,
|
||
useSSL: process.env.MINIO_USE_SSL === "true",
|
||
bucket,
|
||
accessKey: process.env.MINIO_ACCESS_KEY || "",
|
||
secretKey: process.env.MINIO_SECRET_KEY || "",
|
||
region: process.env.MINIO_REGION || "china",
|
||
publicUrl: publicUrl.replace(/\/$/, ""),
|
||
uploadPrefix,
|
||
};
|
||
}
|