66 lines
2.7 KiB
TypeScript
66 lines
2.7 KiB
TypeScript
import path from "path";
|
|
import os from "os";
|
|
|
|
// 博客根目录
|
|
// Docker 构建时 BLOG_ROOT=/blog 已被 Turbopack 内联
|
|
// 本地开发时回退到上级目录
|
|
export const BLOG_ROOT = process.env.BLOG_ROOT || path.resolve(process.cwd(), "..");
|
|
|
|
export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts");
|
|
export const STATIC_DIR = path.join(BLOG_ROOT, "static");
|
|
export const RECYCLE_DIR = path.join(process.cwd(), "recycle");
|
|
export const RECYCLE_POSTS_DIR = path.join(RECYCLE_DIR, "posts");
|
|
export const RECYCLE_META_DIR = path.join(RECYCLE_DIR, "meta");
|
|
export const ARTALK_SERVER = process.env.ARTALK_SERVER || "https://artalk.usj.cc";
|
|
export const ARTALK_SITE = process.env.ARTALK_SITE || "优世界";
|
|
export const ITEMS_PER_PAGE = parseInt(process.env.ITEMS_PER_PAGE || "20", 10);
|
|
export const RECYCLE_DAYS = parseInt(process.env.RECYCLE_DAYS || "30", 10);
|
|
export const HUGO_PREVIEW = process.env.NEXT_PUBLIC_HUGO_PREVIEW || process.env.HUGO_PREVIEW || "http://localhost:1313";
|
|
export const RSS_API_BASE = process.env.RSS_API_BASE || "https://api.usj.cc";
|
|
export const RSS_API_TOKEN = process.env.RSS_API_TOKEN || "";
|
|
export const WECHAT_APP_ID = process.env.WECHAT_APP_ID || "";
|
|
export const WECHAT_APP_SECRET = process.env.WECHAT_APP_SECRET || "";
|
|
|
|
// Bot 配置
|
|
export const TG_BOT_TOKEN = process.env.TG_BOT_TOKEN || "";
|
|
export const TG_ALLOWED_IDS: number[] = (process.env.TG_ALLOWED_CHAT_IDS || "")
|
|
.split(",").map((s) => s.trim()).filter(Boolean).map(Number);
|
|
|
|
// Linux 默认网络接口(eth0, ens33 等),Windows 默认 WLAN
|
|
export const PREFER_IFACE = process.env.PREFER_IFACE || (process.platform === "linux" ? "eth0" : "WLAN");
|
|
export const DEFAULT_AUTHOR = process.env.DEFAULT_AUTHOR || "小赵";
|
|
|
|
export function getLanIP(): string {
|
|
const ifs = os.networkInterfaces();
|
|
const candidates: { name: string; address: string }[] = [];
|
|
for (const [name, addrs] of Object.entries(ifs)) {
|
|
if (!addrs) continue;
|
|
for (const a of addrs) {
|
|
if (a.family !== "IPv4" || a.internal) continue;
|
|
if (a.address.startsWith("169.254.")) continue;
|
|
candidates.push({ name, address: a.address });
|
|
}
|
|
}
|
|
|
|
// 优先查找首选接口
|
|
const pref = candidates.find((c) =>
|
|
c.name.toLowerCase().includes(PREFER_IFACE.toLowerCase())
|
|
);
|
|
if (pref) return pref.address;
|
|
|
|
// 查找真实网络接口(排除虚拟接口)
|
|
const real = candidates.find((c) => {
|
|
const n = c.name.toLowerCase();
|
|
return !n.includes("vmware") &&
|
|
!n.includes("virtual") &&
|
|
!n.includes("vethernet") &&
|
|
!n.includes("docker") &&
|
|
!n.includes("br-") &&
|
|
!n.includes("veth");
|
|
});
|
|
if (real) return real.address;
|
|
|
|
// 返回第一个可用地址
|
|
return candidates[0]?.address || "0.0.0.0";
|
|
}
|