Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ E2E_TEST_PASSWORD="your-test-password"

# ==================== DWEB 发布 ====================

# KeyApp 官网配置(DWEB 自动更新使用)
# 注意:SITE_ORIGIN 与 SITE_BASE_URL 必须成对配置
SITE_ORIGIN="https://bioforestchain.github.io/"
SITE_BASE_URL="/KeyApp/"

# SFTP 服务器地址(默认: sftp://iweb.xin:22022)
# DWEB_SFTP_URL="sftp://iweb.xin:22022"

Expand Down
2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function resolveSiteOrigin(): string | null {
function resolveSiteBaseUrl(): string | null {
const origin = resolveSiteOrigin()
if (!origin) return null
const basePath = process.env.VITEPRESS_BASE ?? '/'
const basePath = process.env.SITE_BASE_URL ?? process.env.VITEPRESS_BASE ?? '/'
return new URL(basePath, origin).toString()
}

Expand Down
11 changes: 10 additions & 1 deletion scripts/env-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
"required": true,
"targets": { "local": true, "github": "variable" },
"mask": "tail",
"description": "DWEB 自动更新使用的官网域名"
"description": "DWEB 自动更新使用的官网域名(需与 SITE_BASE_URL 成对配置)"
},
{
"key": "SITE_BASE_URL",
"label": "KeyApp 站点 Base Path",
"type": "string",
"required": true,
"targets": { "local": true, "github": "variable" },
"mask": "tail",
"description": "DWEB 自动更新使用的站点路径(需与 SITE_ORIGIN 成对配置,例如 /KeyApp/)"
},
{
"key": "DWEB_SFTP_URL",
Expand Down
1 change: 1 addition & 0 deletions src/lib/dweb-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function normalizeBasePath(basePath: string): string {
}

function resolveSiteBase(): string {
// __KEYAPP_SITE_ORIGIN__ + __KEYAPP_BASE_URL__ 必须成对配置,避免丢失站点路径。
const origin = normalizeOrigin(__KEYAPP_SITE_ORIGIN__)
try {
const originUrl = new URL(origin)
Expand Down
7 changes: 5 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export default defineConfig(({ mode }) => {
const etherscanApiKey = env.ETHERSCAN_API_KEY ?? process.env.ETHERSCAN_API_KEY ?? '';
const moralisApiKey = env.MORALIS_API_KEY ?? process.env.MORALIS_API_KEY ?? '';
const isDevBuild = (env.VITE_DEV_MODE ?? process.env.VITE_DEV_MODE) === 'true';
// DWEB 更新地址由 SITE_ORIGIN + SITE_BASE_URL 拼接,二者必须成对配置。
// 注意:这里不要误用 VITE_BASE_URL(它是构建资源的 base),否则会导致更新 URL 丢失站点路径。
const siteOrigin = env.SITE_ORIGIN ?? process.env.SITE_ORIGIN ?? 'https://bioforestchain.github.io/KeyApp/';
const siteBaseUrl = env.SITE_BASE_URL ?? process.env.SITE_BASE_URL ?? BASE_URL;

const buildTime = new Date();
const pad = (value: number) => value.toString().padStart(2, '0');
Expand Down Expand Up @@ -209,8 +212,8 @@ export default defineConfig(({ mode }) => {
__APP_VERSION__: JSON.stringify(appVersion),
// KeyApp 官网 Origin(DWEB 升级检查使用)
__KEYAPP_SITE_ORIGIN__: JSON.stringify(siteOrigin),
// KeyApp Base URL(DWEB 升级链接拼接使用)
__KEYAPP_BASE_URL__: JSON.stringify(BASE_URL),
// KeyApp Base URL(DWEB 升级链接拼接使用;需配合 SITE_ORIGIN 使用
__KEYAPP_BASE_URL__: JSON.stringify(siteBaseUrl),
// 默认生态源列表(用于订阅源管理展示)
__ECOSYSTEM_SOURCES__: JSON.stringify(ecosystemSources),
// API Keys 对象(用于动态读取环境变量)
Expand Down