初始化 M0:Astro SSR + node:sqlite 脚手架与只读页面
This commit is contained in:
1 parent
97440b4120
commit
8430e5304d
39 files changed
+6397
No files matched your search
@@ -0,0 +1,11 @@
|
||||
node_modules
|
||||
dist
|
||||
.astro
|
||||
.pnpm-store
|
||||
data
|
||||
backups
|
||||
.git
|
||||
.screenshots
|
||||
*.log
|
||||
.env
|
||||
.env.*
|
||||
@@ -0,0 +1,26 @@
|
||||
# 复制为 .env 后填写。切勿提交真实密钥。
|
||||
|
||||
# ---- 编辑验证(M2 使用)----
|
||||
ADMIN_PASSWORD=change-me
|
||||
SESSION_SECRET=请替换为随机长字符串
|
||||
|
||||
# ---- AI(OpenAI 兼容协议)----
|
||||
AI_BASE_URL=https://api.deepseek.com/v1
|
||||
AI_API_KEY=
|
||||
AI_MODEL=deepseek-chat
|
||||
SEARCH_API_KEY=
|
||||
|
||||
# ---- 存储 ----
|
||||
# local | s3
|
||||
STORAGE_DRIVER=local
|
||||
UPLOADS_DIR=data/uploads
|
||||
# s3 驱动时填写
|
||||
S3_ENDPOINT=
|
||||
S3_BUCKET=
|
||||
S3_REGION=
|
||||
S3_KEY=
|
||||
S3_SECRET=
|
||||
S3_PUBLIC_BASE_URL=
|
||||
|
||||
# ---- 数据库 ----
|
||||
DB_PATH=data/app.db
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# build output
|
||||
dist/
|
||||
# generated types
|
||||
.astro/
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# logs
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
|
||||
# environment variables
|
||||
.env
|
||||
.env.production
|
||||
|
||||
# macOS-specific files
|
||||
.DS_Store
|
||||
|
||||
# jetbrains setting folder
|
||||
.idea/
|
||||
|
||||
# 运行时数据:数据库与上传图片,不进版本库
|
||||
data/
|
||||
backups/
|
||||
|
||||
# 本地截图/临时产物
|
||||
.screenshots/
|
||||
install.log
|
||||
|
||||
# pnpm 本地 store(本机全局 store 目录存在写权限问题,故用项目内 store)
|
||||
.pnpm-store/
|
||||
@@ -0,0 +1,2 @@
|
||||
# 使用项目内 store,避免本机全局 store 目录(D:\.pnpm-store)的写权限问题
|
||||
store-dir=.pnpm-store
|
||||
@@ -0,0 +1,629 @@
|
||||
# LFSpecs 设计稿(v0.2)
|
||||
|
||||
> 公开硬件规格库。收录手机、平板、电脑、SoC/CPU/GPU、外设等设备配置,页面只读展示,编辑需简单验证,AI 辅助补全参数。
|
||||
> 本文档是设计稿,已确认的决策见第 11 节。
|
||||
|
||||
---
|
||||
|
||||
## 1. 一句话定位
|
||||
|
||||
一个**公开的硬件规格数据库**:像产品库一样浏览任何设备的详细参数,像编辑器一样低成本录入,像 Git 仓库一样可靠备份。
|
||||
|
||||
不是"我的设备清单",是"设备参数百科"——收录的是**产品型号**,不是某个人的资产。因此不记录购入价格、购买渠道、个人持有状态、使用心得。
|
||||
|
||||
**目标**
|
||||
- 录入快:给个型号,AI 把参数表填好并按置信度分级,人只核对低置信度部分。
|
||||
- 参数全:细到摄像头传感器型号、振动马达型号、扬声器单元规格。
|
||||
- 浏览爽:分类、品牌、搜索、筛选、多设备横向对比,手机端也能看。
|
||||
- 运维轻:单机/单容器可跑,数据是几个文件,拷走即迁移。
|
||||
- 只读安全:访客看不到任何编辑入口,写操作必须过一道验证。
|
||||
|
||||
**非目标(明确不做)**
|
||||
- 不做多用户注册体系 / 权限角色矩阵(只有一个"站主"身份)。
|
||||
- 不做社区、评论、点赞、投稿。
|
||||
- 不做实时价格抓取、电商比价(AI 查询是"补参数",不是"追价格")。
|
||||
- 不做个人资产台账(无购入价、无保修期、无转卖记录)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 技术选型
|
||||
|
||||
| 层 | 选择 | 理由 |
|
||||
|---|---|---|
|
||||
| 框架 | **Astro 5** | 默认零 JS、内容型站点最优;需要交互时用 islands 局部加载;内置图片优化、View Transitions |
|
||||
| 样式 | **Tailwind CSS 4** | 与 shadcn 生态绑定,v4 走 `@tailwindcss/vite` 插件,无需 config 文件 |
|
||||
| 组件 | **shadcn/ui** | 注意:它是 React 组件库,Astro 下需 `@astrojs/react` 集成,以 island 形式使用;纯展示区域仍可写 `.astro` 组件 |
|
||||
| 校验 | **Zod** | 数据模型单一事实来源,表单、API、导入导出、AI 输出全部复用同一套 schema |
|
||||
| 动效 | **Motion (原 framer-motion)** + Astro View Transitions | 见第 7 节 |
|
||||
| 数据库 | **SQLite**(方案 A,见第 4 节) | 单文件、零运维、备份即拷贝;实现用 Node 内置 `node:sqlite`,无原生编译依赖 |
|
||||
| 存储 | 本地磁盘 + S3 兼容(双驱动,见 9.1) | 先本地跑通,需要时一键切对象存储 |
|
||||
| 语言 | TypeScript strict | — |
|
||||
| 包管理 | pnpm | — |
|
||||
|
||||
**需要提前踩的点**
|
||||
- shadcn/ui 在 Astro 中是"部分适配":`npx shadcn@latest init` 需选 Astro 选项(依赖 React 集成)。如果发现处处别扭,备选是只借它的**设计 token + Radix 无样式组件**,自己写 Astro 包装,或改用纯 Tailwind 手写组件。**建议先做一个 3 个组件的 PoC 验证,再决定全量采用。**
|
||||
- Tailwind v4 的 `@theme` 写法与 shadcn 旧版 HSL 变量不同,初始化时注意版本一致。
|
||||
|
||||
---
|
||||
|
||||
## 3. 页面与功能
|
||||
|
||||
### 3.1 路由
|
||||
|
||||
```
|
||||
/ 首页:分类入口 + 最新收录 + 热门对比
|
||||
/devices 设备列表(分类 Tab + 品牌筛选 + 搜索 + 排序)
|
||||
/devices/[slug] 设备详情:主图 + 关键参数网格 + 分组规格表 + 关联芯片 + 图库
|
||||
/brands 品牌索引
|
||||
/brands/[brand] 品牌下全部产品
|
||||
/chips 芯片库(SoC / CPU / GPU / NPU / 模组)
|
||||
/chips/[slug] 芯片详情 + "搭载该芯片的设备"反查列表
|
||||
/peripherals 外设列表(显示器/键鼠/耳机/存储/网络/掌机配件)
|
||||
/compare?ids=a,b,c 横向对比(2–4 个,同类别限定,差异高亮)
|
||||
/admin 登录入口
|
||||
/admin/devices/[slug] 编辑表单
|
||||
/admin/import 批量导入导出
|
||||
/api/* 写接口、AI 接口、导出接口
|
||||
```
|
||||
|
||||
> 已去掉 `/timeline`(个人时间线属于私人内容),改为 `/brands` 索引,更符合公开数据库的浏览路径。
|
||||
|
||||
### 3.2 详情页信息布局(以手机为例)
|
||||
|
||||
- 头部:品牌 / 型号 / 别名 / 发布与上市日期 / 生命周期徽章(已发布·在售·停产)/ 封面图
|
||||
- 关键参数卡(6–8 个最重要项,大字号):SoC、屏幕、电池、主摄、重量、存储
|
||||
- 分组规格表:外观 / 屏幕 / 平台 / 内存存储 / 后置影像 / 前置影像 / 音频与震动 / 连接 / 电池充电 / 传感器 / 系统
|
||||
- 关联:同 SoC 的其他机型、同代竞品入口(一键加入对比)
|
||||
- 底部:数据来源与更新时间、字段级置信度说明
|
||||
|
||||
### 3.3 对比页设计要点
|
||||
|
||||
- 入口:列表勾选 / 详情页"加入对比"浮动条 / 直接拼 URL
|
||||
- 顶部设备头图错位排列,便于识别
|
||||
- 表格:首列字段名粘性,横向滚动;移动端可左右滑动查看设备
|
||||
- 开关:**只看差异**、分组折叠
|
||||
- 值对齐:数值化拆分(`6.79 英寸` → 6.79 + 单位),支持条形长度可视化(电池容量、屏幕亮度、重量)
|
||||
- 同类别才能对比(手机 vs 手机、显卡 vs 显卡),跨类别给出提示
|
||||
|
||||
### 3.4 增强想法(可后置)
|
||||
|
||||
- **自动 OG 图**:每台设备生成分享卡片(satori / `@vercel/og`)
|
||||
- **雷达图**:屏幕/性能/续航归一化评分可视化
|
||||
- **结构化数据**:每页输出 `Product` JSON-LD,利于搜索引擎收录(公开站必备)
|
||||
- **sitemap + RSS**:新收录设备可订阅
|
||||
- **完整性提示**:后台将"缺关键字段"的设备标黄,引导补全
|
||||
- **打印样式**:详情页可导出为干净的 PDF 规格表
|
||||
- **Changelog**:每次编辑生成一条记录,公开可见(体现数据可追溯)
|
||||
|
||||
---
|
||||
|
||||
## 4. 数据层:三套方案(关键决策)
|
||||
|
||||
这是整个项目最需要先定的事,因为它决定部署方式、备份方式、编辑方式。
|
||||
|
||||
### ✅ 方案 A:Astro SSR + SQLite(已采纳)
|
||||
|
||||
- 部署:`@astrojs/node` adapter,Docker 单容器;数据 = `data/app.db` + `data/uploads/`,挂载卷。
|
||||
- 备份:`scripts/backup.sh` 执行 `sqlite3 .backup` + 打包 uploads → 一个 `.tar.gz`。
|
||||
- 迁移:换机器 = 拷目录 + 起容器。
|
||||
- 编辑:`/admin` 表单直接写库,密码 cookie 会话。
|
||||
- 优点:网页端可编辑;单文件备份;无外部依赖。
|
||||
- 缺点:需要一台长期在线的机器(VPS / NAS / 树莓派);SQLite 单写入者,够用但不适合高并发。
|
||||
|
||||
### 方案 B:纯静态 + 数据即仓库(最轻运维)
|
||||
|
||||
- 数据存 `src/content/devices/*.md(x)` 或 `data/*.json`,走 Astro Content Collections + zod。
|
||||
- 部署:任意静态托管(Cloudflare Pages / GitHub Pages / 对象存储 / NAS 静态目录)。
|
||||
- 备份:Git 仓库本身就是备份与版本历史,零成本。
|
||||
- 编辑:本地 `pnpm admin` 起一个仅本机可访问的编辑表单,保存后自动 `git commit`;或直接改 JSON + VS Code。
|
||||
- 优点:部署最快、成本≈0、天然版本管理、迁移=clone。
|
||||
- 缺点:**网页端不能改**(除非引入 Decap CMS/TinaCMS,那又需要一个 Git 网关/服务)。
|
||||
|
||||
### 方案 C:静态 + Cloudflare D1/R2 + Workers 写接口
|
||||
|
||||
- 页面静态化,写操作走 Worker + 密码;图片进 R2。
|
||||
- 优点:零运维、全球加速、免费额度够个人用。
|
||||
- 缺点:数据落在 Cloudflare,备份靠 `d1 export`(能做,但迁移到非 CF 环境要多一步)。
|
||||
|
||||
### 结论(已确认)
|
||||
|
||||
采纳 **方案 A**:VPS/NAS 上 Docker 单容器,Astro SSR(`@astrojs/node`)+ SQLite,浏览器内直接编辑。
|
||||
|
||||
- 数据访问仍收敛到单一 repository 层(`src/lib/repo.ts` 暴露 `listDevices/getDevice/saveDevice/...`),未来若想迁到 B/C 只改这一层。
|
||||
- 保留 B/C 的价值:**A 必须能导出一份完整 JSON**,这样随时可以降级为静态站(导出 → 生成 content collection → 静态构建)。这个导出能力不是可选项,是方案 A 的逃生舱。
|
||||
|
||||
### 4.1 目录结构
|
||||
|
||||
```
|
||||
LFSpecs/
|
||||
├─ src/
|
||||
│ ├─ pages/
|
||||
│ │ ├─ index.astro
|
||||
│ │ ├─ devices/index.astro · [slug].astro
|
||||
│ │ ├─ chips/index.astro · [slug].astro
|
||||
│ │ ├─ peripherals/index.astro
|
||||
│ │ ├─ compare.astro
|
||||
│ │ ├─ timeline.astro
|
||||
│ │ ├─ admin/…(login / devices/[slug] / import)
|
||||
│ │ └─ api/(auth, devices, ai, export, import)
|
||||
│ ├─ components/ # .astro 为主,交互的才用 .tsx
|
||||
│ ├─ lib/
|
||||
│ │ ├─ repo.ts # 唯一数据出入口
|
||||
│ │ ├─ db.ts # sqlite 连接 + 迁移
|
||||
│ │ ├─ schema/ # zod:device / chip / specs 各分类 + FieldMeta
|
||||
│ │ ├─ storage.ts # 图片存储抽象(local / s3)
|
||||
│ │ ├─ ai/ # provider 抽象 + prompt + 结果校验
|
||||
│ │ └─ auth.ts # 签发/校验 cookie
|
||||
│ ├─ content/ # 可选:markdown 长文
|
||||
│ └─ styles/
|
||||
├─ data/ # 运行时数据(不进 git)
|
||||
│ ├─ app.db
|
||||
│ └─ uploads/
|
||||
├─ scripts/backup.ts
|
||||
├─ migrations/
|
||||
├─ Dockerfile
|
||||
└─ docker-compose.yml
|
||||
```
|
||||
|
||||
### 4.2 表结构(SQLite)
|
||||
|
||||
```sql
|
||||
CREATE TABLE devices (
|
||||
id INTEGER PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
category TEXT NOT NULL, -- phone/tablet/laptop/desktop/handheld/peripheral
|
||||
sub_category TEXT, -- 外设细分:monitor/keyboard/mouse/...
|
||||
brand TEXT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
aliases_json TEXT DEFAULT '[]', -- 别名 / 地区型号,参与搜索
|
||||
announce_date TEXT,
|
||||
release_date TEXT,
|
||||
lifecycle TEXT NOT NULL DEFAULT 'released', -- announced/released/discontinued
|
||||
cover_key TEXT, -- 存储 key,不是 URL
|
||||
gallery_json TEXT DEFAULT '[]', -- 存储 key 数组
|
||||
tags_json TEXT DEFAULT '[]',
|
||||
summary TEXT, -- 客观简介
|
||||
specs_json TEXT NOT NULL, -- 分类规格,zod 校验后写入
|
||||
chip_refs_json TEXT DEFAULT '{}', -- {soc,cpu,gpu,npu,modem} -> chip.slug
|
||||
meta_json TEXT DEFAULT '[]', -- FieldMeta[]:字段级置信度与来源
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE chips (
|
||||
id INTEGER PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL, type TEXT NOT NULL, -- soc/cpu/gpu/npu/modem
|
||||
brand TEXT, model TEXT NOT NULL, codename TEXT,
|
||||
aliases_json TEXT DEFAULT '[]',
|
||||
process TEXT, arch TEXT,
|
||||
detail_json TEXT NOT NULL, -- 核心簇/显存/跑分等,结构随 type 变化
|
||||
meta_json TEXT DEFAULT '[]',
|
||||
created_at TEXT, updated_at TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE revisions ( -- 每次保存一条,用于回滚与 changelog
|
||||
id INTEGER PRIMARY KEY,
|
||||
entity TEXT NOT NULL, -- 'device' | 'chip'
|
||||
entity_id INTEGER NOT NULL,
|
||||
snapshot_json TEXT NOT NULL, -- 保存后的完整态
|
||||
diff_json TEXT, -- 与上版差异,便于展示
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE ai_cache ( -- 省钱用
|
||||
key TEXT PRIMARY KEY, -- category|brand|model
|
||||
result_json TEXT NOT NULL,
|
||||
sources_json TEXT, created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE ai_drafts ( -- AI 结果先进草稿态,人工确认后才 merge
|
||||
id INTEGER PRIMARY KEY, device_id INTEGER,
|
||||
payload_json TEXT NOT NULL, sources_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'pending', created_at TEXT
|
||||
);
|
||||
|
||||
CREATE INDEX idx_devices_cat ON devices(category);
|
||||
CREATE INDEX idx_devices_brand ON devices(brand);
|
||||
CREATE INDEX idx_chips_type ON chips(type);
|
||||
```
|
||||
|
||||
> `specs_json` 用 JSON 列而非拆表:参数随代际变化大,拆表会陷入持续迁移。`json_extract` 足够应付筛选(如 `WHERE json_extract(specs_json,'$.display.refreshRate') >= 120`)。筛选需求变重时再加 `spec_index` 辅助表,把热门可筛字段(刷新率/容量/尺寸/重量)打平。
|
||||
|
||||
### 4.3 部署产物
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
ports: ["3000:3000"]
|
||||
volumes: ["./data:/app/data"]
|
||||
environment:
|
||||
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
|
||||
SESSION_SECRET: ${SESSION_SECRET}
|
||||
AI_BASE_URL: ${AI_BASE_URL}
|
||||
AI_API_KEY: ${AI_API_KEY}
|
||||
AI_MODEL: ${AI_MODEL}
|
||||
SEARCH_API_KEY: ${SEARCH_API_KEY}
|
||||
STORAGE_DRIVER: ${STORAGE_DRIVER} # local | s3
|
||||
# s3 时追加:S3_ENDPOINT / S3_BUCKET / S3_REGION / S3_KEY / S3_SECRET / S3_PUBLIC_BASE_URL
|
||||
```
|
||||
|
||||
迁移到新机器:`tar` 打包 `data/` → 拷贝 → `docker compose up -d`。
|
||||
|
||||
---
|
||||
|
||||
## 5. 数据模型
|
||||
|
||||
### 5.1 设计取向
|
||||
|
||||
公开规格库的核心诉求是**可比**,所以:
|
||||
|
||||
- **强模板 + 可扩展**:每个 category 一套 zod schema 定义核心字段(保证任意两台同类设备都能逐行对齐),另留 `extra: Record<string,string>` 收纳长尾参数。不再"弱 schema"——对比页依赖字段一致性。
|
||||
- **字段级元数据**:每个值都能携带 `confidence / sourceUrl / verified / capturedAt`。这是 AI 分级录入的基础,也是公开展示"数据可信度"的依据。
|
||||
- **产品导向**:只记录产品客观参数,不含购入价、个人评价、持有状态。
|
||||
|
||||
### 5.2 实体
|
||||
|
||||
**Device(设备)** — 手机、平板、笔记本、台式机、掌机、外设统一入口,用 `category` 区分。
|
||||
|
||||
```ts
|
||||
Device {
|
||||
id, slug
|
||||
category: 'phone' | 'tablet' | 'laptop' | 'desktop' | 'handheld' | 'peripheral'
|
||||
subCategory? // 外设细分:monitor/keyboard/mouse/headset/storage/network
|
||||
brand, model
|
||||
aliases: string[] // 别名、地区型号(如 "Xiaomi 14 / 小米14")
|
||||
announceDate?, releaseDate?
|
||||
lifecycle: 'announced' | 'released' | 'discontinued'
|
||||
cover?, gallery: string[] // 存 storage key,不是绝对 URL
|
||||
tags: string[]
|
||||
summary? // 客观简介(AI 可生成,人工可改)
|
||||
specs: PhoneSpecs | LaptopSpecs | DesktopSpecs | GpuSpecs | ...
|
||||
chipRefs: { soc?, cpu?, gpu?, npu?, modem? } // -> Chip.slug
|
||||
meta: FieldMeta[] // 字段级来源与置信度
|
||||
createdAt, updatedAt
|
||||
}
|
||||
```
|
||||
|
||||
**Chip(芯片)** — 独立实体,设备通过 `chipRefs` 引用,支持反查"搭载该芯片的机型"。
|
||||
|
||||
```ts
|
||||
Chip {
|
||||
id, slug
|
||||
type: 'soc' | 'cpu' | 'gpu' | 'npu' | 'modem'
|
||||
brand, model, codename?, aliases: string[]
|
||||
process: string // "TSMC N4P"
|
||||
arch: string // "ARMv9.2" / "Zen 5" / "Blackwell"
|
||||
// SoC 专属
|
||||
cpuClusters?: { name, cores: { microArch, count, clockMax, l1, l2 }[], l3 }[]
|
||||
gpuBlock?: { name, arch, cores, clockMax, apis[] }
|
||||
npuBlock?: { name, tops? }
|
||||
ispBlock?, dspBlock?, modemBlock?
|
||||
memorySupport?, storageSupport?, displaySupport?, videoCodec?
|
||||
// CPU / GPU 专属
|
||||
cores?, threads?, clocks?, cache?
|
||||
smCount?, rtCores?, tensorCores?
|
||||
memory?: { type, capacity, busWidth, bandwidth }
|
||||
tdp?, pcie?, powerConnectors?
|
||||
benchmarks: { name, score, unit }[]
|
||||
features: string[]
|
||||
meta: FieldMeta[]
|
||||
createdAt, updatedAt
|
||||
}
|
||||
```
|
||||
|
||||
**FieldMeta(字段元数据)** — 与 AI 分级机制配套。
|
||||
|
||||
```ts
|
||||
FieldMeta {
|
||||
path: string // "specs.rearCamera[0].sensorModel"
|
||||
confidence: 'high' | 'medium' | 'low'
|
||||
sourceUrl?: string
|
||||
verified: boolean // 人工确认过
|
||||
capturedAt: string
|
||||
}
|
||||
```
|
||||
|
||||
**Revision / ai_cache / ai_drafts** — 与 4.2 节的表一致。
|
||||
|
||||
### 5.3 手机规格模板(细化版)
|
||||
|
||||
```ts
|
||||
PhoneSpecs {
|
||||
body: {
|
||||
dimensions, weight, build: { front, back, frame },
|
||||
sim, ipRating, colors[], buttons
|
||||
}
|
||||
display: {
|
||||
size, resolution, aspectRatio, panel,
|
||||
refreshRate, refreshRange, // "1-120Hz"
|
||||
touchSampling, brightnessTypical, brightnessPeak,
|
||||
hdr, protection, // "康宁大猩猩 Victus 2"
|
||||
pwmDimming, // "2160Hz PWM"
|
||||
alwaysOn
|
||||
}
|
||||
platform: { os, skin, chipset }
|
||||
memory: { ram, ramType, storage, storageType, cardSlot }
|
||||
rearCamera: CameraModule[]
|
||||
frontCamera: CameraModule[]
|
||||
vibration: { type, model?, size? } // 马达:X轴/Z轴线性、转子;型号如 "AAC 0809"
|
||||
speakers: {
|
||||
count, stereo, units: { model?, size?, power? }[],
|
||||
dolbyAtmos, hiRes, loudnessDba?,
|
||||
headphoneJack
|
||||
}
|
||||
connectivity: { cellular, wifi, bluetooth, nfc, gps, usb, ir, uwb }
|
||||
battery: { capacity, type, wired, wireless, reverse, chargingProtocol }
|
||||
sensors: {
|
||||
fingerprint, fingerprintType, fingerprintPosition,
|
||||
gyro, barometer, colorSensor, flickerSensor, sar, ...
|
||||
}
|
||||
software: { launchVersion, currentVersion, updatePolicy }
|
||||
extra: Record<string, string>
|
||||
}
|
||||
|
||||
CameraModule {
|
||||
position: 'wide' | 'ultrawide' | 'tele' | 'periscope' | 'macro' | 'depth' | 'mono' | 'front'
|
||||
sensorModel? // "Sony IMX890"
|
||||
resolution, aperture, focalLength, sensorSize, pixelSize,
|
||||
lensElements, // "7P"
|
||||
ois, eis,
|
||||
zoom?, // "3x 光学 / 30x 数码"
|
||||
autofocusType?, // "双像素 PDAF / 激光对焦"
|
||||
video: { max, modes[], stabilization } // max: "8K@24fps"
|
||||
flash?
|
||||
extra
|
||||
}
|
||||
```
|
||||
|
||||
**关键点:多摄必须逐颗建模**,不能在 `camera` 里塞一个字符串数组。每颗摄像头独立一条记录,才能做出"主摄 IMX890 + 长焦 OV64B + 超广角 JN1"这种可检索、可对比的结构。
|
||||
|
||||
**其他模板**
|
||||
|
||||
- 笔记本:`display / cpu / gpu / memory / storage / keyboard / touchpad / ports / battery / thermal / speakers / webcam / wifi / weight / build`
|
||||
- 台式机:`cpu / gpu / motherboard / memory / storage / psu / case / cooling / ports`
|
||||
- 显卡:`arch / shaders / rtCores / tensorCores / memory(类型·容量·位宽·带宽) / bus / tdp / powerConnectors / outputs / pcie / dimensions / cooling`
|
||||
- 外设(按 subCategory 再分套模板):显示器 `panel/size/resolution/refreshRate/responseTime/brightness/contrast/colorGamut/hdr/ports/stand`;键盘 `layout/switch/actuation/travel/keycap/connection/battery`;鼠标 `sensor/dpi/reportRate/buttons/weight/connection`;耳机 `driver/impedance/frequencyResponse/anc/battery/codecs`;存储 `capacity/interface/seqRead/seqWrite/tbw/nand`。
|
||||
|
||||
### 5.4 对比逻辑
|
||||
|
||||
1. 校验同 `category`(外设再校验同 `subCategory`),2–4 台。
|
||||
2. 取各设备 specs 的扁平化路径并集,按模板定义的字段顺序排序(模板里就是渲染顺序)。
|
||||
3. 值比较前做**归一化**:拆成 `{ num, unit, raw }`,数值类字段(电池容量、屏幕亮度、重量、跑分)可用于排序与条形可视化。
|
||||
4. 不同则高亮;缺失显示 `—` 并置灰。
|
||||
5. 支持"只看差异"过滤与分组折叠。
|
||||
|
||||
---
|
||||
|
||||
## 6. 编辑验证("简单验证")
|
||||
|
||||
不做用户系统,只做**单密钥**:
|
||||
|
||||
1. 环境变量 `ADMIN_PASSWORD`(哈希后存,不存明文)。
|
||||
2. `POST /api/auth/login` → 校验 → 签发 **HttpOnly + SameSite=Lax + Secure** cookie,内含签名 token(`jose`,有效期 7 天)。
|
||||
3. 中间件保护 `/admin/*` 与所有写接口。
|
||||
4. `POST` 接口校验 `Origin`,防 CSRF;登录接口做 IP 级限速(3 次/分钟)。
|
||||
5. 可选:TOTP 二次验证(`otpauth`),10 行代码,愿意的话加上更稳。
|
||||
|
||||
> 关键原则:**读接口全部公开、无鉴权、可被 CDN 缓存**;只有写接口和 AI 接口需要 token。AI 接口也要鉴权,否则会被人刷爆额度。
|
||||
|
||||
---
|
||||
|
||||
## 7. AI 能力设计
|
||||
|
||||
> ✅ 已采纳:**OpenAI 兼容协议 + 独立搜索 API(Tavily/Exa)**。
|
||||
|
||||
### 7.1 三类能力,按优先级
|
||||
|
||||
1. **参数补全(P0)**:输入 `品牌 + 型号`,返回该分类的完整 specs JSON,每个字段带置信度与来源。
|
||||
2. **纠错/查缺(P1)**:指向已有设备,AI 对比公开资料指出错误字段与缺失字段。
|
||||
3. **文案生成(P2)**:生成客观简介与规格要点摘要(只写客观卖点,不写个人体验)。
|
||||
4. (可选)**自然语言查询(P3)**:`"哪些手机支持 144Hz 且重量低于 190g"` → 转结构化筛选条件。
|
||||
|
||||
### 7.2 工程约束(很重要)
|
||||
|
||||
- **绝不静默入库**:AI 返回 → zod 校验 → 按置信度分级预填 → 人工核对 → 保存。AI 输出永远先落"草稿态"。
|
||||
- **必须联网**:硬件参数迭代快,纯模型记忆幻觉严重。需要给模型接搜索工具(Tavily / Exa / Brave Search / 模型自带 web search)。
|
||||
- **字段级来源**:每批 AI 结果附带 URL;写入 `meta[]`,详情页用"已核实 / 待核实"徽章区分。
|
||||
- **缓存**:以 `category+brand+model` 为 key 存到 `ai_cache`,避免重复付费。
|
||||
- **供应商可换**:统一走 **OpenAI 兼容协议**(`baseURL` + `apiKey` + `model` 三个环境变量),可切 OpenAI / DeepSeek / 通义 / Kimi / 本地 Ollama。
|
||||
- **结构化输出**:优先用 JSON Schema 模式(`response_format: json_schema`),失败则退回"JSON + zod 修复一轮"。
|
||||
- **成本**:单次补全预计 1–3k tokens 输入;加缓存后日常开销可忽略。
|
||||
|
||||
### 7.3 置信度分级(核心机制)
|
||||
|
||||
AI 必须为**每个字段**输出置信度,前端据此决定默认行为:
|
||||
|
||||
| 级别 | 判定依据 | 前台行为 | 保存行为 |
|
||||
|---|---|---|---|
|
||||
| `high` | 官方规格页原文,或 ≥2 个独立来源一致 | 自动填入,绿色徽章 | 可直接保存 |
|
||||
| `medium` | 单一非官方来源(评测、数据库站),或由多个字段推导 | 预填,黄色徽章 + "待核对" | 可保存,但记录为未核实 |
|
||||
| `low` | 模型推测、无出处、字段冲突 | 预填但标红,折叠进"待确认"区 | **阻塞保存**,必须逐项确认或清空 |
|
||||
| 无 | 未找到 | 留空 | — |
|
||||
|
||||
交互要求:
|
||||
- 每个字段右侧一个小徽章,hover 显示来源链接与抓取时间。
|
||||
- 顶部固定条显示"共 N 项待核对",点击跳到首个 `low` 项。
|
||||
- 批量操作:"全部接受 high"、"清空全部 low"。
|
||||
- 保存后 `verified` 按用户是否手动确认置位;详情页据此显示数据可信度。
|
||||
|
||||
### 7.4 接口草案
|
||||
|
||||
```
|
||||
POST /api/ai/lookup { category, brand, model }
|
||||
-> { fields: { path, value, confidence, sourceUrl? }[], sources: Url[], cached: boolean }
|
||||
|
||||
POST /api/ai/audit { deviceId }
|
||||
-> { issues: { path, expected, current, confidence, sourceUrl? }[] }
|
||||
|
||||
POST /api/ai/summary { deviceId }
|
||||
-> { summary, highlights: string[] }
|
||||
```
|
||||
|
||||
`fields` 用**扁平路径**而非嵌套对象:前端可以直接按 `path` 合入、高亮、着色,不必维护两套结构树。
|
||||
|
||||
---
|
||||
|
||||
## 8. 动效与视觉
|
||||
|
||||
### 8.1 选型建议(✅ 已采纳克制型)
|
||||
|
||||
| 用途 | 方案 | 说明 |
|
||||
|---|---|---|
|
||||
| 页面切换 | **Astro View Transitions**(`transition:animate`) | 零依赖,自带淡入/滑动 |
|
||||
| 列表渐入、卡片悬停 | **Motion**(`motion/react`,在 island 内) | `useInView` + `stagger`,体积约 30KB |
|
||||
| 数字滚动(跑分/容量) | 自写 20 行 hook | 不必引第三方 |
|
||||
| 滚动叙事(首页 hero) | **GSAP + ScrollTrigger**(可选,仅首页懒加载) | 只在确实需要"一段横向滑动叙事"时才引 |
|
||||
| 平滑滚动 | **Lenis**(可选) | 谨慎:会干扰可访问性,建议不开 |
|
||||
| 骨架屏/加载 | 纯 CSS | — |
|
||||
|
||||
**结论:主用 Astro View Transitions + Motion;GSAP 作为可选增强,不默认引入**,避免三套动效库打架。
|
||||
|
||||
### 8.2 视觉方向
|
||||
|
||||
- 深色为主、浅色可选;中性灰底 + 单一强调色(如青绿/琥珀)。
|
||||
- 大字号型号名 + 等宽字体的参数值(`font-variant-numeric: tabular-nums`),参数表对齐才好看。
|
||||
- 卡片:细边框 + 极轻内发光,悬停时 1px 描边渐亮,不做夸张投影。
|
||||
- 图片:设备正面照统一裁切比例(4:3 / 1:1),列表用同一角度,视觉更整齐。
|
||||
|
||||
---
|
||||
|
||||
## 9. 存储、部署与备份
|
||||
|
||||
### 9.1 图片存储驱动(本地 + 对象存储,双支持)
|
||||
|
||||
抽一层接口,默认本地,配置项一改就切对象存储:
|
||||
|
||||
```ts
|
||||
interface StorageDriver {
|
||||
put(key: string, buf: Buffer, contentType: string): Promise<void>
|
||||
delete(key: string): Promise<void>
|
||||
publicUrl(key: string): string
|
||||
}
|
||||
```
|
||||
|
||||
- **`local`**:写 `data/uploads/`,URL 走 `/uploads/*`,由 Astro 端点或静态服务返回。
|
||||
- **`s3`**:S3 兼容协议(AWS S3 / Cloudflare R2 / MinIO / Backblaze B2),配置 `endpoint / bucket / region / accessKey / secretKey / publicBaseUrl`。
|
||||
- **环境变量**:`STORAGE_DRIVER=local|s3`,其余按驱动按需读取。
|
||||
|
||||
**关键约束:数据库只存 key,绝不存绝对 URL。** 这样换驱动、换域名时数据完全不用改(`Device.cover` 存 `devices/xxx/cover.webp`,渲染时由 driver 生成 URL)。
|
||||
|
||||
- 上传即处理:`sharp` 生成 3 档(原图 / 1600w / 400w 缩略),转 WebP,原图保留。
|
||||
- 对象存储的 `publicBaseUrl` 可以是 CDN 域名。
|
||||
|
||||
### 9.2 备份与迁移的差异
|
||||
|
||||
| 驱动 | 备份方式 | 说明 |
|
||||
|---|---|---|
|
||||
| local | `tar` 打包 `data/`(db + uploads) | 一份包即全量,最省心 |
|
||||
| s3 | `sqlite3 .backup` + `rclone sync` 桶 | 两部分,脚本里分两条路径 |
|
||||
|
||||
### 9.3 方案 A 落地细节
|
||||
|
||||
```
|
||||
docker-compose.yml
|
||||
volumes: ./data:/app/data
|
||||
```
|
||||
|
||||
- `data/app.db`(SQLite)、`data/uploads/`(图片)
|
||||
- **备份**:`pnpm backup` → `sqlite3 .backup` + tar → `backups/2026-10-30.tar.gz`
|
||||
- **迁移**:新机器解包 → `docker compose up -d` → 完成
|
||||
- **导出**:`GET /api/export` 输出版本化的全量 JSON(含 `formatVersion`),作为长期归档格式
|
||||
- **定时**:cron / 计划任务每日备份,保留 7 份轮转
|
||||
|
||||
> 使用 s3 驱动时,"图片随备份一起走"的前提消失,必须单独确认 `rclone sync` 是否成功——备份脚本要把两条路径的结果都打进日志。
|
||||
|
||||
### 9.4 必备的两条逃生通道
|
||||
|
||||
- `GET /api/export` 全量 JSON(含 `formatVersion`),用于跨方案迁移或降级为静态站
|
||||
- `POST /admin/import` 导入并 zod 校验,拒绝脏数据
|
||||
|
||||
---
|
||||
|
||||
## 10. 分期
|
||||
|
||||
| 阶段 | 内容 | 产出 |
|
||||
|---|---|---|
|
||||
| M0 | 脚手架、Tailwind、shadcn PoC(3 个组件)、zod schema、storage 驱动、repo 层 | 能跑的空站 |
|
||||
| M1 | 只读:手机列表/详情、芯片库、搜索筛选 + sitemap、JSON-LD | 可看、可收录的站 |
|
||||
| M2 | 编辑:登录、表单(含字段级徽章)、图片上传、修订记录 | 可维护 |
|
||||
| M3 | AI 分级补全(high 自动 / medium 标黄 / low 阻塞)+ 差异预览 | 录入效率 |
|
||||
| M4 | 对比页(差异高亮、只看差异、条形可视化)、导出导入、备份脚本 | 完整闭环 |
|
||||
| M5 | 动效打磨、OG 图、打印样式、部署上线 | 成品 |
|
||||
|
||||
---
|
||||
|
||||
## 11. 决策记录
|
||||
|
||||
| # | 决策 | 结论 | 影响 |
|
||||
|---|---|---|---|
|
||||
| D1 | 部署与数据层 | **方案 A**:VPS/NAS + Docker + Astro SSR + SQLite | 需要一台常开机器;浏览器内可编辑;备份=tar |
|
||||
| D2 | AI 接入 | **OpenAI 兼容 + 独立搜索 API** | 多一个 `SEARCH_API_KEY`;参数可追溯来源 |
|
||||
| D3 | 组件库 | **先 PoC(Button/Card/Dialog)再定** | M0 先验证 Astro + shadcn 手感,不急着全量采用 |
|
||||
| D4 | 动效 | **克制型**:View Transitions + Motion,不引 GSAP/Lenis | 首页不做滚动叙事,包体小 |
|
||||
| D5 | 站点定位 | **公开展示的规格库**,收录任意型号,非个人资产 | 移除购入价/持有状态/时间线;加品牌页、JSON-LD、sitemap |
|
||||
| D6 | 录入分级 | **high 自动填入 / medium 预填+标黄 / low 预填+阻塞保存** | schema 需 `FieldMeta`;表单需置信度徽章与待核对汇总 |
|
||||
| D7 | 图片存储 | **本地 + S3 双驱动,DB 只存 key** | 存储抽象层;备份分两条路径 |
|
||||
| D8 | 芯片 | **独立实体**,设备页引用并可展开、跳转、反查 | 多一张 chips 表与一套维护流程 |
|
||||
| D9 | 对比 | **同类别 2–4 台**,差异高亮、只看差异、数值条形化 | specs 需强模板与数值归一化 |
|
||||
| D10 | 参数颗粒度 | **细到传感器型号 / 马达型号 / 扬声器单元** | 手机模板需多摄逐颗建模,录入成本上升(由 AI 缓解) |
|
||||
|
||||
### 11.1 已确认 / 待确认
|
||||
|
||||
**已确认**
|
||||
- 语言:**仅中文**,不做多语言;参数值保留英文原文(`LPDDR5X-8533`)。
|
||||
- 首批范围:**只做手机 + 芯片(SoC)**,笔记本/台式/显卡/外设的模板与路由先留空壳后置。
|
||||
|
||||
**待确认**
|
||||
1. **站点名**:见第 12 节的候选,选定后要查域名与商标。
|
||||
2. **数据来源声明**:页脚是否常驻"数据由人工与 AI 辅助整理,仅供参考"?(建议加,公开站需要)。
|
||||
3. **是否允许被搜索引擎收录**:公开站默认是,但如果初期数据还不完整,可以先 `noindex` 到 M5 再放开。
|
||||
|
||||
### 11.2 下一步(M0 开工清单)
|
||||
|
||||
1. `pnpm create astro`(SSR)+ Tailwind v4 + `@astrojs/node` + `@astrojs/react`
|
||||
2. shadcn PoC:装 Button / Card / Dialog,写一页 demo 验证手感
|
||||
3. `src/lib/schema/`:先只做 **phone** 与 **soc** 两套 zod + `FieldMeta`
|
||||
4. `src/lib/storage.ts`:`local` 驱动先实现,`s3` 留接口
|
||||
5. `src/lib/db.ts` + `migrations/001_init.sql`(第 4.2 节表结构)
|
||||
6. `src/lib/repo.ts` 骨架 + 可跑通的 `/devices` 列表页(先读种子数据)
|
||||
7. Dockerfile / docker-compose,验证卷挂载与备份脚本
|
||||
|
||||
M0 完成标志:**本地 `docker compose up` 能打开首页,`/devices` 与 `/chips` 各自从 SQLite 读出种子数据。**
|
||||
|
||||
### 11.3 M0 实施记录(已完成)
|
||||
|
||||
- 脚手架:Astro 7.4.4 + `@astrojs/node` 11(standalone)+ `@astrojs/react` 7 + Tailwind 4.3.3(`@tailwindcss/vite`)
|
||||
- 数据库:**改用 Node 内置 `node:sqlite`**(`DatabaseSync`),放弃 better-sqlite3,避免 Windows 原生编译与 Docker 交叉编译问题
|
||||
- 已落地:`schema/`(phone、soc、FieldMeta、Device/Chip 判别联合)、`db.ts`、`repo.ts`、`storage.ts`(local 已实现,s3 留接口)、`migrations/001_init.sql`、`scripts/seed.mjs`、`scripts/backup.mjs`
|
||||
- 页面:`/`、`/devices`、`/devices/[slug]`、`/chips`、`/chips/[slug]`、`/poc`、`/uploads/[...path]`
|
||||
- 验证:`pnpm build` 通过;生产产物 6 个路由全部 200、伪造 slug 返回 404;Dialog island 交互经浏览器验证可开可关;`backup.mjs` 用 `VACUUM INTO` 产出快照
|
||||
- 环境坑:本机 pnpm 全局 store `D:\.pnpm-store` 写权限不足导致 `ERR_PNPM_EPERM`,已用项目内 `.npmrc`(`store-dir=.pnpm-store`)规避
|
||||
- **未验证**:本机未安装 Docker,Dockerfile / docker-compose 未实际跑过,需在有 Docker 的环境确认
|
||||
|
||||
---
|
||||
|
||||
## 12. 站点命名(已定:LFSpecs)
|
||||
|
||||
> 已确认:对外站名用 **LFSpecs**。下表保留作为备选,仅当域名 `lfspecs.*` 不可用时再启用。
|
||||
|
||||
站名要满足三点:能表达"参数规格"、不绑定单一品类(手机/芯片/电脑都能装进去)、中文念着不别扭。
|
||||
|
||||
| 候选 | 域名建议 | 说明 | 风险 |
|
||||
|---|---|---|---|
|
||||
| **器谱** | `qipu.app` / `qipu.wiki` | "器物谱系"。一个字表,可扩展全部硬件;中文感强,不像厂商站 | 略抽象,需副标题解释 |
|
||||
| **SpecDock** | `specdock.dev` | dock = 停靠/汇总坞。英文顺口,SEO 词直白(spec 是核心搜索词) | 英文站名在国内传播弱 |
|
||||
| **机尺** | `jichi.app` | 手机 + 标尺双关,记忆点最强 | 只贴手机,扩展电脑时尴尬 |
|
||||
| **规格集** | `specset.io` | 最中性直白,永不过时,搜索友好 | 平庸,没有品牌感 |
|
||||
| **硬件谱** | `hwpu.app` | 通俗易懂,"硬件"覆盖广 | 商标与域名大概率被占 |
|
||||
|
||||
**我的建议:器谱(`qipu.app`)**,理由:
|
||||
|
||||
- "谱"天然承接"谱系/参数表",既像一个可查的表,又暗示"收录成体系",比"库""站"高级。
|
||||
- 不绑定品类——以后加显卡、外设,名字不用改;`机尺` 会卡住。
|
||||
- 两个音节,中文站点名里属于短的一档,好记也好念。
|
||||
|
||||
备选 `SpecDock`:如果你更希望技术上易被检索、且不介意英文名,它的 `spec` 前缀对 SEO 更友好。
|
||||
|
||||
> 两个都需要自己去查域名注册与商标情况,我只能给方向,无法保证可注册。选定后告诉我,我同步改 README 与文档标题。
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# ---- 依赖 ----
|
||||
FROM node:24-alpine AS deps
|
||||
WORKDIR /app
|
||||
RUN npm i -g pnpm@10.5.2
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# ---- 构建 ----
|
||||
FROM node:24-alpine AS build
|
||||
WORKDIR /app
|
||||
RUN npm i -g pnpm@10.5.2
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN pnpm build
|
||||
|
||||
# ---- 运行 ----
|
||||
FROM node:24-alpine AS runtime
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=3000
|
||||
|
||||
COPY --from=build /app/dist ./dist
|
||||
COPY --from=build /app/node_modules ./node_modules
|
||||
COPY --from=build /app/package.json ./package.json
|
||||
COPY --from=build /app/migrations ./migrations
|
||||
COPY --from=build /app/scripts ./scripts
|
||||
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
EXPOSE 3000
|
||||
CMD ["node", "./dist/server/entry.mjs"]
|
||||
@@ -1 +1,44 @@
|
||||
# LFSpecs
|
||||
|
||||
公开硬件规格库:收录手机、芯片等设备的详细参数,支持横向对比。设计文档见 [DESIGN.md](./DESIGN.md)。
|
||||
|
||||
## 技术栈
|
||||
|
||||
Astro 7(SSR / Node adapter)+ Tailwind CSS 4 + shadcn/ui(React islands)+ SQLite(`node:sqlite`,无原生依赖)
|
||||
|
||||
## 本地开发
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
cp .env.example .env # Windows: Copy-Item .env.example .env
|
||||
pnpm db:seed # 建表 + 写入种子数据(Xiaomi 14 / 骁龙 8 Gen 3)
|
||||
pnpm dev # http://localhost:4321
|
||||
```
|
||||
|
||||
组件自检页:`/poc`(验证 Button / Card / Dialog 可用,M0 验收后可删)。
|
||||
|
||||
## 部署
|
||||
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
只持久化 `./data`(`app.db` + `uploads/`),迁移时拷走这一个目录即可。
|
||||
|
||||
## 运维
|
||||
|
||||
```bash
|
||||
pnpm backup # VACUUM INTO 快照 + 打包 uploads 到 backups/<时间戳>/
|
||||
pnpm db:seed # 重跑种子数据(幂等,按 slug upsert)
|
||||
```
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
src/lib/schema/ zod 数据模型(phone / soc / FieldMeta)
|
||||
src/lib/db.ts SQLite 连接 + 迁移
|
||||
src/lib/repo.ts 唯一数据出入口
|
||||
src/lib/storage.ts 图片存储驱动(local / s3 接口)
|
||||
migrations/ SQL 迁移,按文件名顺序执行
|
||||
scripts/ seed / backup
|
||||
```
|
||||
@@ -0,0 +1,17 @@
|
||||
// @ts-check
|
||||
import { defineConfig } from 'astro/config';
|
||||
import node from '@astrojs/node';
|
||||
import react from '@astrojs/react';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({
|
||||
// TODO: 上线时改成正式域名,影响 sitemap / canonical / OG
|
||||
site: 'http://localhost:4321',
|
||||
output: 'server',
|
||||
adapter: node({ mode: 'standalone' }),
|
||||
integrations: [react()],
|
||||
vite: {
|
||||
plugins: [tailwindcss()],
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
services:
|
||||
app:
|
||||
build: .
|
||||
container_name: lfspecs
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
# 宿主 3010 -> 容器 3000(宿主 3000 已被 frps 占用)
|
||||
- "3010:3000"
|
||||
volumes:
|
||||
# 唯一需要持久化的目录:SQLite 与上传图片
|
||||
- ./data:/app/data
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DB_PATH: /app/data/app.db
|
||||
UPLOADS_DIR: /app/data/uploads
|
||||
@@ -0,0 +1,70 @@
|
||||
-- 001_init.sql:设备与芯片主表 + 修订 + AI 缓存
|
||||
-- 约定:所有 *_json 列存 JSON 文本,读写由 repo 层负责序列化
|
||||
|
||||
CREATE TABLE IF NOT EXISTS devices (
|
||||
id INTEGER PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
sub_category TEXT,
|
||||
brand TEXT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
aliases_json TEXT NOT NULL DEFAULT '[]',
|
||||
announce_date TEXT,
|
||||
release_date TEXT,
|
||||
lifecycle TEXT NOT NULL DEFAULT 'released',
|
||||
cover_key TEXT,
|
||||
gallery_json TEXT NOT NULL DEFAULT '[]',
|
||||
tags_json TEXT NOT NULL DEFAULT '[]',
|
||||
summary TEXT,
|
||||
specs_json TEXT NOT NULL,
|
||||
chip_refs_json TEXT NOT NULL DEFAULT '{}',
|
||||
meta_json TEXT NOT NULL DEFAULT '[]',
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS chips (
|
||||
id INTEGER PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
brand TEXT NOT NULL,
|
||||
model TEXT NOT NULL,
|
||||
codename TEXT,
|
||||
aliases_json TEXT NOT NULL DEFAULT '[]',
|
||||
process TEXT,
|
||||
arch TEXT,
|
||||
detail_json TEXT NOT NULL,
|
||||
meta_json TEXT NOT NULL DEFAULT '[]',
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS revisions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
entity TEXT NOT NULL,
|
||||
entity_id INTEGER NOT NULL,
|
||||
snapshot_json TEXT NOT NULL,
|
||||
diff_json TEXT,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_cache (
|
||||
key TEXT PRIMARY KEY,
|
||||
result_json TEXT NOT NULL,
|
||||
sources_json TEXT,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_drafts (
|
||||
id INTEGER PRIMARY KEY,
|
||||
device_id INTEGER,
|
||||
payload_json TEXT NOT NULL,
|
||||
sources_json TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_devices_cat ON devices(category);
|
||||
CREATE INDEX IF NOT EXISTS idx_devices_brand ON devices(brand);
|
||||
CREATE INDEX IF NOT EXISTS idx_chips_type ON chips(type);
|
||||
CREATE INDEX IF NOT EXISTS idx_revisions_entity ON revisions(entity, entity_id);
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "lfspecs",
|
||||
"type": "module",
|
||||
"version": "0.1.0",
|
||||
"engines": {
|
||||
"node": ">=22.23.4"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "astro dev",
|
||||
"build": "astro build",
|
||||
"preview": "astro preview",
|
||||
"db:seed": "node scripts/seed.mjs",
|
||||
"backup": "node scripts/backup.mjs",
|
||||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^11.1.9",
|
||||
"@astrojs/react": "^7.1.2",
|
||||
"@radix-ui/react-dialog": "^1.3.1",
|
||||
"@radix-ui/react-slot": "^1.5.0",
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"astro": "^7.4.4",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"jose": "^6.2.14",
|
||||
"lucide-react": "^1.64.0",
|
||||
"motion": "^14.8.0",
|
||||
"react": "^19.3.1",
|
||||
"react-dom": "^19.3.1",
|
||||
"tailwind-merge": "^3.7.0",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^26.6.6",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0"
|
||||
}
|
||||
}
|
||||
Generated
+3519
File diff suppressed because it is too large.
Load diff
Binary file not shown.
|
After Width: | Height: | Size: 655 B |
@@ -0,0 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 128 128">
|
||||
<path d="M50.4 78.5a75.1 75.1 0 0 0-28.5 6.9l24.2-65.7c.7-2 1.9-3.2 3.4-3.2h29c1.5 0 2.7 1.2 3.4 3.2l24.2 65.7s-11.6-7-28.5-7L67 45.5c-.4-1.7-1.6-2.8-2.9-2.8-1.3 0-2.5 1.1-2.9 2.7L50.4 78.5Zm-1.1 28.2Zm-4.2-20.2c-2 6.6-.6 15.8 4.2 20.2a17.5 17.5 0 0 1 .2-.7 5.5 5.5 0 0 1 5.7-4.5c2.8.1 4.3 1.5 4.7 4.7.2 1.1.2 2.3.2 3.5v.4c0 2.7.7 5.2 2.2 7.4a13 13 0 0 0 5.7 4.9v-.3l-.2-.3c-1.8-5.6-.5-9.5 4.4-12.8l1.5-1a73 73 0 0 0 3.2-2.2 16 16 0 0 0 6.8-11.4c.3-2 .1-4-.6-6l-.8.6-1.6 1a37 37 0 0 1-22.4 2.7c-5-.7-9.7-2-13.2-6.2Z" />
|
||||
<style>
|
||||
path { fill: #000; }
|
||||
@media (prefers-color-scheme: dark) {
|
||||
path { fill: #FFF; }
|
||||
}
|
||||
</style>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 749 B |
@@ -0,0 +1,21 @@
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { cpSync, existsSync, mkdirSync } from 'node:fs';
|
||||
|
||||
const DB_PATH = process.env.DB_PATH ?? 'data/app.db';
|
||||
const UPLOADS = process.env.UPLOADS_DIR ?? 'data/uploads';
|
||||
|
||||
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
const dir = `backups/${stamp}`;
|
||||
mkdirSync(dir, { recursive: true });
|
||||
|
||||
// VACUUM INTO 产出一致性快照,比直接拷贝 db 文件安全(WAL 模式下也有效)
|
||||
const db = new DatabaseSync(DB_PATH);
|
||||
db.exec(`VACUUM INTO '${dir}/app.db'`);
|
||||
db.close();
|
||||
|
||||
if (existsSync(UPLOADS)) {
|
||||
cpSync(UPLOADS, `${dir}/uploads`, { recursive: true });
|
||||
console.log(`已复制 uploads -> ${dir}/uploads`);
|
||||
}
|
||||
|
||||
console.log(`备份完成:${dir}`);
|
||||
@@ -0,0 +1,292 @@
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { existsSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
|
||||
const DB_PATH = process.env.DB_PATH ?? 'data/app.db';
|
||||
const now = new Date().toISOString();
|
||||
|
||||
mkdirSync(dirname(DB_PATH), { recursive: true });
|
||||
const db = new DatabaseSync(DB_PATH);
|
||||
db.exec('PRAGMA journal_mode = WAL;');
|
||||
|
||||
// 应用迁移(与 src/lib/db.ts 行为一致,脚本独立运行不依赖 Astro)
|
||||
db.exec('CREATE TABLE IF NOT EXISTS _migrations (name TEXT PRIMARY KEY, applied_at TEXT NOT NULL)');
|
||||
const applied = new Set(db.prepare('SELECT name FROM _migrations').all().map((r) => r.name));
|
||||
for (const file of readdirSync('migrations').filter((f) => f.endsWith('.sql')).sort()) {
|
||||
if (applied.has(file)) continue;
|
||||
db.exec(readFileSync(join('migrations', file), 'utf8'));
|
||||
db.prepare('INSERT INTO _migrations (name, applied_at) VALUES (?, ?)').run(file, now);
|
||||
}
|
||||
|
||||
/* ------------------------------ 种子数据 ------------------------------ */
|
||||
|
||||
const soc = {
|
||||
slug: 'snapdragon-8-gen-3',
|
||||
type: 'soc',
|
||||
brand: 'Qualcomm',
|
||||
model: 'Snapdragon 8 Gen 3',
|
||||
codename: 'SM8650-AB',
|
||||
aliases: ['骁龙 8 Gen 3', '骁龙8Gen3'],
|
||||
process: 'TSMC N4P (4nm)',
|
||||
arch: 'ARMv9.2',
|
||||
detail: {
|
||||
cpuClusters: [
|
||||
{
|
||||
name: '超大核',
|
||||
cores: [{ microArch: 'Cortex-X4', count: 1, clockMax: '3.30 GHz', l2: '2 MB' }],
|
||||
l3: '12 MB',
|
||||
},
|
||||
{
|
||||
name: '性能核',
|
||||
cores: [{ microArch: 'Cortex-A720', count: 3, clockMax: '3.15 GHz', l2: '512 KB' }],
|
||||
},
|
||||
{
|
||||
name: '能效核',
|
||||
cores: [{ microArch: 'Cortex-A520', count: 2, clockMax: '2.27 GHz', l2: '256 KB' }],
|
||||
},
|
||||
],
|
||||
gpuBlock: {
|
||||
name: 'Adreno 750',
|
||||
arch: 'Adreno 7xx',
|
||||
clockMax: '903 MHz',
|
||||
apis: ['Vulkan 1.3', 'OpenGL ES 3.2', 'OpenCL 2.0'],
|
||||
},
|
||||
npuBlock: { name: 'Hexagon NPU', tops: '约 45 TOPS (INT8)' },
|
||||
ispBlock: 'Spectra 18-bit',
|
||||
modemBlock: 'Snapdragon X75 5G',
|
||||
memorySupport: { type: 'LPDDR5X', maxClock: '4800 MHz', bandwidth: '76.8 GB/s' },
|
||||
storageSupport: 'UFS 4.0',
|
||||
displaySupport: '最高 4K@60Hz / QHD+@144Hz',
|
||||
videoCodec: { encode: ['H.264', 'H.265', 'AV1'], decode: ['H.264', 'H.265', 'AV1'] },
|
||||
benchmarks: [
|
||||
{ name: 'Geekbench 6 单核', score: '2200', unit: 'pts' },
|
||||
{ name: 'Geekbench 6 多核', score: '6800', unit: 'pts' },
|
||||
{ name: '安兔兔 V10', score: '2100000', unit: 'pts' },
|
||||
],
|
||||
extra: {},
|
||||
},
|
||||
meta: [
|
||||
{
|
||||
path: 'process',
|
||||
confidence: 'high',
|
||||
sourceUrl: 'https://www.qualcomm.com/products/mobile/snapdragon/smartphones/snapdragon-8-series-mobile-platforms',
|
||||
verified: true,
|
||||
capturedAt: now,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const phone = {
|
||||
slug: 'xiaomi-14',
|
||||
category: 'phone',
|
||||
brand: 'Xiaomi',
|
||||
model: 'Xiaomi 14',
|
||||
aliases: ['小米 14', '23127PN0CC'],
|
||||
announceDate: '2023-10-26',
|
||||
releaseDate: '2023-11-01',
|
||||
lifecycle: 'discontinued',
|
||||
tags: ['旗舰', '小屏', '徕卡影像'],
|
||||
summary: '小米与徕卡合作的小尺寸旗舰,主打影像与手感。',
|
||||
chipRefs: { soc: 'snapdragon-8-gen-3' },
|
||||
specs: {
|
||||
body: {
|
||||
dimensions: '152.8 x 71.5 x 8.2 mm',
|
||||
weight: '188 g',
|
||||
build: { front: '康宁大猩猩 Victus', back: '玻璃', frame: '铝合金' },
|
||||
sim: 'Nano-SIM + eSIM',
|
||||
ipRating: 'IP68',
|
||||
colors: ['黑色', '白色', '岩石青', '雪山粉'],
|
||||
buttons: '右侧电源 + 音量',
|
||||
},
|
||||
display: {
|
||||
size: '6.36 英寸',
|
||||
resolution: '2670 x 1200',
|
||||
aspectRatio: '20:9',
|
||||
panel: 'LTPO AMOLED',
|
||||
refreshRate: '120Hz',
|
||||
refreshRange: '1-120Hz',
|
||||
touchSampling: '300Hz',
|
||||
brightnessTypical: '600 nit',
|
||||
brightnessPeak: '3000 nit',
|
||||
hdr: 'HDR10+ / Dolby Vision',
|
||||
protection: '康宁大猩猩 Victus',
|
||||
pwmDimming: '1920Hz PWM',
|
||||
alwaysOn: true,
|
||||
},
|
||||
platform: { os: 'Android 14', skin: 'HyperOS', chipset: 'Snapdragon 8 Gen 3' },
|
||||
memory: {
|
||||
ram: '8 / 12 / 16 GB',
|
||||
ramType: 'LPDDR5X',
|
||||
storage: '256 / 512 GB / 1TB',
|
||||
storageType: 'UFS 4.0',
|
||||
cardSlot: '无',
|
||||
},
|
||||
rearCamera: [
|
||||
{
|
||||
position: 'wide',
|
||||
sensorModel: 'OmniVision OV50H',
|
||||
resolution: '50MP',
|
||||
aperture: 'f/1.6',
|
||||
focalLength: '23mm',
|
||||
sensorSize: '1/1.31"',
|
||||
pixelSize: '1.2µm',
|
||||
lensElements: '7P',
|
||||
ois: true,
|
||||
zoom: '1x',
|
||||
autofocusType: '双像素 PDAF',
|
||||
video: { max: '8K@24fps', modes: ['4K@60fps', '1080p@240fps 慢动作'], stabilization: 'OIS + EIS' },
|
||||
extra: {},
|
||||
},
|
||||
{
|
||||
position: 'tele',
|
||||
sensorModel: 'Samsung S5KJN1',
|
||||
resolution: '50MP',
|
||||
aperture: 'f/2.0',
|
||||
focalLength: '75mm',
|
||||
sensorSize: '1/2.76"',
|
||||
pixelSize: '0.64µm',
|
||||
lensElements: '6P',
|
||||
ois: true,
|
||||
zoom: '3.2x 光学 / 60x 数码',
|
||||
autofocusType: 'PDAF',
|
||||
extra: {},
|
||||
},
|
||||
{
|
||||
position: 'ultrawide',
|
||||
sensorModel: 'Samsung S5KJN1',
|
||||
resolution: '50MP',
|
||||
aperture: 'f/2.2',
|
||||
focalLength: '14mm',
|
||||
sensorSize: '1/2.76"',
|
||||
pixelSize: '0.64µm',
|
||||
lensElements: '6P',
|
||||
ois: false,
|
||||
zoom: '0.6x',
|
||||
extra: {},
|
||||
},
|
||||
],
|
||||
frontCamera: [
|
||||
{
|
||||
position: 'front',
|
||||
sensorModel: 'OmniVision OV32C',
|
||||
resolution: '32MP',
|
||||
aperture: 'f/2.0',
|
||||
focalLength: '22mm',
|
||||
sensorSize: '1/3.14"',
|
||||
video: { max: '1080p@30fps', modes: [], stabilization: 'EIS' },
|
||||
extra: {},
|
||||
},
|
||||
],
|
||||
vibration: { type: 'X 轴线性马达', model: 'AAC 0809', size: '0809' },
|
||||
speakers: {
|
||||
count: 2,
|
||||
stereo: true,
|
||||
units: [
|
||||
{ model: 'AAC 1116', size: '11 x 16 mm' },
|
||||
{ model: 'AAC 1012', size: '10 x 12 mm' },
|
||||
],
|
||||
dolbyAtmos: true,
|
||||
hiRes: true,
|
||||
loudnessDba: '82 dB',
|
||||
headphoneJack: false,
|
||||
},
|
||||
connectivity: {
|
||||
cellular: '5G Sub-6 / mmWave',
|
||||
wifi: 'Wi-Fi 7 (802.11be)',
|
||||
bluetooth: '5.4, LDAC / LHDC 5.0',
|
||||
nfc: true,
|
||||
gps: 'L1 + L5 双频',
|
||||
usb: 'USB 3.2 Gen 1 Type-C',
|
||||
ir: true,
|
||||
uwb: false,
|
||||
},
|
||||
battery: {
|
||||
capacity: '4610 mAh',
|
||||
type: '锂聚合物',
|
||||
wired: '90W',
|
||||
wireless: '50W',
|
||||
reverse: '10W',
|
||||
chargingProtocol: '小米澎湃 P1 + G1',
|
||||
},
|
||||
sensors: {
|
||||
fingerprint: '屏下光学指纹',
|
||||
fingerprintType: '光学',
|
||||
fingerprintPosition: '屏下短焦',
|
||||
gyro: true,
|
||||
barometer: true,
|
||||
colorSensor: true,
|
||||
flickerSensor: true,
|
||||
},
|
||||
software: {
|
||||
launchVersion: 'Android 14 / HyperOS 1.0',
|
||||
currentVersion: 'Android 14 / HyperOS 1.0',
|
||||
updatePolicy: '4 代大版本 + 5 年安全更新',
|
||||
},
|
||||
extra: {},
|
||||
},
|
||||
meta: [
|
||||
{
|
||||
path: 'specs.rearCamera[0].sensorModel',
|
||||
confidence: 'high',
|
||||
sourceUrl: 'https://www.mi.com/xiaomi-14/specs',
|
||||
verified: true,
|
||||
capturedAt: now,
|
||||
},
|
||||
{
|
||||
path: 'specs.vibration.model',
|
||||
confidence: 'low',
|
||||
verified: false,
|
||||
capturedAt: now,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/* ------------------------------- 写库 ------------------------------- */
|
||||
|
||||
const deviceCols = [
|
||||
'slug', 'category', 'sub_category', 'brand', 'model', 'aliases_json',
|
||||
'announce_date', 'release_date', 'lifecycle', 'cover_key', 'gallery_json',
|
||||
'tags_json', 'summary', 'specs_json', 'chip_refs_json', 'meta_json',
|
||||
'created_at', 'updated_at',
|
||||
];
|
||||
|
||||
const deviceValues = [
|
||||
phone.slug, phone.category, null, phone.brand, phone.model,
|
||||
JSON.stringify(phone.aliases), phone.announceDate ?? null, phone.releaseDate ?? null,
|
||||
phone.lifecycle, null, JSON.stringify(phone.gallery ?? []),
|
||||
JSON.stringify(phone.tags ?? []), phone.summary ?? null, JSON.stringify(phone.specs),
|
||||
JSON.stringify(phone.chipRefs ?? {}), JSON.stringify(phone.meta ?? []), now, now,
|
||||
];
|
||||
|
||||
db.prepare(
|
||||
`INSERT INTO devices (${deviceCols.join(', ')}) VALUES (${deviceCols.map(() => '?').join(', ')})
|
||||
ON CONFLICT(slug) DO UPDATE SET
|
||||
category = excluded.category, brand = excluded.brand, model = excluded.model,
|
||||
aliases_json = excluded.aliases_json, announce_date = excluded.announce_date,
|
||||
release_date = excluded.release_date, lifecycle = excluded.lifecycle,
|
||||
tags_json = excluded.tags_json, summary = excluded.summary,
|
||||
specs_json = excluded.specs_json, chip_refs_json = excluded.chip_refs_json,
|
||||
meta_json = excluded.meta_json, updated_at = excluded.updated_at`,
|
||||
).run(...deviceValues);
|
||||
|
||||
const chipCols = [
|
||||
'slug', 'type', 'brand', 'model', 'codename', 'aliases_json',
|
||||
'process', 'arch', 'detail_json', 'meta_json', 'created_at', 'updated_at',
|
||||
];
|
||||
|
||||
db.prepare(
|
||||
`INSERT INTO chips (${chipCols.join(', ')}) VALUES (${chipCols.map(() => '?').join(', ')})
|
||||
ON CONFLICT(slug) DO UPDATE SET
|
||||
type = excluded.type, brand = excluded.brand, model = excluded.model,
|
||||
codename = excluded.codename, aliases_json = excluded.aliases_json,
|
||||
process = excluded.process, arch = excluded.arch,
|
||||
detail_json = excluded.detail_json, meta_json = excluded.meta_json,
|
||||
updated_at = excluded.updated_at`,
|
||||
).run(
|
||||
soc.slug, soc.type, soc.brand, soc.model, soc.codename ?? null,
|
||||
JSON.stringify(soc.aliases ?? []), soc.process ?? null, soc.arch ?? null,
|
||||
JSON.stringify(soc.detail), JSON.stringify(soc.meta ?? []), now, now,
|
||||
);
|
||||
|
||||
console.log('种子数据写入完成:xiaomi-14 / snapdragon-8-gen-3');
|
||||
db.close();
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
/**
|
||||
* shadcn/ui PoC:整棵 Radix 树必须写在同一个 React 组件里,
|
||||
* 分散在 .astro 模板中会被拆成多个 island,Context 无法传递。
|
||||
*/
|
||||
export default function DemoDialog() {
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline">打开对话框</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>组件自检</DialogTitle>
|
||||
<DialogDescription>
|
||||
这段弹窗由 React island 渲染,用于验证 shadcn/ui 在 Astro SSR 下的可用性。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
能看到这个框、能按 Esc 关闭、焦点能回到触发按钮,就说明集成没问题。
|
||||
</p>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button>知道了</Button>
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import * as React from 'react';
|
||||
import { Slot } from '@radix-ui/react-slot';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
outline: 'border border-border bg-transparent hover:bg-accent hover:text-accent-foreground',
|
||||
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
||||
destructive: 'bg-destructive text-white hover:bg-destructive/90',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-9 px-4 py-2',
|
||||
sm: 'h-8 px-3 text-xs',
|
||||
lg: 'h-10 px-6',
|
||||
icon: 'h-9 w-9',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
export function Button({ className, variant, size, asChild = false, ...props }: ButtonProps) {
|
||||
const Comp = asChild ? Slot : 'button';
|
||||
return <Comp className={cn(buttonVariants({ variant, size }), className)} {...props} />;
|
||||
}
|
||||
|
||||
export { buttonVariants };
|
||||
@@ -0,0 +1,34 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export function Card({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-lg border border-border bg-card text-card-foreground shadow-sm transition-colors',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function CardHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn('flex flex-col gap-1.5 p-5', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function CardTitle({ className, ...props }: React.HTMLAttributes<HTMLHeadingElement>) {
|
||||
return <h3 className={cn('text-base font-semibold leading-tight', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function CardDescription({ className, ...props }: React.HTMLAttributes<HTMLParagraphElement>) {
|
||||
return <p className={cn('text-sm text-muted-foreground', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function CardContent({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn('p-5 pt-0', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function CardFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn('flex items-center gap-2 p-5 pt-0', className)} {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as React from 'react';
|
||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||
import { X } from 'lucide-react';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export const Dialog = DialogPrimitive.Root;
|
||||
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||
export const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
export function DialogContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content>) {
|
||||
return (
|
||||
<DialogPrimitive.Portal>
|
||||
<DialogPrimitive.Overlay className="fixed inset-0 z-50 bg-black/60 backdrop-blur-sm" />
|
||||
<DialogPrimitive.Content
|
||||
className={cn(
|
||||
'fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl border border-border bg-card p-6 shadow-2xl',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm text-muted-foreground opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">关闭</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
export function DialogHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn('flex flex-col gap-1.5', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function DialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={cn('flex justify-end gap-2', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return <DialogPrimitive.Title className={cn('text-lg font-semibold', className)} {...props} />;
|
||||
}
|
||||
|
||||
export function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return <DialogPrimitive.Description className={cn('text-sm text-muted-foreground', className)} {...props} />;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
import '../styles/global.css';
|
||||
|
||||
interface Props {
|
||||
title?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
const {
|
||||
title = 'LFSpecs',
|
||||
description = '公开硬件规格库:收录手机、芯片等设备的详细参数,支持横向对比。',
|
||||
} = Astro.props;
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<meta name="description" content={description} />
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
<body class="min-h-dvh">
|
||||
<header class="border-b border-border/60">
|
||||
<div class="mx-auto flex h-14 max-w-6xl items-center gap-6 px-5">
|
||||
<a href="/" class="text-sm font-semibold tracking-tight">LFSpecs</a>
|
||||
<nav class="flex items-center gap-1 text-sm text-muted-foreground">
|
||||
<a href="/devices" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">手机</a>
|
||||
<a href="/chips" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">芯片</a>
|
||||
<a href="/poc" class="rounded-md px-2.5 py-1.5 transition-colors hover:bg-accent hover:text-foreground">组件自检</a>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="mx-auto max-w-6xl px-5 py-10">
|
||||
<slot />
|
||||
</main>
|
||||
|
||||
<footer class="mt-16 border-t border-border/60 py-8">
|
||||
<div class="mx-auto max-w-6xl px-5 text-xs text-muted-foreground">
|
||||
<p>数据由人工与 AI 辅助整理,仅供参考。</p>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,43 @@
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
|
||||
const DB_PATH = process.env.DB_PATH ?? 'data/app.db';
|
||||
const MIGRATIONS_DIR = 'migrations';
|
||||
|
||||
let instance: DatabaseSync | undefined;
|
||||
|
||||
/** 单例连接。首次调用时建目录、开 WAL、跑未应用的迁移。 */
|
||||
export function getDb(): DatabaseSync {
|
||||
if (!instance) {
|
||||
mkdirSync(dirname(DB_PATH), { recursive: true });
|
||||
instance = new DatabaseSync(DB_PATH);
|
||||
instance.exec('PRAGMA journal_mode = WAL;');
|
||||
instance.exec('PRAGMA foreign_keys = ON;');
|
||||
applyMigrations(instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
function applyMigrations(db: DatabaseSync): void {
|
||||
db.exec('CREATE TABLE IF NOT EXISTS _migrations (name TEXT PRIMARY KEY, applied_at TEXT NOT NULL)');
|
||||
|
||||
if (!existsSync(MIGRATIONS_DIR)) return;
|
||||
|
||||
const applied = new Set(
|
||||
(db.prepare('SELECT name FROM _migrations').all() as { name: string }[]).map((r) => r.name),
|
||||
);
|
||||
|
||||
const files = readdirSync(MIGRATIONS_DIR)
|
||||
.filter((f) => f.endsWith('.sql'))
|
||||
.sort();
|
||||
|
||||
for (const file of files) {
|
||||
if (applied.has(file)) continue;
|
||||
db.exec(readFileSync(join(MIGRATIONS_DIR, file), 'utf8'));
|
||||
db.prepare('INSERT INTO _migrations (name, applied_at) VALUES (?, ?)').run(
|
||||
file,
|
||||
new Date().toISOString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
import { getDb } from './db';
|
||||
import { chipSchema, deviceSchema, type Chip, type Device, type DeviceCategory } from './schema';
|
||||
|
||||
type Row = Record<string, unknown>;
|
||||
|
||||
function parseJson<T>(value: unknown, fallback: T): T {
|
||||
if (typeof value !== 'string' || value.length === 0) return fallback;
|
||||
try {
|
||||
return JSON.parse(value) as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
function toNullable(value: string | undefined | null): string | null {
|
||||
return value ?? null;
|
||||
}
|
||||
|
||||
function rowToDevice(row: Row): Device {
|
||||
return deviceSchema.parse({
|
||||
slug: row.slug,
|
||||
category: row.category,
|
||||
brand: row.brand,
|
||||
model: row.model,
|
||||
aliases: parseJson(row.aliases_json, []),
|
||||
announceDate: row.announce_date ?? undefined,
|
||||
releaseDate: row.release_date ?? undefined,
|
||||
lifecycle: row.lifecycle,
|
||||
cover: row.cover_key ?? undefined,
|
||||
gallery: parseJson(row.gallery_json, []),
|
||||
tags: parseJson(row.tags_json, []),
|
||||
summary: row.summary ?? undefined,
|
||||
chipRefs: parseJson(row.chip_refs_json, {}),
|
||||
meta: parseJson(row.meta_json, []),
|
||||
specs: parseJson(row.specs_json, {}),
|
||||
});
|
||||
}
|
||||
|
||||
function rowToChip(row: Row): Chip {
|
||||
return chipSchema.parse({
|
||||
slug: row.slug,
|
||||
type: row.type,
|
||||
brand: row.brand,
|
||||
model: row.model,
|
||||
codename: row.codename ?? undefined,
|
||||
aliases: parseJson(row.aliases_json, []),
|
||||
process: row.process ?? undefined,
|
||||
arch: row.arch ?? undefined,
|
||||
meta: parseJson(row.meta_json, []),
|
||||
detail: parseJson(row.detail_json, {}),
|
||||
});
|
||||
}
|
||||
|
||||
/* ------------------------------- devices ------------------------------- */
|
||||
|
||||
export function listDevices(options: { category?: DeviceCategory } = {}): Device[] {
|
||||
const db = getDb();
|
||||
const rows = options.category
|
||||
? db
|
||||
.prepare(
|
||||
'SELECT * FROM devices WHERE category = ? ORDER BY release_date DESC, brand, model',
|
||||
)
|
||||
.all(options.category)
|
||||
: db.prepare('SELECT * FROM devices ORDER BY release_date DESC, brand, model').all();
|
||||
return (rows as Row[]).map(rowToDevice);
|
||||
}
|
||||
|
||||
export function getDevice(slug: string): Device | undefined {
|
||||
const row = getDb().prepare('SELECT * FROM devices WHERE slug = ?').get(slug) as Row | undefined;
|
||||
return row ? rowToDevice(row) : undefined;
|
||||
}
|
||||
|
||||
export function countDevices(category?: DeviceCategory): number {
|
||||
const db = getDb();
|
||||
const row = category
|
||||
? (db.prepare('SELECT COUNT(*) AS n FROM devices WHERE category = ?').get(category) as { n: number })
|
||||
: (db.prepare('SELECT COUNT(*) AS n FROM devices').get() as { n: number });
|
||||
return row.n;
|
||||
}
|
||||
|
||||
/** 反查:搭载某颗芯片的设备(按 chipRefs 中任一引用匹配) */
|
||||
export function devicesUsingChip(chipSlug: string): Device[] {
|
||||
const rows = getDb()
|
||||
.prepare(
|
||||
`SELECT * FROM devices
|
||||
WHERE json_extract(chip_refs_json, '$.soc') = ?
|
||||
OR json_extract(chip_refs_json, '$.cpu') = ?
|
||||
OR json_extract(chip_refs_json, '$.gpu') = ?
|
||||
OR json_extract(chip_refs_json, '$.npu') = ?
|
||||
OR json_extract(chip_refs_json, '$.modem') = ?
|
||||
ORDER BY release_date DESC`,
|
||||
)
|
||||
.all(chipSlug, chipSlug, chipSlug, chipSlug, chipSlug);
|
||||
return (rows as Row[]).map(rowToDevice);
|
||||
}
|
||||
|
||||
export function saveDevice(input: Device): Device {
|
||||
const device = deviceSchema.parse(input);
|
||||
const now = new Date().toISOString();
|
||||
getDb()
|
||||
.prepare(
|
||||
`INSERT INTO devices (
|
||||
slug, category, sub_category, brand, model, aliases_json,
|
||||
announce_date, release_date, lifecycle, cover_key, gallery_json,
|
||||
tags_json, summary, specs_json, chip_refs_json, meta_json,
|
||||
created_at, updated_at
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
ON CONFLICT(slug) DO UPDATE SET
|
||||
category = excluded.category,
|
||||
sub_category = excluded.sub_category,
|
||||
brand = excluded.brand,
|
||||
model = excluded.model,
|
||||
aliases_json = excluded.aliases_json,
|
||||
announce_date = excluded.announce_date,
|
||||
release_date = excluded.release_date,
|
||||
lifecycle = excluded.lifecycle,
|
||||
cover_key = excluded.cover_key,
|
||||
gallery_json = excluded.gallery_json,
|
||||
tags_json = excluded.tags_json,
|
||||
summary = excluded.summary,
|
||||
specs_json = excluded.specs_json,
|
||||
chip_refs_json = excluded.chip_refs_json,
|
||||
meta_json = excluded.meta_json,
|
||||
updated_at = excluded.updated_at`,
|
||||
)
|
||||
.run(
|
||||
device.slug,
|
||||
device.category,
|
||||
null,
|
||||
device.brand,
|
||||
device.model,
|
||||
JSON.stringify(device.aliases),
|
||||
toNullable(device.announceDate),
|
||||
toNullable(device.releaseDate),
|
||||
device.lifecycle,
|
||||
toNullable(device.cover),
|
||||
JSON.stringify(device.gallery),
|
||||
JSON.stringify(device.tags),
|
||||
toNullable(device.summary),
|
||||
JSON.stringify(device.specs),
|
||||
JSON.stringify(device.chipRefs),
|
||||
JSON.stringify(device.meta),
|
||||
now,
|
||||
now,
|
||||
);
|
||||
return getDevice(device.slug)!;
|
||||
}
|
||||
|
||||
/* -------------------------------- chips -------------------------------- */
|
||||
|
||||
export function listChips(options: { type?: Chip['type'] } = {}): Chip[] {
|
||||
const db = getDb();
|
||||
const rows = options.type
|
||||
? db.prepare('SELECT * FROM chips WHERE type = ? ORDER BY brand, model').all(options.type)
|
||||
: db.prepare('SELECT * FROM chips ORDER BY brand, model').all();
|
||||
return (rows as Row[]).map(rowToChip);
|
||||
}
|
||||
|
||||
export function getChip(slug: string): Chip | undefined {
|
||||
const row = getDb().prepare('SELECT * FROM chips WHERE slug = ?').get(slug) as Row | undefined;
|
||||
return row ? rowToChip(row) : undefined;
|
||||
}
|
||||
|
||||
export function countChips(type?: Chip['type']): number {
|
||||
const db = getDb();
|
||||
const row = type
|
||||
? (db.prepare('SELECT COUNT(*) AS n FROM chips WHERE type = ?').get(type) as { n: number })
|
||||
: (db.prepare('SELECT COUNT(*) AS n FROM chips').get() as { n: number });
|
||||
return row.n;
|
||||
}
|
||||
|
||||
export function saveChip(input: Chip): Chip {
|
||||
const chip = chipSchema.parse(input);
|
||||
const now = new Date().toISOString();
|
||||
getDb()
|
||||
.prepare(
|
||||
`INSERT INTO chips (
|
||||
slug, type, brand, model, codename, aliases_json,
|
||||
process, arch, detail_json, meta_json, created_at, updated_at
|
||||
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
ON CONFLICT(slug) DO UPDATE SET
|
||||
type = excluded.type,
|
||||
brand = excluded.brand,
|
||||
model = excluded.model,
|
||||
codename = excluded.codename,
|
||||
aliases_json = excluded.aliases_json,
|
||||
process = excluded.process,
|
||||
arch = excluded.arch,
|
||||
detail_json = excluded.detail_json,
|
||||
meta_json = excluded.meta_json,
|
||||
updated_at = excluded.updated_at`,
|
||||
)
|
||||
.run(
|
||||
chip.slug,
|
||||
chip.type,
|
||||
chip.brand,
|
||||
chip.model,
|
||||
toNullable(chip.codename),
|
||||
JSON.stringify(chip.aliases),
|
||||
toNullable(chip.process),
|
||||
toNullable(chip.arch),
|
||||
JSON.stringify(chip.detail),
|
||||
JSON.stringify(chip.meta),
|
||||
now,
|
||||
now,
|
||||
);
|
||||
return getChip(chip.slug)!;
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { z } from 'zod';
|
||||
import { phoneSpecsSchema } from './phone';
|
||||
import { socDetailSchema } from './soc';
|
||||
import { fieldMetaSchema, dateStringSchema } from './meta';
|
||||
|
||||
export const deviceCategorySchema = z.enum([
|
||||
'phone',
|
||||
'tablet',
|
||||
'laptop',
|
||||
'desktop',
|
||||
'handheld',
|
||||
'peripheral',
|
||||
]);
|
||||
export type DeviceCategory = z.infer<typeof deviceCategorySchema>;
|
||||
|
||||
export const lifecycleSchema = z.enum(['announced', 'released', 'discontinued']);
|
||||
export const chipTypeSchema = z.enum(['soc', 'cpu', 'gpu', 'npu', 'modem']);
|
||||
|
||||
export const slugSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, 'slug 只能用小写字母、数字和连字符');
|
||||
|
||||
export const chipRefsSchema = z
|
||||
.object({
|
||||
soc: z.string().optional(),
|
||||
cpu: z.string().optional(),
|
||||
gpu: z.string().optional(),
|
||||
npu: z.string().optional(),
|
||||
modem: z.string().optional(),
|
||||
})
|
||||
.default({});
|
||||
|
||||
const deviceBaseSchema = z.object({
|
||||
slug: slugSchema,
|
||||
brand: z.string().min(1),
|
||||
model: z.string().min(1),
|
||||
aliases: z.array(z.string()).default([]),
|
||||
announceDate: dateStringSchema.optional(),
|
||||
releaseDate: dateStringSchema.optional(),
|
||||
lifecycle: lifecycleSchema.default('released'),
|
||||
/** 存储 key,不是 URL */
|
||||
cover: z.string().optional(),
|
||||
gallery: z.array(z.string()).default([]),
|
||||
tags: z.array(z.string()).default([]),
|
||||
summary: z.string().optional(),
|
||||
chipRefs: chipRefsSchema,
|
||||
meta: z.array(fieldMetaSchema).default([]),
|
||||
});
|
||||
|
||||
/** M0 只实现 phone,后续 tablet/laptop/... 逐个加进 discriminatedUnion */
|
||||
export const phoneDeviceSchema = deviceBaseSchema.extend({
|
||||
category: z.literal('phone'),
|
||||
specs: phoneSpecsSchema,
|
||||
});
|
||||
export type PhoneDevice = z.infer<typeof phoneDeviceSchema>;
|
||||
|
||||
export const deviceSchema = z.discriminatedUnion('category', [phoneDeviceSchema]);
|
||||
export type Device = z.infer<typeof deviceSchema>;
|
||||
|
||||
const chipBaseSchema = z.object({
|
||||
slug: slugSchema,
|
||||
brand: z.string().min(1),
|
||||
model: z.string().min(1),
|
||||
codename: z.string().optional(),
|
||||
aliases: z.array(z.string()).default([]),
|
||||
process: z.string().optional(), // "TSMC N4P"
|
||||
arch: z.string().optional(), // "ARMv9.2"
|
||||
meta: z.array(fieldMetaSchema).default([]),
|
||||
});
|
||||
|
||||
export const socChipSchema = chipBaseSchema.extend({
|
||||
type: z.literal('soc'),
|
||||
detail: socDetailSchema,
|
||||
});
|
||||
export type SocChip = z.infer<typeof socChipSchema>;
|
||||
|
||||
export const chipSchema = z.discriminatedUnion('type', [socChipSchema]);
|
||||
export type Chip = z.infer<typeof chipSchema>;
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './meta';
|
||||
export * from './phone';
|
||||
export * from './soc';
|
||||
export * from './device';
|
||||
@@ -0,0 +1,23 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/** 字段置信度:AI 分级录入的唯一依据 */
|
||||
export const confidenceSchema = z.enum(['high', 'medium', 'low']);
|
||||
export type Confidence = z.infer<typeof confidenceSchema>;
|
||||
|
||||
/**
|
||||
* 字段级元数据。path 是扁平路径(如 specs.rearCamera[0].sensorModel),
|
||||
* 与 AI 接口返回的字段路径一一对应。
|
||||
*/
|
||||
export const fieldMetaSchema = z.object({
|
||||
path: z.string(),
|
||||
confidence: confidenceSchema,
|
||||
sourceUrl: z.url().optional(),
|
||||
verified: z.boolean().default(false),
|
||||
capturedAt: z.string(),
|
||||
});
|
||||
export type FieldMeta = z.infer<typeof fieldMetaSchema>;
|
||||
|
||||
/** ISO 日期字符串(只到日或 datetime 均可) */
|
||||
export const dateStringSchema = z.string().refine((v) => !Number.isNaN(new Date(v).getTime()), {
|
||||
message: '不是有效日期',
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const extraSchema = z.record(z.string(), z.string()).default({});
|
||||
|
||||
export const cameraPositionSchema = z.enum([
|
||||
'wide',
|
||||
'ultrawide',
|
||||
'tele',
|
||||
'periscope',
|
||||
'macro',
|
||||
'depth',
|
||||
'mono',
|
||||
'front',
|
||||
]);
|
||||
|
||||
/** 单颗摄像头。多摄必须逐颗建模,才能检索与对比 */
|
||||
export const cameraModuleSchema = z.object({
|
||||
position: cameraPositionSchema,
|
||||
sensorModel: z.string().optional(), // "Sony IMX890"
|
||||
resolution: z.string().optional(), // "50MP"
|
||||
aperture: z.string().optional(), // "f/1.8"
|
||||
focalLength: z.string().optional(), // "24mm"
|
||||
sensorSize: z.string().optional(), // "1/1.56\""
|
||||
pixelSize: z.string().optional(), // "1.0µm"
|
||||
lensElements: z.string().optional(), // "7P"
|
||||
ois: z.boolean().optional(),
|
||||
eis: z.boolean().optional(),
|
||||
zoom: z.string().optional(), // "3x 光学 / 30x 数码"
|
||||
autofocusType: z.string().optional(), // "双像素 PDAF"
|
||||
video: z
|
||||
.object({
|
||||
max: z.string().optional(), // "8K@24fps"
|
||||
modes: z.array(z.string()).default([]),
|
||||
stabilization: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
flash: z.string().optional(),
|
||||
extra: extraSchema,
|
||||
});
|
||||
export type CameraModule = z.infer<typeof cameraModuleSchema>;
|
||||
|
||||
export const phoneSpecsSchema = z.object({
|
||||
body: z
|
||||
.object({
|
||||
dimensions: z.string().optional(), // "161.4 x 74.6 x 8.2 mm"
|
||||
weight: z.string().optional(), // "193 g"
|
||||
build: z
|
||||
.object({
|
||||
front: z.string().optional(),
|
||||
back: z.string().optional(),
|
||||
frame: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
sim: z.string().optional(),
|
||||
ipRating: z.string().optional(), // "IP68"
|
||||
colors: z.array(z.string()).default([]),
|
||||
buttons: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
display: z
|
||||
.object({
|
||||
size: z.string().optional(), // "6.79 英寸"
|
||||
resolution: z.string().optional(), // "2712 x 1220"
|
||||
aspectRatio: z.string().optional(),
|
||||
panel: z.string().optional(), // "LTPO AMOLED"
|
||||
refreshRate: z.string().optional(), // "120Hz"
|
||||
refreshRange: z.string().optional(), // "1-120Hz"
|
||||
touchSampling: z.string().optional(),
|
||||
brightnessTypical: z.string().optional(),
|
||||
brightnessPeak: z.string().optional(),
|
||||
hdr: z.string().optional(),
|
||||
protection: z.string().optional(), // "康宁大猩猩 Victus 2"
|
||||
pwmDimming: z.string().optional(),
|
||||
alwaysOn: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
platform: z
|
||||
.object({
|
||||
os: z.string().optional(),
|
||||
skin: z.string().optional(),
|
||||
chipset: z.string().optional(), // 冗余展示用,权威值在 chipRefs.soc
|
||||
})
|
||||
.optional(),
|
||||
memory: z
|
||||
.object({
|
||||
ram: z.string().optional(),
|
||||
ramType: z.string().optional(), // "LPDDR5X"
|
||||
storage: z.string().optional(),
|
||||
storageType: z.string().optional(), // "UFS 4.0"
|
||||
cardSlot: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
rearCamera: z.array(cameraModuleSchema).default([]),
|
||||
frontCamera: z.array(cameraModuleSchema).default([]),
|
||||
/** 振动马达:X轴/Z轴线性、转子;型号如 "AAC 0809" */
|
||||
vibration: z
|
||||
.object({
|
||||
type: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
size: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
speakers: z
|
||||
.object({
|
||||
count: z.number().optional(),
|
||||
stereo: z.boolean().optional(),
|
||||
units: z
|
||||
.array(
|
||||
z.object({
|
||||
model: z.string().optional(),
|
||||
size: z.string().optional(),
|
||||
power: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
dolbyAtmos: z.boolean().optional(),
|
||||
hiRes: z.boolean().optional(),
|
||||
loudnessDba: z.string().optional(),
|
||||
headphoneJack: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
connectivity: z
|
||||
.object({
|
||||
cellular: z.string().optional(),
|
||||
wifi: z.string().optional(),
|
||||
bluetooth: z.string().optional(),
|
||||
nfc: z.boolean().optional(),
|
||||
gps: z.string().optional(),
|
||||
usb: z.string().optional(),
|
||||
ir: z.boolean().optional(),
|
||||
uwb: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
battery: z
|
||||
.object({
|
||||
capacity: z.string().optional(), // "5400mAh"
|
||||
type: z.string().optional(),
|
||||
wired: z.string().optional(),
|
||||
wireless: z.string().optional(),
|
||||
reverse: z.string().optional(),
|
||||
chargingProtocol: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
sensors: z
|
||||
.object({
|
||||
fingerprint: z.string().optional(),
|
||||
fingerprintType: z.string().optional(), // 超声波 / 光学
|
||||
fingerprintPosition: z.string().optional(),
|
||||
gyro: z.boolean().optional(),
|
||||
barometer: z.boolean().optional(),
|
||||
colorSensor: z.boolean().optional(),
|
||||
flickerSensor: z.boolean().optional(),
|
||||
})
|
||||
.optional(),
|
||||
software: z
|
||||
.object({
|
||||
launchVersion: z.string().optional(),
|
||||
currentVersion: z.string().optional(),
|
||||
updatePolicy: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
extra: extraSchema,
|
||||
});
|
||||
export type PhoneSpecs = z.infer<typeof phoneSpecsSchema>;
|
||||
@@ -0,0 +1,70 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* SoC 详情。与设备 specs 分开维护,供多机型引用。
|
||||
*/
|
||||
export const socDetailSchema = z.object({
|
||||
cpuClusters: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string().optional(), // "性能簇" / "能效簇"
|
||||
cores: z
|
||||
.array(
|
||||
z.object({
|
||||
microArch: z.string().optional(), // "Cortex-X4"
|
||||
count: z.number().optional(),
|
||||
clockMax: z.string().optional(), // "3.3GHz"
|
||||
l1: z.string().optional(),
|
||||
l2: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
l3: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
gpuBlock: z
|
||||
.object({
|
||||
name: z.string().optional(), // "Adreno 750"
|
||||
arch: z.string().optional(),
|
||||
cores: z.number().optional(),
|
||||
clockMax: z.string().optional(),
|
||||
apis: z.array(z.string()).default([]),
|
||||
})
|
||||
.optional(),
|
||||
npuBlock: z
|
||||
.object({
|
||||
name: z.string().optional(),
|
||||
tops: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
ispBlock: z.string().optional(),
|
||||
dspBlock: z.string().optional(),
|
||||
modemBlock: z.string().optional(),
|
||||
memorySupport: z
|
||||
.object({
|
||||
type: z.string().optional(), // "LPDDR5X"
|
||||
maxClock: z.string().optional(),
|
||||
bandwidth: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
storageSupport: z.string().optional(), // "UFS 4.0"
|
||||
displaySupport: z.string().optional(), // 最高分辨率/刷新率
|
||||
videoCodec: z
|
||||
.object({
|
||||
encode: z.array(z.string()).default([]),
|
||||
decode: z.array(z.string()).default([]),
|
||||
})
|
||||
.optional(),
|
||||
benchmarks: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
score: z.string(),
|
||||
unit: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
extra: z.record(z.string(), z.string()).default({}),
|
||||
});
|
||||
export type SocDetail = z.infer<typeof socDetailSchema>;
|
||||
@@ -0,0 +1,65 @@
|
||||
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export interface StorageDriver {
|
||||
put(key: string, buf: Uint8Array, contentType: string): Promise<void>;
|
||||
delete(key: string): Promise<void>;
|
||||
publicUrl(key: string): string;
|
||||
}
|
||||
|
||||
const LOCAL_ROOT = process.env.UPLOADS_DIR ?? 'data/uploads';
|
||||
|
||||
/**
|
||||
* 本地磁盘驱动。key 形如 `devices/xiaomi-14/cover.webp`,
|
||||
* 落盘到 data/uploads 下,URL 由 /uploads/[...key] 端点提供。
|
||||
*/
|
||||
class LocalDriver implements StorageDriver {
|
||||
async put(key: string, buf: Uint8Array, _contentType: string): Promise<void> {
|
||||
const target = join(LOCAL_ROOT, key);
|
||||
await mkdir(join(target, '..'), { recursive: true });
|
||||
await writeFile(target, buf);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<void> {
|
||||
await rm(join(LOCAL_ROOT, key), { force: true });
|
||||
}
|
||||
|
||||
publicUrl(key: string): string {
|
||||
return `/uploads/${key}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* S3 兼容驱动占位。M2 接入(@aws-sdk/client-s3 或 SigV4 手写),
|
||||
* 配置项:S3_ENDPOINT / S3_BUCKET / S3_REGION / S3_KEY / S3_SECRET / S3_PUBLIC_BASE_URL
|
||||
*/
|
||||
class S3Driver implements StorageDriver {
|
||||
private readonly base: string;
|
||||
constructor() {
|
||||
this.base = process.env.S3_PUBLIC_BASE_URL ?? '';
|
||||
}
|
||||
async put(): Promise<void> {
|
||||
throw new Error('S3 驱动尚未实现(M2 接入)');
|
||||
}
|
||||
async delete(): Promise<void> {
|
||||
throw new Error('S3 驱动尚未实现(M2 接入)');
|
||||
}
|
||||
publicUrl(key: string): string {
|
||||
if (!this.base) throw new Error('缺少 S3_PUBLIC_BASE_URL');
|
||||
return `${this.base.replace(/\/$/, '')}/${key}`;
|
||||
}
|
||||
}
|
||||
|
||||
let driver: StorageDriver | undefined;
|
||||
|
||||
export function getStorage(): StorageDriver {
|
||||
if (!driver) {
|
||||
const kind = process.env.STORAGE_DRIVER ?? 'local';
|
||||
driver = kind === 's3' ? new S3Driver() : new LocalDriver();
|
||||
}
|
||||
return driver;
|
||||
}
|
||||
|
||||
export function storageRoot(): string {
|
||||
return LOCAL_ROOT;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { devicesUsingChip, getChip } from '@/lib/repo';
|
||||
|
||||
const slug = Astro.params.slug ?? '';
|
||||
const chip = getChip(slug);
|
||||
if (!chip) {
|
||||
return new Response('未找到该芯片', { status: 404 });
|
||||
}
|
||||
|
||||
const detail = chip.detail;
|
||||
const devices = devicesUsingChip(chip.slug);
|
||||
const coreTotal = detail.cpuClusters.reduce(
|
||||
(sum, c) => sum + (c.cores ?? []).reduce((n, x) => n + (x.count ?? 0), 0),
|
||||
0,
|
||||
);
|
||||
---
|
||||
|
||||
<BaseLayout title={`${chip.brand} ${chip.model} 规格 · LFSpecs`}>
|
||||
<nav class="text-xs text-muted-foreground">
|
||||
<a href="/chips" class="hover:text-foreground">芯片</a>
|
||||
<span class="mx-1.5">/</span>
|
||||
<span class="text-foreground">{chip.model}</span>
|
||||
</nav>
|
||||
|
||||
<header class="mt-3">
|
||||
<p class="text-sm text-muted-foreground">{chip.brand}</p>
|
||||
<h1 class="mt-1 text-3xl font-semibold tracking-tight">{chip.model}</h1>
|
||||
<p class="tabular mt-1.5 text-xs text-muted-foreground">
|
||||
{chip.codename ?? ''} {chip.aliases.length > 0 && `· 别名:${chip.aliases.join('、')}`}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<dl class="tabular mt-6 grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6">
|
||||
{
|
||||
[
|
||||
['制程', chip.process],
|
||||
['架构', chip.arch],
|
||||
['CPU 核心', coreTotal ? `${coreTotal} 核` : undefined],
|
||||
['GPU', detail.gpuBlock?.name],
|
||||
['NPU', detail.npuBlock?.name],
|
||||
['基带', detail.modemBlock],
|
||||
].map(([label, value]) => (
|
||||
<div class="rounded-lg border border-border bg-card p-3">
|
||||
<dt class="text-[11px] text-muted-foreground">{label}</dt>
|
||||
<dd class="mt-1 truncate text-sm font-medium">{value ?? '—'}</dd>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</dl>
|
||||
|
||||
<section class="mt-10">
|
||||
<h2 class="text-lg font-semibold">CPU 核心簇</h2>
|
||||
<div class="mt-3 overflow-hidden rounded-lg border border-border">
|
||||
<table class="w-full border-collapse text-sm">
|
||||
<thead class="bg-secondary/60 text-xs text-muted-foreground">
|
||||
<tr>
|
||||
<th class="px-4 py-2 text-left font-normal">簇</th>
|
||||
<th class="px-4 py-2 text-left font-normal">微架构</th>
|
||||
<th class="px-4 py-2 text-right font-normal">数量</th>
|
||||
<th class="px-4 py-2 text-right font-normal">最高频率</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{
|
||||
detail.cpuClusters.map((cluster) =>
|
||||
cluster.cores.map((core) => (
|
||||
<tr class="border-t border-border/60">
|
||||
<td class="px-4 py-2">{cluster.name ?? '—'}</td>
|
||||
<td class="px-4 py-2">{core.microArch ?? '—'}</td>
|
||||
<td class="tabular px-4 py-2 text-right">{core.count ?? '—'}</td>
|
||||
<td class="tabular px-4 py-2 text-right">{core.clockMax ?? '—'}</td>
|
||||
</tr>
|
||||
)),
|
||||
)
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mt-10 grid gap-3 sm:grid-cols-2">
|
||||
<div class="rounded-lg border border-border bg-card p-5">
|
||||
<h3 class="text-sm font-semibold">GPU</h3>
|
||||
<dl class="tabular mt-3 grid grid-cols-2 gap-x-3 gap-y-1 text-xs">
|
||||
<dt class="text-muted-foreground">型号</dt>
|
||||
<dd class="text-right">{detail.gpuBlock?.name ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">最高频率</dt>
|
||||
<dd class="text-right">{detail.gpuBlock?.clockMax ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">API</dt>
|
||||
<dd class="text-right">{detail.gpuBlock?.apis.join(' / ') || '—'}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div class="rounded-lg border border-border bg-card p-5">
|
||||
<h3 class="text-sm font-semibold">内存与存储支持</h3>
|
||||
<dl class="tabular mt-3 grid grid-cols-2 gap-x-3 gap-y-1 text-xs">
|
||||
<dt class="text-muted-foreground">内存类型</dt>
|
||||
<dd class="text-right">{detail.memorySupport?.type ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">带宽</dt>
|
||||
<dd class="text-right">{detail.memorySupport?.bandwidth ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">存储</dt>
|
||||
<dd class="text-right">{detail.storageSupport ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">显示支持</dt>
|
||||
<dd class="text-right">{detail.displaySupport ?? '—'}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{
|
||||
detail.benchmarks.length > 0 && (
|
||||
<section class="mt-10">
|
||||
<h2 class="text-lg font-semibold">跑分</h2>
|
||||
<div class="mt-3 grid gap-3 sm:grid-cols-3">
|
||||
{detail.benchmarks.map((b) => (
|
||||
<div class="rounded-lg border border-border bg-card p-4">
|
||||
<div class="text-xs text-muted-foreground">{b.name}</div>
|
||||
<div class="tabular mt-1 text-xl font-semibold">
|
||||
{b.score}
|
||||
<span class="ml-1 text-xs font-normal text-muted-foreground">{b.unit ?? ''}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
<section class="mt-10">
|
||||
<h2 class="text-lg font-semibold">搭载该芯片的设备</h2>
|
||||
{devices.length > 0 ? (
|
||||
<ul class="mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{devices.map((d) => (
|
||||
<li>
|
||||
<a
|
||||
href={`/devices/${d.slug}`}
|
||||
class="block rounded-lg border border-border bg-card p-4 transition-colors hover:border-primary/40"
|
||||
>
|
||||
<div class="text-xs text-muted-foreground">{d.brand}</div>
|
||||
<div class="text-sm font-medium">{d.model}</div>
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p class="mt-3 text-sm text-muted-foreground">暂无收录设备。</p>
|
||||
)}
|
||||
</section>
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { listChips } from '@/lib/repo';
|
||||
|
||||
const chips = listChips({ type: 'soc' });
|
||||
---
|
||||
|
||||
<BaseLayout title="芯片库 · LFSpecs">
|
||||
<div class="flex items-baseline justify-between">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">SoC</h1>
|
||||
<span class="tabular text-sm text-muted-foreground">{chips.length} 颗</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{
|
||||
chips.map((chip) => {
|
||||
const clusters = chip.detail.cpuClusters ?? [];
|
||||
const coreCount = clusters.reduce(
|
||||
(sum, c) => sum + (c.cores ?? []).reduce((n, x) => n + (x.count ?? 0), 0),
|
||||
0,
|
||||
);
|
||||
return (
|
||||
<a
|
||||
href={`/chips/${chip.slug}`}
|
||||
class="group rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40"
|
||||
>
|
||||
<div class="text-xs text-muted-foreground">{chip.brand}</div>
|
||||
<div class="mt-0.5 text-base font-semibold">{chip.model}</div>
|
||||
<dl class="tabular mt-4 grid grid-cols-2 gap-x-4 gap-y-1 text-xs">
|
||||
<dt class="text-muted-foreground">制程</dt>
|
||||
<dd class="truncate text-right">{chip.process ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">核心</dt>
|
||||
<dd class="text-right">{coreCount || '—'} 核</dd>
|
||||
<dt class="text-muted-foreground">GPU</dt>
|
||||
<dd class="truncate text-right">{chip.detail.gpuBlock?.name ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">架构</dt>
|
||||
<dd class="truncate text-right">{chip.arch ?? '—'}</dd>
|
||||
</dl>
|
||||
</a>
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
chips.length === 0 && (
|
||||
<p class="mt-6 rounded-lg border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
|
||||
暂无芯片数据,运行 <code class="font-mono text-foreground">pnpm db:seed</code> 写入种子数据。
|
||||
</p>
|
||||
)
|
||||
}
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,254 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { getChip, getDevice } from '@/lib/repo';
|
||||
|
||||
const slug = Astro.params.slug ?? '';
|
||||
const device = getDevice(slug);
|
||||
if (!device) {
|
||||
return new Response('未找到该设备', { status: 404 });
|
||||
}
|
||||
|
||||
const s = device.specs;
|
||||
const soc = device.chipRefs.soc ? getChip(device.chipRefs.soc) : undefined;
|
||||
|
||||
function fmt(value: unknown): string | undefined {
|
||||
if (value === undefined || value === null || value === '') return undefined;
|
||||
if (typeof value === 'boolean') return value ? '支持' : '不支持';
|
||||
if (Array.isArray(value)) return value.length > 0 ? value.join(' / ') : undefined;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
const build = [s.body?.build?.front, s.body?.build?.back, s.body?.build?.frame]
|
||||
.filter(Boolean)
|
||||
.join(' / ');
|
||||
|
||||
const groups = [
|
||||
{
|
||||
title: '外观',
|
||||
rows: [
|
||||
['尺寸', fmt(s.body?.dimensions)],
|
||||
['重量', fmt(s.body?.weight)],
|
||||
['机身材质', build || undefined],
|
||||
['SIM', fmt(s.body?.sim)],
|
||||
['防护等级', fmt(s.body?.ipRating)],
|
||||
['配色', fmt(s.body?.colors)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '屏幕',
|
||||
rows: [
|
||||
['尺寸', fmt(s.display?.size)],
|
||||
['分辨率', fmt(s.display?.resolution)],
|
||||
['比例', fmt(s.display?.aspectRatio)],
|
||||
['面板', fmt(s.display?.panel)],
|
||||
['刷新率', fmt(s.display?.refreshRate)],
|
||||
['刷新范围', fmt(s.display?.refreshRange)],
|
||||
['触控采样率', fmt(s.display?.touchSampling)],
|
||||
['典型亮度', fmt(s.display?.brightnessTypical)],
|
||||
['峰值亮度', fmt(s.display?.brightnessPeak)],
|
||||
['HDR', fmt(s.display?.hdr)],
|
||||
['保护玻璃', fmt(s.display?.protection)],
|
||||
['调光', fmt(s.display?.pwmDimming)],
|
||||
['息屏显示', fmt(s.display?.alwaysOn)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '平台与存储',
|
||||
rows: [
|
||||
['系统', fmt(s.platform?.os)],
|
||||
['定制 UI', fmt(s.platform?.skin)],
|
||||
['内存', fmt(s.memory?.ram)],
|
||||
['内存类型', fmt(s.memory?.ramType)],
|
||||
['存储', fmt(s.memory?.storage)],
|
||||
['存储类型', fmt(s.memory?.storageType)],
|
||||
['存储卡', fmt(s.memory?.cardSlot)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '音频与振动',
|
||||
rows: [
|
||||
['马达类型', fmt(s.vibration?.type)],
|
||||
['马达型号', fmt(s.vibration?.model)],
|
||||
['扬声器数量', fmt(s.speakers?.count)],
|
||||
['立体声', fmt(s.speakers?.stereo)],
|
||||
[
|
||||
'扬声器单元',
|
||||
s.speakers?.units?.length
|
||||
? s.speakers.units.map((u) => [u.model, u.size].filter(Boolean).join(' ')).join(' / ')
|
||||
: undefined,
|
||||
],
|
||||
['杜比全景声', fmt(s.speakers?.dolbyAtmos)],
|
||||
['Hi-Res', fmt(s.speakers?.hiRes)],
|
||||
['响度', fmt(s.speakers?.loudnessDba)],
|
||||
['耳机孔', fmt(s.speakers?.headphoneJack)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '连接',
|
||||
rows: [
|
||||
['蜂窝', fmt(s.connectivity?.cellular)],
|
||||
['Wi-Fi', fmt(s.connectivity?.wifi)],
|
||||
['蓝牙', fmt(s.connectivity?.bluetooth)],
|
||||
['NFC', fmt(s.connectivity?.nfc)],
|
||||
['定位', fmt(s.connectivity?.gps)],
|
||||
['USB', fmt(s.connectivity?.usb)],
|
||||
['红外', fmt(s.connectivity?.ir)],
|
||||
['UWB', fmt(s.connectivity?.uwb)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '电池与充电',
|
||||
rows: [
|
||||
['容量', fmt(s.battery?.capacity)],
|
||||
['电池类型', fmt(s.battery?.type)],
|
||||
['有线充电', fmt(s.battery?.wired)],
|
||||
['无线充电', fmt(s.battery?.wireless)],
|
||||
['反向充电', fmt(s.battery?.reverse)],
|
||||
['充电协议', fmt(s.battery?.chargingProtocol)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '传感器',
|
||||
rows: [
|
||||
['指纹', fmt(s.sensors?.fingerprint)],
|
||||
['指纹类型', fmt(s.sensors?.fingerprintType)],
|
||||
['指纹位置', fmt(s.sensors?.fingerprintPosition)],
|
||||
['陀螺仪', fmt(s.sensors?.gyro)],
|
||||
['气压计', fmt(s.sensors?.barometer)],
|
||||
['色温传感器', fmt(s.sensors?.colorSensor)],
|
||||
['闪烁传感器', fmt(s.sensors?.flickerSensor)],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '系统与更新',
|
||||
rows: [
|
||||
['出厂版本', fmt(s.software?.launchVersion)],
|
||||
['当前版本', fmt(s.software?.currentVersion)],
|
||||
['更新策略', fmt(s.software?.updatePolicy)],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const visibleGroups = groups
|
||||
.map((g) => ({ title: g.title, rows: g.rows.filter((row) => row[1] !== undefined) }))
|
||||
.filter((g) => g.rows.length > 0);
|
||||
|
||||
const cameras = [
|
||||
{ title: '后置影像', list: s.rearCamera },
|
||||
{ title: '前置影像', list: s.frontCamera },
|
||||
].filter((c) => c.list.length > 0);
|
||||
---
|
||||
|
||||
<BaseLayout title={`${device.brand} ${device.model} 规格 · LFSpecs`} description={device.summary}>
|
||||
<nav class="text-xs text-muted-foreground">
|
||||
<a href="/devices" class="hover:text-foreground">手机</a>
|
||||
<span class="mx-1.5">/</span>
|
||||
<span class="text-foreground">{device.model}</span>
|
||||
</nav>
|
||||
|
||||
<header class="mt-3">
|
||||
<p class="text-sm text-muted-foreground">{device.brand}</p>
|
||||
<h1 class="mt-1 text-3xl font-semibold tracking-tight">{device.model}</h1>
|
||||
{device.aliases.length > 0 && (
|
||||
<p class="mt-1.5 text-xs text-muted-foreground">别名:{device.aliases.join('、')}</p>
|
||||
)}
|
||||
{device.summary && <p class="mt-3 max-w-2xl text-sm text-muted-foreground">{device.summary}</p>}
|
||||
</header>
|
||||
|
||||
<dl class="tabular mt-6 grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6">
|
||||
{
|
||||
[
|
||||
['SoC', s.platform?.chipset],
|
||||
['屏幕', s.display?.size],
|
||||
['电池', s.battery?.capacity],
|
||||
['主摄', s.rearCamera[0]?.resolution],
|
||||
['重量', s.body?.weight],
|
||||
['存储', s.memory?.storage],
|
||||
].map(([label, value]) => (
|
||||
<div class="rounded-lg border border-border bg-card p-3">
|
||||
<dt class="text-[11px] text-muted-foreground">{label}</dt>
|
||||
<dd class="mt-1 truncate text-sm font-medium">{value ?? '—'}</dd>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</dl>
|
||||
|
||||
{
|
||||
soc && (
|
||||
<div class="mt-6 rounded-lg border border-border bg-card p-4">
|
||||
<div class="flex flex-wrap items-baseline justify-between gap-2">
|
||||
<div>
|
||||
<span class="text-xs text-muted-foreground">SoC</span>
|
||||
<a href={`/chips/${soc.slug}`} class="ml-2 text-sm font-medium text-primary hover:underline">
|
||||
{soc.brand} {soc.model}
|
||||
</a>
|
||||
</div>
|
||||
<span class="tabular text-xs text-muted-foreground">
|
||||
{soc.process ?? ''} {soc.arch ? `· ${soc.arch}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
{
|
||||
cameras.map((section) => (
|
||||
<section class="mt-10">
|
||||
<h2 class="text-lg font-semibold">{section.title}</h2>
|
||||
<div class="mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{section.list.map((cam) => (
|
||||
<div class="rounded-lg border border-border bg-card p-4">
|
||||
<div class="flex items-baseline justify-between">
|
||||
<span class="text-sm font-medium">{cam.position}</span>
|
||||
<span class="tabular text-xs text-muted-foreground">{cam.resolution ?? ''}</span>
|
||||
</div>
|
||||
<dl class="tabular mt-3 grid grid-cols-2 gap-x-3 gap-y-1 text-xs">
|
||||
{[
|
||||
['传感器', cam.sensorModel],
|
||||
['光圈', cam.aperture],
|
||||
['等效焦距', cam.focalLength],
|
||||
['传感器尺寸', cam.sensorSize],
|
||||
['单像素', cam.pixelSize],
|
||||
['镜片', cam.lensElements],
|
||||
['变焦', cam.zoom],
|
||||
['OIS', fmt(cam.ois)],
|
||||
['对焦', cam.autofocusType],
|
||||
['最高视频', cam.video?.max],
|
||||
]
|
||||
.filter(([, v]) => v !== undefined)
|
||||
.map(([k, v]) => (
|
||||
<>
|
||||
<dt class="text-muted-foreground">{k}</dt>
|
||||
<dd class="text-right">{v}</dd>
|
||||
</>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
))
|
||||
}
|
||||
|
||||
{
|
||||
visibleGroups.map((group) => (
|
||||
<section class="mt-10">
|
||||
<h2 class="text-lg font-semibold">{group.title}</h2>
|
||||
<table class="mt-3 w-full border-collapse text-sm">
|
||||
<tbody>
|
||||
{group.rows.map(([label, value]) => (
|
||||
<tr class="border-b border-border/60">
|
||||
<th class="w-36 py-2 text-left align-top text-xs font-normal text-muted-foreground">{label}</th>
|
||||
<td class="tabular py-2">{value}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
))
|
||||
}
|
||||
|
||||
<p class="mt-12 text-xs text-muted-foreground">
|
||||
共 {device.meta.length} 条字段级来源记录,其中人工核实 {device.meta.filter((m) => m.verified).length} 条。
|
||||
</p>
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,55 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { listDevices } from '@/lib/repo';
|
||||
|
||||
const devices = listDevices({ category: 'phone' });
|
||||
---
|
||||
|
||||
<BaseLayout title="手机规格库 · LFSpecs">
|
||||
<div class="flex items-baseline justify-between">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">手机</h1>
|
||||
<span class="tabular text-sm text-muted-foreground">{devices.length} 款</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{
|
||||
devices.map((device) => (
|
||||
<a
|
||||
href={`/devices/${device.slug}`}
|
||||
class="group rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<div>
|
||||
<div class="text-xs text-muted-foreground">{device.brand}</div>
|
||||
<div class="mt-0.5 text-base font-semibold">{device.model}</div>
|
||||
</div>
|
||||
<span class="rounded-full border border-border px-2 py-0.5 text-[11px] text-muted-foreground">
|
||||
{device.lifecycle === 'discontinued' ? '已停产' : device.lifecycle === 'announced' ? '已发布' : '在售'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<dl class="tabular mt-4 grid grid-cols-2 gap-x-4 gap-y-1 text-xs">
|
||||
<dt class="text-muted-foreground">SoC</dt>
|
||||
<dd class="truncate text-right">{device.specs.platform?.chipset ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">屏幕</dt>
|
||||
<dd class="truncate text-right">{device.specs.display?.size ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">电池</dt>
|
||||
<dd class="truncate text-right">{device.specs.battery?.capacity ?? '—'}</dd>
|
||||
<dt class="text-muted-foreground">重量</dt>
|
||||
<dd class="truncate text-right">{device.specs.body?.weight ?? '—'}</dd>
|
||||
</dl>
|
||||
|
||||
{device.summary && <p class="mt-4 line-clamp-2 text-xs text-muted-foreground">{device.summary}</p>}
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
devices.length === 0 && (
|
||||
<p class="mt-6 rounded-lg border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
|
||||
暂无手机数据,运行 <code class="font-mono text-foreground">pnpm db:seed</code> 写入种子数据。
|
||||
</p>
|
||||
)
|
||||
}
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import { countChips, countDevices, listDevices } from '@/lib/repo';
|
||||
|
||||
const phoneCount = countDevices('phone');
|
||||
const socCount = countChips('soc');
|
||||
const latest = listDevices({ category: 'phone' }).slice(0, 6);
|
||||
---
|
||||
|
||||
<BaseLayout>
|
||||
<section>
|
||||
<h1 class="text-3xl font-semibold tracking-tight">硬件规格库</h1>
|
||||
<p class="mt-2 max-w-2xl text-sm text-muted-foreground">
|
||||
收录手机与芯片的详细参数,颗粒度到摄像头传感器型号、振动马达与扬声器单元。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section class="mt-8 grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||
<a href="/devices" class="rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40">
|
||||
<div class="text-xs text-muted-foreground">手机收录</div>
|
||||
<div class="tabular mt-1 text-2xl font-semibold">{phoneCount}</div>
|
||||
</a>
|
||||
<a href="/chips" class="rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40">
|
||||
<div class="text-xs text-muted-foreground">SoC 收录</div>
|
||||
<div class="tabular mt-1 text-2xl font-semibold">{socCount}</div>
|
||||
</a>
|
||||
</section>
|
||||
|
||||
<section class="mt-12">
|
||||
<div class="flex items-baseline justify-between">
|
||||
<h2 class="text-lg font-semibold">最新收录</h2>
|
||||
<a href="/devices" class="text-sm text-muted-foreground hover:text-foreground">全部手机 →</a>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{
|
||||
latest.map((device) => (
|
||||
<a
|
||||
href={`/devices/${device.slug}`}
|
||||
class="group rounded-lg border border-border bg-card p-5 transition-colors hover:border-primary/40"
|
||||
>
|
||||
<div class="text-xs text-muted-foreground">{device.brand}</div>
|
||||
<div class="mt-0.5 text-base font-semibold">{device.model}</div>
|
||||
<div class="tabular mt-3 text-xs text-muted-foreground">
|
||||
{device.specs.platform?.chipset ?? '未填写 SoC'}
|
||||
{' · '}
|
||||
{device.specs.display?.size ?? '—'}
|
||||
{' · '}
|
||||
{device.specs.battery?.capacity ?? '—'}
|
||||
</div>
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
{
|
||||
latest.length === 0 && (
|
||||
<p class="mt-4 rounded-lg border border-dashed border-border p-8 text-center text-sm text-muted-foreground">
|
||||
还没有数据。先运行 <code class="font-mono text-foreground">pnpm db:seed</code> 写入种子数据。
|
||||
</p>
|
||||
)
|
||||
}
|
||||
</section>
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
import BaseLayout from '@/layouts/BaseLayout.astro';
|
||||
import DemoDialog from '@/components/DemoDialog.tsx';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
---
|
||||
|
||||
<BaseLayout title="组件自检 · LFSpecs">
|
||||
<h1 class="text-2xl font-semibold tracking-tight">组件自检</h1>
|
||||
<p class="mt-2 max-w-2xl text-sm text-muted-foreground">
|
||||
验证 Button / Card / Dialog 三个 shadcn/ui 组件在 Astro 中的渲染与交互。M0 验收后可删除此页。
|
||||
</p>
|
||||
|
||||
<section class="mt-8">
|
||||
<h2 class="text-sm font-semibold text-muted-foreground">Button</h2>
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
<Button>主要</Button>
|
||||
<Button variant="secondary">次要</Button>
|
||||
<Button variant="outline">描边</Button>
|
||||
<Button variant="ghost">幽灵</Button>
|
||||
<Button variant="destructive">危险</Button>
|
||||
<Button size="sm">小号</Button>
|
||||
<Button size="lg">大号</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mt-8">
|
||||
<h2 class="text-sm font-semibold text-muted-foreground">Card</h2>
|
||||
<div class="mt-3 grid gap-3 sm:grid-cols-2">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>普通卡片</CardTitle>
|
||||
<CardDescription>服务端渲染,零 JS</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="text-sm text-muted-foreground">卡片主体内容。</CardContent>
|
||||
<CardFooter>
|
||||
<Button size="sm" variant="outline">操作</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
|
||||
<Card class="border-primary/40">
|
||||
<CardHeader>
|
||||
<CardTitle>强调卡片</CardTitle>
|
||||
<CardDescription>强调色描边</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent class="text-sm text-muted-foreground">用于高亮关键信息。</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mt-8">
|
||||
<h2 class="text-sm font-semibold text-muted-foreground">Dialog(需要 JS)</h2>
|
||||
<div class="mt-3">
|
||||
<DemoDialog client:load />
|
||||
</div>
|
||||
</section>
|
||||
</BaseLayout>
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { extname, join, normalize } from 'node:path';
|
||||
|
||||
const ROOT = process.env.UPLOADS_DIR ?? 'data/uploads';
|
||||
|
||||
const CONTENT_TYPES: Record<string, string> = {
|
||||
'.webp': 'image/webp',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.png': 'image/png',
|
||||
'.avif': 'image/avif',
|
||||
'.svg': 'image/svg+xml',
|
||||
};
|
||||
|
||||
export const GET: APIRoute = async ({ params }) => {
|
||||
const rel = (params.path ?? '').replace(/\\/g, '/');
|
||||
const safe = normalize(rel);
|
||||
|
||||
// 防路径穿越:拒绝任何包含 .. 的请求
|
||||
if (safe.startsWith('..') || safe.includes('..') || rel.startsWith('/')) {
|
||||
return new Response('Bad request', { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const buf = await readFile(join(ROOT, safe));
|
||||
return new Response(new Uint8Array(buf), {
|
||||
headers: {
|
||||
'content-type': CONTENT_TYPES[extname(safe).toLowerCase()] ?? 'application/octet-stream',
|
||||
'cache-control': 'public, max-age=31536000, immutable',
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new Response('Not found', { status: 404 });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* 深色为主的中性色板,强调色用青绿 */
|
||||
:root {
|
||||
--background: #0b0d0f;
|
||||
--foreground: #e8eaed;
|
||||
--card: #121518;
|
||||
--card-foreground: #e8eaed;
|
||||
--popover: #121518;
|
||||
--popover-foreground: #e8eaed;
|
||||
--primary: #2dd4bf;
|
||||
--primary-foreground: #04110f;
|
||||
--secondary: #1c2126;
|
||||
--secondary-foreground: #e8eaed;
|
||||
--muted: #1a1e23;
|
||||
--muted-foreground: #9aa3ad;
|
||||
--accent: #1c2126;
|
||||
--accent-foreground: #e8eaed;
|
||||
--destructive: #f87171;
|
||||
--border: #242a30;
|
||||
--input: #242a30;
|
||||
--ring: #2dd4bf;
|
||||
--radius: 0.625rem;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--color-card: var(--card);
|
||||
--color-card-foreground: var(--card-foreground);
|
||||
--color-popover: var(--popover);
|
||||
--color-popover-foreground: var(--popover-foreground);
|
||||
--color-primary: var(--primary);
|
||||
--color-primary-foreground: var(--primary-foreground);
|
||||
--color-secondary: var(--secondary);
|
||||
--color-secondary-foreground: var(--secondary-foreground);
|
||||
--color-muted: var(--muted);
|
||||
--color-muted-foreground: var(--muted-foreground);
|
||||
--color-accent: var(--accent);
|
||||
--color-accent-foreground: var(--accent-foreground);
|
||||
--color-destructive: var(--destructive);
|
||||
--color-border: var(--border);
|
||||
--color-input: var(--input);
|
||||
--color-ring: var(--ring);
|
||||
|
||||
--radius-sm: calc(var(--radius) - 4px);
|
||||
--radius-md: calc(var(--radius) - 2px);
|
||||
--radius-lg: var(--radius);
|
||||
--radius-xl: calc(var(--radius) + 4px);
|
||||
|
||||
--font-sans: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
|
||||
--font-mono: ui-monospace, "JetBrains Mono", Consolas, monospace;
|
||||
}
|
||||
|
||||
@layer base {
|
||||
* {
|
||||
border-color: var(--color-border);
|
||||
}
|
||||
|
||||
html {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: var(--color-background);
|
||||
color: var(--color-foreground);
|
||||
font-family: var(--font-sans);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
/* 参数值对齐:等宽数字 */
|
||||
.tabular {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "astro/tsconfigs/strict",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"jsx": "react-jsx",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": [".astro/types.d.ts", "**/*"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
Reference in new issue
Block a user