功能:收口小程序前后台安全与防重复提交

This commit is contained in:
xiaowang
2026-04-20 16:02:57 +08:00
parent eb1c209d79
commit a3df262fae
237 changed files with 14068 additions and 728 deletions
+60 -6
View File
@@ -1,3 +1,11 @@
function safeRequire(modulePath) {
try {
return require(modulePath)
} catch (error) {
return {}
}
}
function getEnvVersion() {
if (typeof wx === 'undefined') {
return 'develop'
@@ -48,24 +56,70 @@ function getRuntimePlatform() {
return 'unknown'
}
function normalizeDomain(value, fallbackValue) {
const target = String(value || fallbackValue || '').trim()
if (!target) {
return ''
}
return target.replace(/\/+$/, '')
}
function ensureHttps(value, envVersion) {
if (!value) {
throw new Error(`Missing API domain for ${envVersion}`)
}
if (envVersion !== 'develop' && !value.startsWith('https://')) {
throw new Error(`${envVersion} environment must use HTTPS`)
}
return value
}
const localOverride = safeRequire('./config.local')
const ENV_VERSION = getEnvVersion()
const RUNTIME_PLATFORM = getRuntimePlatform()
const IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools'
const LOCAL_API_DOMAIN = 'http://127.0.0.1:80'
const REMOTE_API_DOMAIN = 'https://yunail.art'
const USE_LOCAL_API = ENV_VERSION === 'develop' && IS_DEVTOOLS
const API_DOMAIN = USE_LOCAL_API ? LOCAL_API_DOMAIN : REMOTE_API_DOMAIN
const DEFAULT_DOMAINS = {
local: 'http://127.0.0.1:80',
tunnel: 'https://yunail.art',
'dev-remote': 'https://yunail.art',
trial: 'https://yunail.art',
release: 'https://yunail.art'
}
const DOMAIN_MAP = {
...DEFAULT_DOMAINS,
...(localOverride.domains || {})
}
const DEFAULT_DEVELOP_TARGET = IS_DEVTOOLS ? 'local' : 'dev-remote'
const DEVELOP_TARGET = String(localOverride.developTarget || DEFAULT_DEVELOP_TARGET)
const API_DOMAIN = ensureHttps(
ENV_VERSION === 'develop'
? normalizeDomain(DOMAIN_MAP[DEVELOP_TARGET], DOMAIN_MAP['dev-remote'])
: normalizeDomain(DOMAIN_MAP[ENV_VERSION], DOMAIN_MAP.release),
ENV_VERSION
)
module.exports = {
ENV_VERSION,
RUNTIME_PLATFORM,
IS_DEVTOOLS,
USE_LOCAL_API,
DEVELOP_TARGET,
API_DOMAIN,
API_BASE_URL: `${API_DOMAIN}/api`,
IS_DEV_ENV: ENV_VERSION === 'develop',
REQUEST_TIMEOUT: 10000,
REQUEST_TIMEOUT: Number(localOverride.requestTimeout || 10000),
ENABLE_REQUEST_SIGNING: localOverride.enableRequestSigning !== false,
IDLE_TIMEOUT_MS: 60 * 60 * 1000,
IDLE_WARNING_MS: 2 * 60 * 1000,
CACHE_TTL: {
banner: 5 * 60 * 1000,
publicShops: 5 * 60 * 1000,
tags: 10 * 60 * 1000,
homeList: 2 * 60 * 1000,
signedUrl: 50 * 60 * 1000
},
DEFAULT_AVATAR: 'https://api.dicebear.com/7.x/avataaars/svg?seed=default',
DEFAULT_PRODUCT_IMAGE: 'https://via.placeholder.com/200x200?text=Product',
DEFAULT_SHOP_IMAGE: 'https://via.placeholder.com/200x200?text=Shop',