feat: 在连接列表展示目标 IP 归属地(集成 nali 离线数据库)#117
Open
yu1745 wants to merge 1 commit into
Open
Conversation
Connections 页每行新增 Location 列,渲染目标 IP 的归属地。 点开连接详情还能看到 Destination/Source Location。 数据源是从 Go 的 zu1k/nali 移植过来的 4 个离线 DB: - ip2region.xdb (Apache-2.0) - qqwry.dat (CZ88 纯真,个人使用) - zxipv6wry.db (ZX 非商业,协议要求随附 协议 txt) - cdn.yml (SukkaLab MIT) DB 通过 pnpm fetch:geoip 在 build 时下载到 assets/geoip/, 该目录已 gitignore。zxinc 的协议 txt 会被自动抽到 assets/geoip/zxinc-license/ 满足 §1 的再分发要求。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

这个 PR 干了什么
Connections 页的每条连接现在会在
Destination IP列右侧多一个Location列,显示该目标 IP 的归属地(例如中国|江苏省|南京市|中国电信|CN、United States|California|Google LLC|US等)。点开连接详情弹窗也能看到Destination Location和Source Location两行。CDN 库的解析函数(lookupCdn)也加载好了,后续在 proxies 页接上即可,本 PR 不动它。为什么需要
改了什么
src/lib/geoip/{xdb,qqwry,zxipv6,cdn}.ts— 4 个 TS 写的离线 DB reader,从 Go 的 zu1k/nali 移植过来。每个 reader 自包含、200-250 行src/api/geoip.ts— 上层包装:init()异步加载、lookupIp(ip)同步查 + LRU 缓存、还有独立的lookupCdn(host)。main.tsx启动时并行调init(),加载完前lookupIp返回'',表格显示—scripts/fetch-geoip-dbs.ts— build 时下载脚本。从各 DB 官方源拉下来,自动把 zxinc 7z 包里的协议 txt 抽出来,再生成assets/geoip/NOTICE.md列出每个 DB 的 SPDX、版权、限制src/lib/buffer-polyfill.ts— 把buffernpm 包的 Buffer 挂到globalThis上,否则 iconv-lite 依赖的safer-buffer在浏览器 bundle 里 import 时就会崩GEOIP.md— 集成文档:怎么 fetch、为什么 build 时、合规说明(重点讲 qqwry 的个人使用、zxinc 的非商业)、如何彻底关闭怎么用
首次克隆后:
```
pnpm fetch:geoip # ~10s,下载 ~38 MB 到 assets/geoip/
pnpm dev
```
之后想更新 DB 重跑
pnpm fetch:geoip就行。Build / CI
assets/geoip/已 gitignore)。CI runner 需要在pnpm build之前先跑pnpm fetch:geoip,否则产出的 build 不会有 Location 列.part。zxinc 偶尔半路 RST,其他三个源稳定iconv-lite、js-yaml、buffer。新增 dev 依赖:tsx(只fetch-geoip-dbs.ts用,进不了 browser bundle)协议 / 合规(麻烦重点 review)
NOTICE.md里qqwry.dat移出 bundle(GEOIP.md 里有步骤)版权声明.txt、使用说明.txt、格式详解-ipdb.txt三个文件抽到assets/geoip/zxinc-license/里,再分发时不要删。相比 nali Go 版(运行时下载到
~/.local/share/nali/),我们只是把同一组下载挪到 build 阶段,没更坏。已知限制
这次 PR 不动的事
POST /upgrade/geo),那是 Clash 自己的 DB,跟我们这套无关怎么验
手动:
—变成具体归属地回归:
useConnectionsStream的 WebSocket 流程没动