refactor: 拆分通用资金工具为国信和华泰证券专属版本
- 移除原通用funds工具代码与配置 - 新增国信证券、华泰证券专属资金工具页面、样式与逻辑 - 为两个工具添加独立的鉴权配置 - 更新导航菜单,将原通用入口替换为两个券商专属入口 - 新增对应券商的SVG图标文件
This commit is contained in:
+144
-40
@@ -53,7 +53,8 @@ const securityCalendarBridge = require('./security_calendar_calendar_bridge')
|
||||
const marketsWeeklyReport = require('./markets_weekly_report')
|
||||
const { upsertMarketArchive, getMarketArchive } = require('./db')
|
||||
const { getConfig: getWallCfg, setConfig: setWallCfg, listCards: listWallCards, createCard: createWallCard, updateCardById: updateWallCardById, deleteCardById: deleteWallCardById } = require('./wall')
|
||||
const funds = require('./funds')
|
||||
const fundsGuoxin = require('./funds_guoxin')
|
||||
const fundsHuatai = require('./funds_huatai')
|
||||
const ccbPrivateFunds = require('./ccb_private_funds')
|
||||
const cloud = require('./cloud')
|
||||
const cloudBalanceWatch = require('./cloud_balance_watch')
|
||||
@@ -1182,7 +1183,7 @@ if (!fs.existsSync(settingsPath)) fs.writeFileSync(settingsPath, JSON.stringify(
|
||||
const flagsPath = path.join(process.cwd(), 'config', 'flags.json')
|
||||
if (!fs.existsSync(flagsPath)) fs.writeFileSync(flagsPath, JSON.stringify({
|
||||
debugTool: { enabled: true, launchDate: null, autoHideAfterDays: 30 },
|
||||
debug: { weibo: true, markets: true, wall: true, funds: true },
|
||||
debug: { weibo: true, markets: true, wall: true, funds_guoxin: true, funds_huatai: true },
|
||||
navAuth: { enable_auth: true, iss: 'TRAE-NAV', iss_strict: false }
|
||||
}, null, 2))
|
||||
|
||||
@@ -1561,7 +1562,8 @@ const mapSystemIdToUrl = (systemId) => {
|
||||
'Tools-weibo': '/tools/weibo',
|
||||
'Tools-markets': '/tools/markets',
|
||||
'Tools-wall-': '/tools/wall',
|
||||
'Tools-funds': '/tools/funds',
|
||||
'Tools-funds_guoxin': '/tools/funds_guoxin',
|
||||
'Tools-funds_huatai': '/tools/funds_huatai',
|
||||
'Tools-ccb_private_funds': '/tools/ccb_private_funds',
|
||||
'Tools-cloud': '/tools/cloud',
|
||||
'Tools-weekly': '/tools/weekly',
|
||||
@@ -1842,17 +1844,17 @@ app.use('/api/cloud', (req, res, next) => {
|
||||
return res.status(401).json({ ok: false, error: 'unauthorized' })
|
||||
})
|
||||
|
||||
const FUNDS_AUTH_COOKIE = 'funds_gate'
|
||||
const readFundsJwk = () => {
|
||||
const FUNDS_GUOXIN_AUTH_COOKIE = 'funds_guoxin_gate'
|
||||
const readFundsGuoxinJwk = () => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'config', 'funds.jwk.json')
|
||||
const p = path.join(process.cwd(), 'config', 'funds_guoxin.jwk.json')
|
||||
if (fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
} catch {}
|
||||
return { kty: 'RSA', n: '', e: '' }
|
||||
}
|
||||
const hasFundsAuth = (req) => {
|
||||
const hasFundsGuoxinAuth = (req) => {
|
||||
try {
|
||||
const configPath = path.join(process.cwd(), 'public', 'tools', 'funds', 'auth_config.json');
|
||||
const configPath = path.join(process.cwd(), 'public', 'tools', 'funds_guoxin', 'auth_config.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
if (config.enable_auth === false) return true;
|
||||
@@ -1860,32 +1862,32 @@ const hasFundsAuth = (req) => {
|
||||
const cookies = parseCookie(req.headers.cookie || '')
|
||||
const name = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds', 'auth_config.json')
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_guoxin', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const n = String(cfg.cookieName || '')
|
||||
if (n) return n
|
||||
}
|
||||
} catch {}
|
||||
return FUNDS_AUTH_COOKIE
|
||||
return FUNDS_GUOXIN_AUTH_COOKIE
|
||||
})()
|
||||
return cookies[name] === '1'
|
||||
} catch { return false }
|
||||
}
|
||||
app.get('/tools/funds', (req, res, next) => {
|
||||
app.get('/tools/funds_guoxin', (req, res, next) => {
|
||||
try {
|
||||
const token = String(req.query.token || '')
|
||||
if (!token) return next()
|
||||
const payload = verifyJwtWithKeys(token, jwkKeys(readFundsJwk()))
|
||||
const payload = verifyJwtWithKeys(token, jwkKeys(readFundsGuoxinJwk()))
|
||||
if (!payload) return res.status(401).send('未授权')
|
||||
{
|
||||
const iss = String(payload.iss || '')
|
||||
const navIss = getNavIssFromFlags()
|
||||
if (iss === navIss && !audMatch(payload, 'Tools-funds')) return res.status(401).send('未授权')
|
||||
if (iss === navIss && !audMatch(payload, 'Tools-funds_guoxin')) return res.status(401).send('未授权')
|
||||
}
|
||||
const maxAgeFunds = (() => {
|
||||
const maxAgeFundsGuoxin = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds', 'auth_config.json')
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_guoxin', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const days = Number(cfg.max_age_days || 0)
|
||||
@@ -1896,27 +1898,105 @@ app.get('/tools/funds', (req, res, next) => {
|
||||
})()
|
||||
const cookieName = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds', 'auth_config.json')
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_guoxin', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const n = String(cfg.cookieName || '')
|
||||
if (n) return n
|
||||
}
|
||||
} catch {}
|
||||
return FUNDS_AUTH_COOKIE
|
||||
return FUNDS_GUOXIN_AUTH_COOKIE
|
||||
})()
|
||||
res.cookie(cookieName, '1', { httpOnly: true, sameSite: 'lax', maxAge: maxAgeFunds, path: '/' })
|
||||
return res.redirect('/tools/funds')
|
||||
res.cookie(cookieName, '1', { httpOnly: true, sameSite: 'lax', maxAge: maxAgeFundsGuoxin, path: '/' })
|
||||
return res.redirect('/tools/funds_guoxin')
|
||||
} catch { return res.status(401).send('未授权') }
|
||||
})
|
||||
app.use('/tools/funds', (req, res, next) => {
|
||||
if (hasFundsAuth(req)) return next()
|
||||
app.use('/tools/funds_guoxin', (req, res, next) => {
|
||||
if (hasFundsGuoxinAuth(req)) return next()
|
||||
const isHandshake = req.method === 'GET' && (req.path === '/' || req.path === '')
|
||||
if (isHandshake && String(req.query.token || '')) return next()
|
||||
return res.status(401).send('未授权')
|
||||
})
|
||||
app.use('/api/funds', (req, res, next) => {
|
||||
if (hasFundsAuth(req)) return next()
|
||||
app.use('/api/funds_guoxin', (req, res, next) => {
|
||||
if (hasFundsGuoxinAuth(req)) return next()
|
||||
return res.status(401).json({ ok: false, error: 'unauthorized' })
|
||||
})
|
||||
|
||||
const FUNDS_HUATAI_AUTH_COOKIE = 'funds_huatai_gate'
|
||||
const readFundsHuataiJwk = () => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'config', 'funds_huatai.jwk.json')
|
||||
if (fs.existsSync(p)) return JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
} catch {}
|
||||
return { kty: 'RSA', n: '', e: '' }
|
||||
}
|
||||
const hasFundsHuataiAuth = (req) => {
|
||||
try {
|
||||
const configPath = path.join(process.cwd(), 'public', 'tools', 'funds_huatai', 'auth_config.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
if (config.enable_auth === false) return true;
|
||||
}
|
||||
const cookies = parseCookie(req.headers.cookie || '')
|
||||
const name = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_huatai', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const n = String(cfg.cookieName || '')
|
||||
if (n) return n
|
||||
}
|
||||
} catch {}
|
||||
return FUNDS_HUATAI_AUTH_COOKIE
|
||||
})()
|
||||
return cookies[name] === '1'
|
||||
} catch { return false }
|
||||
}
|
||||
app.get('/tools/funds_huatai', (req, res, next) => {
|
||||
try {
|
||||
const token = String(req.query.token || '')
|
||||
if (!token) return next()
|
||||
const payload = verifyJwtWithKeys(token, jwkKeys(readFundsHuataiJwk()))
|
||||
if (!payload) return res.status(401).send('未授权')
|
||||
{
|
||||
const iss = String(payload.iss || '')
|
||||
const navIss = getNavIssFromFlags()
|
||||
if (iss === navIss && !audMatch(payload, 'Tools-funds_huatai')) return res.status(401).send('未授权')
|
||||
}
|
||||
const maxAgeFundsHuatai = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_huatai', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const days = Number(cfg.max_age_days || 0)
|
||||
if (Number.isFinite(days) && days > 0) return Math.min(days, 365) * 24 * 3600 * 1000
|
||||
}
|
||||
} catch {}
|
||||
return 90 * 24 * 3600 * 1000
|
||||
})()
|
||||
const cookieName = (() => {
|
||||
try {
|
||||
const p = path.join(process.cwd(), 'public', 'tools', 'funds_huatai', 'auth_config.json')
|
||||
if (fs.existsSync(p)) {
|
||||
const cfg = JSON.parse(fs.readFileSync(p, 'utf-8'))
|
||||
const n = String(cfg.cookieName || '')
|
||||
if (n) return n
|
||||
}
|
||||
} catch {}
|
||||
return FUNDS_HUATAI_AUTH_COOKIE
|
||||
})()
|
||||
res.cookie(cookieName, '1', { httpOnly: true, sameSite: 'lax', maxAge: maxAgeFundsHuatai, path: '/' })
|
||||
return res.redirect('/tools/funds_huatai')
|
||||
} catch { return res.status(401).send('未授权') }
|
||||
})
|
||||
app.use('/tools/funds_huatai', (req, res, next) => {
|
||||
if (hasFundsHuataiAuth(req)) return next()
|
||||
const isHandshake = req.method === 'GET' && (req.path === '/' || req.path === '')
|
||||
if (isHandshake && String(req.query.token || '')) return next()
|
||||
return res.status(401).send('未授权')
|
||||
})
|
||||
app.use('/api/funds_huatai', (req, res, next) => {
|
||||
if (hasFundsHuataiAuth(req)) return next()
|
||||
return res.status(401).json({ ok: false, error: 'unauthorized' })
|
||||
})
|
||||
|
||||
@@ -3971,7 +4051,8 @@ app.get('/api/debug/jwt/verify', (req, res) => {
|
||||
'expense': () => EXPENSE_JWK,
|
||||
'ai-lib': () => readAiLibJwk(),
|
||||
'cloud': () => readCloudJwk(),
|
||||
'funds': () => readFundsJwk(),
|
||||
'funds_guoxin': () => readFundsGuoxinJwk(),
|
||||
'funds_huatai': () => readFundsHuataiJwk(),
|
||||
'markets': () => readMarketsJwk(),
|
||||
'wall': () => readWallJwk(),
|
||||
'weekly': () => readWeeklyJwk(),
|
||||
@@ -4033,7 +4114,7 @@ app.get('/api/debug/nav/private', (req, res) => {
|
||||
|
||||
app.get('/api/flags', (req, res) => {
|
||||
const enabled = computeDebugEnabled()
|
||||
res.json({ ok: true, debugToolEnabled: enabled, debug: { weibo: computeToolDebug('weibo'), markets: computeToolDebug('markets'), wall: computeToolDebug('wall'), funds: computeToolDebug('funds'), weekly: computeToolDebug('weekly') } })
|
||||
res.json({ ok: true, debugToolEnabled: enabled, debug: { weibo: computeToolDebug('weibo'), markets: computeToolDebug('markets'), wall: computeToolDebug('wall'), funds_guoxin: computeToolDebug('funds_guoxin'), funds_huatai: computeToolDebug('funds_huatai'), weekly: computeToolDebug('weekly') } })
|
||||
})
|
||||
|
||||
app.get('/api/weibo/devtools/status', async (req, res) => {
|
||||
@@ -4878,27 +4959,50 @@ app.get('/api/wall/cards', (req, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
// Funds tool
|
||||
app.get('/api/funds/config', (req, res) => {
|
||||
try { res.json({ ok: true, config: funds.getConfig() }) } catch (e) { res.status(500).json({ ok: false, error: String(e.message||e) }) }
|
||||
// Funds Guoxin tool
|
||||
app.get('/api/funds_guoxin/config', (req, res) => {
|
||||
try { res.json({ ok: true, config: fundsGuoxin.getConfig() }) } catch (e) { res.status(500).json({ ok: false, error: String(e.message||e) }) }
|
||||
})
|
||||
app.post('/api/funds/config', (req, res) => {
|
||||
try { const cfg = funds.getConfig(); const body = req.body || {}; const next = Object.assign({}, cfg, body); funds.setConfig(next); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.post('/api/funds_guoxin/config', (req, res) => {
|
||||
try { const cfg = fundsGuoxin.getConfig(); const body = req.body || {}; const next = Object.assign({}, cfg, body); fundsGuoxin.setConfig(next); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.get('/api/funds/flows', (req, res) => {
|
||||
try { res.set('Cache-Control', 'no-store'); const start = String(req.query.start||''); const end = String(req.query.end||''); const type = String(req.query.type||'all'); const kw = String(req.query.kw||''); const rows = funds.listFlows(start, end, type, kw); res.json({ ok: true, rows }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.get('/api/funds_guoxin/flows', (req, res) => {
|
||||
try { res.set('Cache-Control', 'no-store'); const start = String(req.query.start||''); const end = String(req.query.end||''); const type = String(req.query.type||'all'); const kw = String(req.query.kw||''); const rows = fundsGuoxin.listFlows(start, end, type, kw); res.json({ ok: true, rows }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.post('/api/funds/flows', (req, res) => {
|
||||
try { funds.createFlow(req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.post('/api/funds_guoxin/flows', (req, res) => {
|
||||
try { fundsGuoxin.createFlow(req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.put('/api/funds/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); funds.updateFlowById(id, req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.put('/api/funds_guoxin/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); fundsGuoxin.updateFlowById(id, req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.delete('/api/funds/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); funds.deleteFlow(id); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.delete('/api/funds_guoxin/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); fundsGuoxin.deleteFlow(id); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.get('/api/funds/export.csv', (req, res) => {
|
||||
try { const start = String(req.query.start||''); const end = String(req.query.end||''); const rows = funds.listFlows(start, end, 'all', ''); const header = '日期,类型,金额(人民币),银行方/状态,期末金额,备注\n'; const content = rows.map(r => `${r.date},${r.type==='in'?'汇入':'汇出'},${(r.amount_cents/100).toFixed(2)},${(r.bank_status||'').replace(/,/g,' ')},${(r.ending_cents/100).toFixed(2)},${(r.remark||'').replace(/,/g,' ')}`).join('\n'); res.setHeader('Content-Type','text/csv; charset=utf-8'); res.setHeader('Content-Disposition','attachment; filename="funds.csv"'); res.send(header+content) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
app.get('/api/funds_guoxin/export.csv', (req, res) => {
|
||||
try { const start = String(req.query.start||''); const end = String(req.query.end||''); const rows = fundsGuoxin.listFlows(start, end, 'all', ''); const header = '日期,类型,金额(人民币),银行方/状态,期末金额,备注\n'; const content = rows.map(r => `${r.date},${r.type==='in'?'汇入':'汇出'},${(r.amount_cents/100).toFixed(2)},${(r.bank_status||'').replace(/,/g,' ')},${(r.ending_cents/100).toFixed(2)},${(r.remark||'').replace(/,/g,' ')}`).join('\n'); res.setHeader('Content-Type','text/csv; charset=utf-8'); res.setHeader('Content-Disposition','attachment; filename="funds_guoxin.csv"'); res.send(header+content) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
|
||||
// Funds Huatai tool
|
||||
app.get('/api/funds_huatai/config', (req, res) => {
|
||||
try { res.json({ ok: true, config: fundsHuatai.getConfig() }) } catch (e) { res.status(500).json({ ok: false, error: String(e.message||e) }) }
|
||||
})
|
||||
app.post('/api/funds_huatai/config', (req, res) => {
|
||||
try { const cfg = fundsHuatai.getConfig(); const body = req.body || {}; const next = Object.assign({}, cfg, body); fundsHuatai.setConfig(next); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.get('/api/funds_huatai/flows', (req, res) => {
|
||||
try { res.set('Cache-Control', 'no-store'); const start = String(req.query.start||''); const end = String(req.query.end||''); const type = String(req.query.type||'all'); const kw = String(req.query.kw||''); const rows = fundsHuatai.listFlows(start, end, type, kw); res.json({ ok: true, rows }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.post('/api/funds_huatai/flows', (req, res) => {
|
||||
try { fundsHuatai.createFlow(req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.put('/api/funds_huatai/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); fundsHuatai.updateFlowById(id, req.body||{}); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.delete('/api/funds_huatai/flows/:id', (req, res) => {
|
||||
try { const id = parseInt(req.params.id,10); fundsHuatai.deleteFlow(id); res.json({ ok: true }) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
app.get('/api/funds_huatai/export.csv', (req, res) => {
|
||||
try { const start = String(req.query.start||''); const end = String(req.query.end||''); const rows = fundsHuatai.listFlows(start, end, 'all', ''); const header = '日期,类型,金额(人民币),银行方/状态,期末金额,备注\n'; const content = rows.map(r => `${r.date},${r.type==='in'?'汇入':'汇出'},${(r.amount_cents/100).toFixed(2)},${(r.bank_status||'').replace(/,/g,' ')},${(r.ending_cents/100).toFixed(2)},${(r.remark||'').replace(/,/g,' ')}`).join('\n'); res.setHeader('Content-Type','text/csv; charset=utf-8'); res.setHeader('Content-Disposition','attachment; filename="funds_huatai.csv"'); res.send(header+content) } catch (e) { res.status(500).json({ ok:false, error:String(e.message||e) }) }
|
||||
})
|
||||
|
||||
app.get('/api/ccb_private_funds/config', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user