初始化 M0:Astro SSR + node:sqlite 脚手架与只读页面
This commit is contained in:
1 parent
97440b4120
commit
8430e5304d
39 files changed
+6398
-1
No files matched your search
@@ -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();
|
||||
Reference in new issue
Block a user