410 lines
13 KiB
JavaScript
410 lines
13 KiB
JavaScript
import { DatabaseSync } from 'node:sqlite';
|
||
import { existsSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
|
||
import { dirname, join } from 'node:path';
|
||
|
||
if (existsSync('.env')) process.loadEnvFile('.env');
|
||
|
||
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' },
|
||
{ microArch: 'Cortex-A720', count: 2, clockMax: '2.96 GHz', l2: '512 KB' },
|
||
],
|
||
},
|
||
{
|
||
name: '能效核',
|
||
cores: [{ microArch: 'Cortex-A520', count: 2, clockMax: '2.27 GHz', l2: '512 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)' },
|
||
systemCache: '6 MB',
|
||
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 5 单核', score: '1700', unit: 'pts' },
|
||
{ name: 'Geekbench 5 多核', score: '6600', unit: 'pts' },
|
||
{ name: 'Geekbench 6 单核', score: '2300', unit: 'pts' },
|
||
{ name: 'Geekbench 6 多核', score: '7400', unit: 'pts' },
|
||
{ name: '安兔兔 V10', score: '2200000', unit: 'pts' },
|
||
{ name: '安兔兔 V11', score: '2300000', 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.20 mm(玻璃)/ 8.28 mm(科技纳米皮)',
|
||
weight: '193 g(玻璃)/ 188 g(科技纳米皮)',
|
||
build: { front: '康宁大猩猩 Victus 2', back: '玻璃 / 科技纳米皮', frame: '铝合金边框' },
|
||
sim: '2 × Nano-SIM',
|
||
ipRating: 'IP68',
|
||
colors: ['黑色', '白色', '岩石青', '雪山粉'],
|
||
buttons: '右侧电源 + 音量',
|
||
cooling: '环形冷泵散热系统',
|
||
},
|
||
display: {
|
||
size: '6.36 英寸',
|
||
resolution: '2670 x 1200',
|
||
cutout: '中孔',
|
||
aspectRatio: '20.0:9',
|
||
panel: 'OLED',
|
||
vendor: '华星光电(TCL 华星)',
|
||
technology: 'C8 发光材质',
|
||
refreshRate: '120Hz 自适应',
|
||
refreshRange: '1-120Hz',
|
||
refreshNote: 'LTPO 1-120Hz 自适应刷新率',
|
||
touchSampling: '240Hz',
|
||
touchSamplingInstant: '最高 2160Hz',
|
||
colorDepth: '12bit / 687 亿色',
|
||
colorGamut: 'DCI-P3',
|
||
pixelDensity: '460 PPI',
|
||
equivalentPpi: '375 PPI',
|
||
screenBodyRatio: '89.3%',
|
||
bezel: '侧边 2.64mm,上+下 5.45mm',
|
||
width16x9: '5.34 英寸',
|
||
brightnessTypical: '600 nit',
|
||
brightnessPeak: '3000 nit',
|
||
hdr: 'HDR10+ / HDR Vivid / Dolby Vision',
|
||
protection: '康宁大猩猩 Victus 2',
|
||
pwmDimming: '1920Hz PWM',
|
||
alwaysOn: true,
|
||
features: [
|
||
'专业原色屏',
|
||
'超动态显示',
|
||
'柔性直屏',
|
||
'前后双光感',
|
||
'心率检测',
|
||
'莱茵低蓝光认证',
|
||
'支持类DC调光',
|
||
'支持环境色温调节',
|
||
],
|
||
},
|
||
platform: { os: 'Android 14', skin: 'Xiaomi HyperOS', chipset: 'Snapdragon 8 Gen 3' },
|
||
memory: {
|
||
ram: '8 / 12 / 16 GB',
|
||
ramType: 'LPDDR5X 8400 MT/s(4 × 16bit)',
|
||
storage: '256 / 512 GB / 1TB',
|
||
storageType: 'UFS 4.0',
|
||
storageSpeed: '约 4.2 GB/s 顺序读取',
|
||
cardSlot: '无',
|
||
},
|
||
rearCamera: [
|
||
{
|
||
position: 'wide',
|
||
sensorModel: 'OmniVision OV50H',
|
||
sensorAlias: '光影猎人 900',
|
||
resolution: '50MP(默认合 1 输出 1250 万像素)',
|
||
aperture: 'f/1.6',
|
||
focalLength: '23mm',
|
||
sensorSize: '1/1.31"',
|
||
pixelSize: '1.2µm',
|
||
lensElements: '7P',
|
||
ois: true,
|
||
eis: true,
|
||
zoom: '1x',
|
||
autofocusType: '全像素全向对焦 + 激光对焦',
|
||
video: {
|
||
max: '8K@24fps',
|
||
modes: ['4K@60fps HDR10+ 录像', '1080p@240fps 慢动作', '电影模式'],
|
||
stabilization: 'OIS + EIS',
|
||
},
|
||
flash: '双色温 LED 闪光灯',
|
||
extra: {},
|
||
},
|
||
{
|
||
position: 'tele',
|
||
sensorModel: 'Samsung S5KJN1',
|
||
resolution: '50MP',
|
||
aperture: 'f/2.0',
|
||
focalLength: '75mm(60mm 裁切)',
|
||
sensorSize: '1/2.76"',
|
||
pixelSize: '0.64µm',
|
||
lensElements: '6P',
|
||
ois: true,
|
||
zoom: '2.6x 光学(60mm)/ 3.2x(75mm)',
|
||
autofocusType: 'PDAF + 10cm 以上自动对焦',
|
||
extra: {},
|
||
},
|
||
{
|
||
position: 'ultrawide',
|
||
sensorModel: 'Samsung S5KJN1',
|
||
resolution: '50MP',
|
||
aperture: 'f/2.2',
|
||
focalLength: '14mm',
|
||
sensorSize: '1/2.76"',
|
||
pixelSize: '0.64µm',
|
||
lensElements: '6P',
|
||
fov: '115°',
|
||
ois: false,
|
||
zoom: '0.6x',
|
||
extra: {},
|
||
},
|
||
],
|
||
frontCamera: [
|
||
{
|
||
position: 'front',
|
||
sensorModel: 'OmniVision OV32B',
|
||
resolution: '32MP',
|
||
aperture: 'f/2.0',
|
||
focalLength: '22mm',
|
||
sensorSize: '1/3.14"',
|
||
pixelSize: '0.7µm',
|
||
video: { max: '4K@60fps', modes: [], stabilization: 'EIS' },
|
||
extra: {},
|
||
},
|
||
],
|
||
vibration: { type: 'X 轴线性马达', model: '瑞声 0809B', size: '0809', volume: '约 1.0 cm³' },
|
||
speakers: {
|
||
count: 2,
|
||
stereo: true,
|
||
units: [
|
||
{ position: 'top', label: '上', model: 'AAC 1115K', size: '11 × 15 mm' },
|
||
{ position: 'bottom', label: '下', model: 'AAC 1014', size: '10 × 14 mm' },
|
||
],
|
||
dolbyAtmos: true,
|
||
hiRes: true,
|
||
loudnessDba: '82 dB',
|
||
headphoneJack: false,
|
||
},
|
||
connectivity: {
|
||
cellular: '5G 双模双卡双通',
|
||
bands: ['n1', 'n3', 'n5', 'n8', 'n28a', 'n38', 'n41', 'n77', 'n78', 'B1', 'B3', 'B5', 'B8', 'B34', 'B38', 'B39', 'B40', 'B41'],
|
||
satellite: false,
|
||
satelliteBands: [],
|
||
wifi: 'Wi-Fi 7(802.11be),2.4 / 5 / 6 GHz,2×2 MIMO,MLO 2.0,8×8 Sounding MU-MIMO,Wi-Fi Direct / Miracast',
|
||
bluetooth: '5.4,Dual-Bluetooth,AAC / AptX / AptX HD / AptX Adaptive / LDAC / LHDC 5.0',
|
||
nfc: true,
|
||
gps: '北斗 B1I + B1C + B2a,GPS L1 + L5,Galileo E1 + E5a,GLONASS G1,QZSS L1 + L5,NavIC L5,AGNSS',
|
||
usb: 'USB 3.2 Gen 1 Type-C(双面椭圆口)',
|
||
usbSpeed: '5 Gbps',
|
||
usbVideoOut: true,
|
||
ir: true,
|
||
uwb: false,
|
||
},
|
||
battery: {
|
||
capacity: '4610 mAh',
|
||
type: '锂聚合物',
|
||
wired: '90W',
|
||
wireless: '50W',
|
||
reverse: '10W',
|
||
chargingProtocol: 'QC4 / QC3+ / QC3.0 / QC2.0 / PD3.0 / PD2.0 / 小米 FC 2.0 快充',
|
||
},
|
||
sensors: {
|
||
fingerprint: '短焦屏下指纹识别',
|
||
fingerprintType: '光学',
|
||
fingerprintPosition: '屏下短焦',
|
||
gyro: true,
|
||
barometer: true,
|
||
colorSensor: true,
|
||
flickerSensor: true,
|
||
list: [
|
||
'距离传感器',
|
||
'屏下环境光(色温)传感器',
|
||
'后置环境光(色温)传感器',
|
||
'加速度传感器',
|
||
'陀螺仪',
|
||
'电子罗盘',
|
||
'红外线遥控器',
|
||
'flicker 传感器',
|
||
'激光对焦传感器',
|
||
'气压计',
|
||
'NFC',
|
||
],
|
||
},
|
||
software: {
|
||
launchVersion: 'Xiaomi HyperOS',
|
||
currentVersion: 'Android 15 / HyperOS 2.0',
|
||
updatePolicy: '4 代大版本 + 5 年安全更新',
|
||
updateTimeline: [
|
||
'2024-06-01 HyperOS 1.0.12(Android 14)',
|
||
'2025-01-15 HyperOS 2.0(Android 15)',
|
||
],
|
||
},
|
||
features: [
|
||
'轻薄小屏旗舰',
|
||
'5G 双模双卡双通',
|
||
'120Hz 自适应刷新率',
|
||
'IP68 防尘防水',
|
||
'4 麦克风',
|
||
'双扬声器(1014 + 1115K)',
|
||
'徕卡影像',
|
||
],
|
||
cameraFeatures: [
|
||
'徕卡影像',
|
||
'4K@60fps HDR10+ 录像',
|
||
'前后双景',
|
||
'10bit 色彩',
|
||
'13.5EV 高动态范围',
|
||
'电影模式',
|
||
],
|
||
benchmarks: [
|
||
'Geekbench 5 单核 1700',
|
||
'Geekbench 5 多核 6600',
|
||
'Geekbench 6 单核 2300',
|
||
'Geekbench 6 多核 7400',
|
||
'GFXBench 曼哈顿 3.1 High 95.0 fps',
|
||
'GFXBench Aztec Ruins High 95.0 fps',
|
||
'综合效能(CPU GB5 + GPU)80550',
|
||
'3DMark Wild Life Unlimited 19500',
|
||
'3DMark Wild Life Extreme 5250',
|
||
'3DMark Solar Bay 8650',
|
||
'安兔兔 V10 2200000',
|
||
'安兔兔 V11 2300000',
|
||
],
|
||
pricing: ['8GB+256GB 3999 元', '12GB+256GB 4299 元', '16GB+512GB 4599 元', '16GB+1TB 4999 元'],
|
||
officialUrl: 'https://www.mi.com/xiaomi-14',
|
||
extra: {
|
||
备注: '厚度 8.20mm(玻璃版)/ 8.28mm(科技纳米皮版);重量 193g(玻璃版)/ 188g(科技纳米皮版)',
|
||
耳机接口: 'USB Type-C(与充电口共用)',
|
||
},
|
||
},
|
||
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,
|
||
},
|
||
{
|
||
path: 'specs.display.vendor',
|
||
confidence: 'high',
|
||
sourceUrl: 'https://www.mi.com/xiaomi-14/specs',
|
||
verified: true,
|
||
capturedAt: now,
|
||
},
|
||
{
|
||
path: 'specs.benchmarks',
|
||
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 seedDevices = [phone, ...JSON.parse(readFileSync('scripts/seed-devices.json', 'utf8'))];
|
||
|
||
for (const device of seedDevices) {
|
||
const deviceValues = [
|
||
device.slug, device.category, device.subCategory ?? null, device.brand, device.model,
|
||
JSON.stringify(device.aliases ?? []), device.announceDate ?? null, device.releaseDate ?? null,
|
||
device.lifecycle, device.cover ?? null, JSON.stringify(device.gallery ?? []),
|
||
JSON.stringify(device.tags ?? []), device.summary ?? null, JSON.stringify(device.specs),
|
||
JSON.stringify(device.chipRefs ?? {}), JSON.stringify(device.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(`种子数据写入完成:${seedDevices.map((device) => device.slug).join(' / ')} / snapdragon-8-gen-3`);
|
||
db.close();
|