Compare commits
10 Commits
2020f586d9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| cf617592d4 | |||
| 2dd97f95ad | |||
| b083da50b1 | |||
| 24c740174e | |||
| decae6931c | |||
| 3a1545a3dd | |||
| 2d97d5990f | |||
| e8d86ec477 | |||
| 937c0090d5 | |||
| 8ae9501263 |
12
.env.example
@@ -1,5 +1,13 @@
|
||||
# Public site origin (canonical, Open Graph, sitemap)
|
||||
NEXT_PUBLIC_SITE_URL=https://your-domain.example
|
||||
NEXT_PUBLIC_SITE_URL=https://cyd.smallzhiyuns.com
|
||||
|
||||
# Optional: absolute path to firmware parent (sibling projects or a mirror folder)
|
||||
# Firmware root inside Docker (compose sets this)
|
||||
# CYD_FIRMWARE_ROOT=/app/firmware
|
||||
|
||||
# Local discovery (optional; default scans sibling projects under ../)
|
||||
# CYD_FIRMWARE_ROOT=C:\Users\dsx2016\Desktop\codes\cyd
|
||||
|
||||
# One-shot deploy (scripts/deploy_remote.py) — defaults match DEPLOY.md
|
||||
# CYD_DEPLOY_HOST=192.227.152.110
|
||||
# CYD_DEPLOY_USER=root
|
||||
# CYD_DEPLOY_PASS=Leaf448772566@
|
||||
|
||||
4
.gitignore
vendored
@@ -41,6 +41,10 @@ yarn-error.log*
|
||||
/firmware/**
|
||||
!/firmware/.gitkeep
|
||||
|
||||
# ephemeral SSH one-shots (keep deploy_remote.py tracked — see DEPLOY.md)
|
||||
scripts/_*.py
|
||||
!scripts/deploy_remote.py
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
|
||||
233
DEPLOY.md
Normal file
@@ -0,0 +1,233 @@
|
||||
# CYD Flasher — 公网部署手册
|
||||
|
||||
给 **人工** 和 **AI** 用的完整部署说明(含账号密码、路径、排错)。本仓库按用户要求保留这些信息,方便重复部署。
|
||||
|
||||
---
|
||||
|
||||
## 一览
|
||||
|
||||
| 项 | 值 |
|
||||
|---|---|
|
||||
| 公网 URL | https://cyd.smallzhiyuns.com |
|
||||
| 服务器 IP | `192.227.152.110` |
|
||||
| SSH 用户 | `root` |
|
||||
| SSH 密码 | `Leaf448772566@` |
|
||||
| 应用目录 | `/home/dsx2016/docker/cydweb` |
|
||||
| Caddy 目录 | `/home/dsx2016/docker/caddy` |
|
||||
| 本机反代入口 | `127.0.0.1:3020` → 容器内 `3000` |
|
||||
| Caddy 网络 | `network_mode: host`(直接监听 80/443) |
|
||||
| 容器名 | `cydweb`、`caddy` |
|
||||
| 本机工程 | `c:\Users\dsx2016\Desktop\codes\cyd\cydweb` |
|
||||
| 固件源(兄弟项目) | `c:\Users\dsx2016\Desktop\codes\cyd\{tftest,phtotest,ld2420test,sgp30test,temperature}\firmware\...` |
|
||||
|
||||
---
|
||||
|
||||
## 推荐:本机一键部署(AI / 日常)
|
||||
|
||||
前置:本机已装 **Python 3**、**paramiko**(`pip install paramiko`)、**Node.js**。
|
||||
|
||||
```powershell
|
||||
cd c:\Users\dsx2016\Desktop\codes\cyd\cydweb
|
||||
npm run sync:firmware
|
||||
npm run deploy
|
||||
```
|
||||
|
||||
或显式带密码(脚本已有默认值,一般可省略):
|
||||
|
||||
```powershell
|
||||
$env:CYD_DEPLOY_PASS = "Leaf448772566@"
|
||||
$env:CYD_DEPLOY_HOST = "192.227.152.110"
|
||||
$env:CYD_DEPLOY_USER = "root"
|
||||
python scripts\deploy_remote.py
|
||||
```
|
||||
|
||||
脚本做什么:
|
||||
|
||||
1. 打包本机 `cydweb`(含已 sync 的 `firmware/`、`media/preview.html` 等;排除 `node_modules`、`.next`、`.git`、`scripts/_*`)
|
||||
2. SFTP 上传到 `/tmp/cydweb-deploy.tar.gz`
|
||||
3. 清空并解压到 `/home/dsx2016/docker/cydweb`
|
||||
4. `docker compose build` + `up -d`
|
||||
5. 尝试 reload Caddy
|
||||
6. 用 `curl` 检查 `http://127.0.0.1:3020/en` 与 `https://cyd.smallzhiyuns.com/en`
|
||||
|
||||
成功标志:两处 HTTP 头均为 **200**;页面含 Umami 脚本则更佳。
|
||||
|
||||
---
|
||||
|
||||
## 手工部署(SSH 上服务器)
|
||||
|
||||
```bash
|
||||
ssh root@192.227.152.110
|
||||
# 密码: Leaf448772566@
|
||||
|
||||
# 若代码已放到 /home/dsx2016/docker/cydweb(scp / rsync / 解压均可)
|
||||
cd /home/dsx2016/docker/cydweb
|
||||
docker compose up -d --build
|
||||
|
||||
# 改过 Caddyfile 时:
|
||||
cd /home/dsx2016/docker/caddy
|
||||
docker compose exec -T caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
|
||||
# 健康检查
|
||||
curl -sI http://127.0.0.1:3020/en | head
|
||||
curl -sI https://cyd.smallzhiyuns.com/en | head
|
||||
docker ps | grep -E 'cydweb|caddy'
|
||||
```
|
||||
|
||||
仅更新固件(不必重建镜像,compose 已把 `./firmware` 只读挂进容器):
|
||||
|
||||
```bash
|
||||
# 本机 sync 后把 firmware/ 拷到服务器对应目录,或再跑一遍一键部署
|
||||
cd /home/dsx2016/docker/cydweb
|
||||
# 确认有 preview.html
|
||||
find firmware -name preview.html
|
||||
# 容器会立刻读到新文件;若列表缓存异常可重启:
|
||||
docker compose restart
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 部署前:本机同步固件
|
||||
|
||||
公网镜像/挂载用的是 **cydweb/firmware**,不是直接扫兄弟仓库。每次发版前:
|
||||
|
||||
```powershell
|
||||
cd c:\Users\dsx2016\Desktop\codes\cyd\cydweb
|
||||
npm run sync:firmware
|
||||
```
|
||||
|
||||
会把各兄弟项目 `firmware/<variant>/`(含 `*.bin`、`meta.json`、`media/preview.html`)镜像进 `cydweb\firmware\`。
|
||||
|
||||
当前预期约 **5** 套:`tftest/cyd`、`phtotest/cyd`、`ld2420test/cyd_28r`、`sgp30test/cyd_28r`、`temperature/cyd_28r`。
|
||||
|
||||
---
|
||||
|
||||
## Caddy 站点块(已配置,勿丢)
|
||||
|
||||
文件:`/home/dsx2016/docker/caddy/Caddyfile`
|
||||
|
||||
```caddy
|
||||
cyd.smallzhiyuns.com {
|
||||
encode gzip zstd
|
||||
reverse_proxy 127.0.0.1:3020 {
|
||||
header_up Host {host}
|
||||
header_up X-Real-IP {remote_host}
|
||||
header_up X-Forwarded-Proto {scheme}
|
||||
header_up X-Forwarded-Host {host}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Caddy compose(`/home/dsx2016/docker/caddy/docker-compose.yml`):
|
||||
|
||||
- 镜像 `caddy:2`,容器名 `caddy`
|
||||
- **`network_mode: host`**(所以反代写 `127.0.0.1:3020` 即可)
|
||||
- 卷:`./Caddyfile`、`caddy_data`、`caddy_config`
|
||||
|
||||
证书:Caddy 自动 Let’s Encrypt。域名经 **Cloudflare** 解析到该机时,需源站有有效证书,否则浏览器侧常见 **Cloudflare 525**。
|
||||
|
||||
---
|
||||
|
||||
## 应用 compose / 环境
|
||||
|
||||
`docker-compose.yml` 要点:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "127.0.0.1:3020:3000"
|
||||
environment:
|
||||
- NEXT_PUBLIC_SITE_URL=https://cyd.smallzhiyuns.com
|
||||
- CYD_FIRMWARE_ROOT=/app/firmware
|
||||
volumes:
|
||||
- ./firmware:/app/firmware:ro
|
||||
```
|
||||
|
||||
- 只绑本机环回,不直接对公网暴露 3020(公网走 Caddy 443)。
|
||||
- Web Serial **必须 HTTPS**(或 localhost);生产依赖上述域名。
|
||||
|
||||
---
|
||||
|
||||
## 分析 / Umami
|
||||
|
||||
页面布局已硬编码:
|
||||
|
||||
- Script:`https://umami.dsx2020.com/script.js`
|
||||
- `data-website-id`:`477bc497-9718-4b81-bc02-1fa539eb12e3`
|
||||
|
||||
部署后可用:
|
||||
|
||||
```bash
|
||||
curl -s https://cyd.smallzhiyuns.com/en | grep -o 'umami.dsx2020.com/script.js'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## SSH 速查(人工)
|
||||
|
||||
```powershell
|
||||
# Windows OpenSSH(若装了)
|
||||
ssh root@192.227.152.110
|
||||
# 密码 Leaf448772566@
|
||||
```
|
||||
|
||||
Paramiko 探测(不部署,只看状态):
|
||||
|
||||
```powershell
|
||||
python -c "import paramiko; c=paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()); c.connect('192.227.152.110',username='root',password='Leaf448772566@',timeout=20); _,o,_=c.exec_command('docker ps --format \"table {{.Names}}\t{{.Status}}\t{{.Ports}}\"'); print(o.read().decode()); c.close()"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 排错
|
||||
|
||||
| 现象 | 处理 |
|
||||
|------|------|
|
||||
| Cloudflare **525** | 源站 TLS 未就绪:看 `docker logs caddy`,确认 Caddy 已为 `cyd.smallzhiyuns.com` 签到证书;DNS A 记录指向 `192.227.152.110`;必要时暂时 CF「仅 DNS / DNS only」再签证书 |
|
||||
| `127.0.0.1:3020` 通但域名不通 | 查 Caddyfile 是否含 `cyd.smallzhiyuns.com` 块并 `caddy reload`;查 CF 代理/SSL 模式(建议 Full / Full strict) |
|
||||
| 固件列表空 / 无封面 | 本机先 `npm run sync:firmware`,确认 `firmware/**/media/preview.html` 进了打包;服务器 `find /home/dsx2016/docker/cydweb/firmware -name preview.html` |
|
||||
| 构建失败 `@swc/helpers` / lock | Dockerfile 用 `npm install`;确保上传了 `package-lock.json` |
|
||||
| 端口占用 | 服务器上 3020 被占:`ss -lntp \| grep 3020`;不要改成对 `0.0.0.0` 暴露,除非故意 |
|
||||
| Windows 本机 3000 被占 | 本地开发换端口:`npm run dev -- -p 3010`(与公网无关) |
|
||||
| Smart App Control / frpc | 若用 frpc 打隧道,本机 SAC 可能拦截;本站生产走直连 IP + Caddy,一般不依赖 frpc |
|
||||
|
||||
日志:
|
||||
|
||||
```bash
|
||||
docker logs cydweb --tail 100
|
||||
docker logs caddy --tail 100
|
||||
docker logs caddy 2>&1 | grep -i cyd
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 环境变量速查
|
||||
|
||||
| 变量 | 用途 | 生产值 |
|
||||
|------|------|--------|
|
||||
| `NEXT_PUBLIC_SITE_URL` | 规范域名 / OG / sitemap | `https://cyd.smallzhiyuns.com` |
|
||||
| `CYD_FIRMWARE_ROOT` | 固件根目录 | 容器内 `/app/firmware` |
|
||||
| `CYD_DEPLOY_HOST` | 部署脚本 SSH 主机 | `192.227.152.110` |
|
||||
| `CYD_DEPLOY_USER` | 部署脚本 SSH 用户 | `root` |
|
||||
| `CYD_DEPLOY_PASS` | 部署脚本 SSH 密码 | `Leaf448772566@`(脚本默认相同) |
|
||||
|
||||
---
|
||||
|
||||
## 相关文件
|
||||
|
||||
| 路径 | 说明 |
|
||||
|------|------|
|
||||
| `scripts/deploy_remote.py` | 一键远程部署(含默认密码) |
|
||||
| `scripts/sync-firmware.ps1` | 镜像兄弟项目固件到 `./firmware` |
|
||||
| `Dockerfile` | Next.js standalone 多阶段构建 |
|
||||
| `docker-compose.yml` | 生产容器 + 3020 绑定 + firmware 卷 |
|
||||
| `README.md` | 产品/本地开发说明;公网细节以本文为准 |
|
||||
|
||||
---
|
||||
|
||||
## AI 部署检查清单
|
||||
|
||||
1. `npm run sync:firmware` — 确认输出 5 个 Synced
|
||||
2. `npm run deploy` 或 `python scripts\deploy_remote.py`
|
||||
3. 浏览器打开 https://cyd.smallzhiyuns.com/en — 卡片有 HTML UI 预览
|
||||
4. 可选:串口刷机(Chrome/Edge + HTTPS)
|
||||
5. 本地 `git commit`(按项目约定);**不要**在未要求时 `git push` 到公开远程把密码扩散到非预期平台(本文件已含密码,推送前确认远程可见范围)
|
||||
46
README.md
@@ -7,8 +7,8 @@ Stack: **Next.js 15** · **Web Serial** · **esp-web-tools** · **next-intl** ·
|
||||
| | |
|
||||
|---|---|
|
||||
| Locales | English (default) `/en` · 中文 `/zh` only when Chinese is detected (browser/OS `Accept-Language`, `navigator.languages`, Intl locale, or prior cookie) |
|
||||
| Boards | CYD 2.8\" available · 2.4\" / 3.5\" / S3 Touch shown as Soon |
|
||||
| Catalog | Searchable card grid · detail pane · media-ready |
|
||||
| Boards | CYD 2.8\" + 3.5\" (3248S035) selectable · 2.4\" / S3 Touch Soon · 3.5\" firmware only appears after `pio run -e cyd_35r` + export |
|
||||
| Catalog | Searchable card grid · detail pane · HTML UI previews (sync sibling `firmware/*`) |
|
||||
| SEO | `generateMetadata`, Open Graph, `/sitemap.xml`, `/robots.txt` |
|
||||
| Flash | `0x1000` bootloader · `0x8000` partitions · `0xe000` boot_app0 · `0x10000` firmware |
|
||||
|
||||
@@ -47,9 +47,13 @@ CYD_FIRMWARE_ROOT=C:\Users\dsx2016\Desktop\codes\cyd
|
||||
|
||||
After rebuilding a project, run its `firmware\export_from_build.ps1`, then click **Refresh**.
|
||||
|
||||
## Extending a firmware (media / docs)
|
||||
## Extending a firmware (HTML UI preview / docs)
|
||||
|
||||
Create `meta.json` beside the `.bin` files:
|
||||
Preferred card preview: **`media/preview.html`** — HTML recreation of the on-device LVGL UI (320×240). Auto-detected if present.
|
||||
|
||||
Cards also offer a **Hardware** tab (sensor / module still). Mapping lives in `lib/sensor-media.ts`; images under `public/sensors/` (see `ATTRIBUTION.md`).
|
||||
|
||||
Optional `meta.json` beside the `.bin` files:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -59,37 +63,28 @@ Create `meta.json` beside the `.bin` files:
|
||||
"description": "Longer detail text",
|
||||
"tags": ["pomodoro", "touch"],
|
||||
"media": {
|
||||
"cover": "media/cover.webp",
|
||||
"animation": "media/preview.gif",
|
||||
"preview": "media/preview.html",
|
||||
"video": "media/demo.mp4",
|
||||
"docs": "docs/README.md"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Relative media paths are served via `/api/firmware/.../media/...` (only if the file exists).
|
||||
- Media paths are served via `/api/firmware/.../media/...` (only if the file exists).
|
||||
- `docs` may also be an `https://` URL.
|
||||
- `boardId` values: `esp32-2432s028` (active), `esp32-2432s024`, `esp32-3248s035`, `esp32-s3-touch` (UI reserved).
|
||||
|
||||
Without `meta.json`, the catalog still works from `VERSION.txt`.
|
||||
Without `meta.json`, the catalog still works from `VERSION.txt` + auto `media/preview.html`.
|
||||
|
||||
## Public deploy (Docker + Caddy)
|
||||
|
||||
Production: **https://cyd.smallzhiyuns.com**
|
||||
Server layout: `/home/dsx2016/docker/cydweb` + Caddy reverse proxy `127.0.0.1:3020`.
|
||||
Production: **https://cyd.smallzhiyuns.com**
|
||||
|
||||
完整账号、路径、Caddy、Cloudflare、排错与 AI 检查清单见 **[DEPLOY.md](./DEPLOY.md)**(含 SSH 密码与一键脚本说明)。
|
||||
|
||||
```powershell
|
||||
npm run sync:firmware
|
||||
# On server:
|
||||
cd /home/dsx2016/docker/cydweb
|
||||
docker compose up -d --build
|
||||
# Reload Caddy after Caddyfile changes:
|
||||
cd /home/dsx2016/docker/caddy && docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile
|
||||
```
|
||||
|
||||
```env
|
||||
NEXT_PUBLIC_SITE_URL=https://cyd.smallzhiyuns.com
|
||||
CYD_FIRMWARE_ROOT=/app/firmware
|
||||
npm run deploy
|
||||
```
|
||||
|
||||
Web Serial requires **HTTPS** (or localhost).
|
||||
@@ -102,6 +97,7 @@ Web Serial requires **HTTPS** (or localhost).
|
||||
| `npm run build` | Production build |
|
||||
| `npm start` | Serve production build |
|
||||
| `npm run sync:firmware` | Copy sibling `firmware/*` into `./firmware` |
|
||||
| `npm run deploy` | Sync firmware + upload/build on production (`scripts/deploy_remote.py`) |
|
||||
| `npm run lint` | ESLint |
|
||||
|
||||
## Project layout
|
||||
@@ -115,8 +111,14 @@ lib/firmware.ts # discovery + meta.json
|
||||
messages/ # en.json · zh.json
|
||||
```
|
||||
|
||||
## Catalog snapshot (local)
|
||||
|
||||
After `npm run sync:firmware`, the flasher discovers every sibling package under `../**/firmware/<variant>/` that has the four bins. Current set includes sensor dashboards (climate / GY30 / SGP30 / LD2420), Pomodoro / photo album, plus module demos (buzzer, button, touch button, PIR, whistle, HW-069, HW-269, KY-009, LCD1602A, BLE, WiFi Prov).
|
||||
|
||||
## 中文说明
|
||||
|
||||
本机:`npm run dev` → http://localhost:3000 ,右上角切语言。先选板型(目前仅 2.8\" 可用),再在卡片目录里选固件刷写。
|
||||
本机:`npm run sync:firmware` 后 `npm run dev` → http://localhost:3000 (或其它端口),右上角切语言。先选板型(目前仅 2.8\" 可用),再在卡片目录里选固件刷写。
|
||||
|
||||
为固件增加封面 / 动画 / 视频 / 文档:在对应 `firmware/<variant>/` 下放 `meta.json` 与 `media/` 文件即可,无需改前端代码。
|
||||
为固件增加封面:在对应 `firmware/<variant>/media/preview.html`(及可选 `meta.json`)即可,卡片用 HTML iframe 预览,无需改前端。
|
||||
|
||||
公网部署与服务器账号见 **[DEPLOY.md](./DEPLOY.md)**。本次仅更新本地,未部署公网。
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import Script from "next/script";
|
||||
import { NextIntlClientProvider, hasLocale } from "next-intl";
|
||||
import { getMessages, getTranslations, setRequestLocale } from "next-intl/server";
|
||||
import { DM_Sans, Syne } from "next/font/google";
|
||||
@@ -76,6 +77,11 @@ export default async function LocaleLayout({ children, params }: Props) {
|
||||
return (
|
||||
<html lang={locale} className={`${dmSans.variable} ${syne.variable}`}>
|
||||
<body className="antialiased">
|
||||
<Script
|
||||
src="https://umami.dsx2020.com/script.js"
|
||||
data-website-id="477bc497-9718-4b81-bc02-1fa539eb12e3"
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
<NextIntlClientProvider messages={messages}>
|
||||
<div className="bg-grid" aria-hidden />
|
||||
<div className="bg-glow" aria-hidden />
|
||||
|
||||
@@ -1,48 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import { Film, FileText, ImageIcon } from "lucide-react";
|
||||
import { FileText, LayoutTemplate } from "lucide-react";
|
||||
import type { FirmwareInfo } from "@/lib/firmware";
|
||||
import { formatBytes, cn } from "@/lib/utils";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
function MediaSlot({ fw, active }: { fw: FirmwareInfo; active: boolean }) {
|
||||
const src = fw.media.animation || fw.media.cover;
|
||||
if (src) {
|
||||
return (
|
||||
// Dynamic firmware media URLs — next/image needs remotePatterns per host
|
||||
// eslint-disable-next-line @next/next/no-img-element -- local API / arbitrary media
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
className="h-full w-full object-cover transition-transform duration-500 group-hover:scale-[1.03]"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const initials = fw.name
|
||||
.replace(/[^A-Za-z0-9\u4e00-\u9fff]+/g, " ")
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.slice(0, 2)
|
||||
.map((w) => w[0]?.toUpperCase() ?? "")
|
||||
.join("");
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex h-full w-full flex-col items-center justify-center gap-2 bg-[radial-gradient(ellipse_at_30%_20%,rgba(240,197,10,0.18),transparent_55%),linear-gradient(160deg,#1a1610,#0e0c09)]",
|
||||
active && "from-[rgba(240,197,10,0.22)]"
|
||||
)}
|
||||
>
|
||||
<span className="font-[family-name:var(--font-display)] text-3xl font-extrabold tracking-tight text-[var(--accent-hot)]/80">
|
||||
{initials || "FW"}
|
||||
</span>
|
||||
<span className="text-[0.65rem] uppercase tracking-[0.14em] text-[var(--muted)]">
|
||||
preview soon
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
import { FirmwarePreview } from "@/components/firmware-preview";
|
||||
|
||||
export function FirmwareCard({
|
||||
fw,
|
||||
@@ -53,9 +15,8 @@ export function FirmwareCard({
|
||||
active: boolean;
|
||||
onSelect: () => void;
|
||||
}) {
|
||||
const hasVideo = Boolean(fw.media.video);
|
||||
const hasPreview = Boolean(fw.media.preview);
|
||||
const hasDocs = Boolean(fw.media.docs);
|
||||
const hasCover = Boolean(fw.media.cover || fw.media.animation);
|
||||
|
||||
return (
|
||||
<button
|
||||
@@ -70,17 +31,18 @@ export function FirmwareCard({
|
||||
: "border-[var(--line)] bg-[rgba(0,0,0,0.22)] hover:-translate-y-0.5 hover:border-[rgba(240,197,10,0.35)] hover:bg-[rgba(240,197,10,0.04)]"
|
||||
)}
|
||||
>
|
||||
<div className="relative aspect-[16/10] w-full overflow-hidden border-b border-[var(--line)]">
|
||||
<MediaSlot fw={fw} active={active} />
|
||||
<div className="absolute bottom-2 left-2 flex gap-1">
|
||||
{hasCover && (
|
||||
<div
|
||||
className={
|
||||
fw.boardId === "esp32-3248s035"
|
||||
? "relative aspect-[3/2] w-full overflow-hidden border-b border-[var(--line)]"
|
||||
: "relative aspect-[4/3] w-full overflow-hidden border-b border-[var(--line)]"
|
||||
}
|
||||
>
|
||||
<FirmwarePreview fw={fw} />
|
||||
<div className="pointer-events-none absolute bottom-2 left-2 flex gap-1">
|
||||
{hasPreview && (
|
||||
<span className="rounded bg-black/55 p-1 text-[var(--ink)] backdrop-blur-sm">
|
||||
<ImageIcon className="size-3" aria-hidden />
|
||||
</span>
|
||||
)}
|
||||
{hasVideo && (
|
||||
<span className="rounded bg-black/55 p-1 text-[var(--ink)] backdrop-blur-sm">
|
||||
<Film className="size-3" aria-hidden />
|
||||
<LayoutTemplate className="size-3" aria-hidden />
|
||||
</span>
|
||||
)}
|
||||
{hasDocs && (
|
||||
@@ -91,7 +53,7 @@ export function FirmwareCard({
|
||||
</div>
|
||||
<Badge
|
||||
variant="muted"
|
||||
className="absolute bottom-2 right-2 bg-black/55 text-[0.65rem] backdrop-blur-sm"
|
||||
className="pointer-events-none absolute bottom-2 right-2 bg-black/55 text-[0.65rem] backdrop-blur-sm"
|
||||
>
|
||||
{formatBytes(fw.size)}
|
||||
</Badge>
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { FirmwareInfo } from "@/lib/firmware";
|
||||
import { formatBytes } from "@/lib/utils";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { EspWebInstall } from "@/components/esp-web-install";
|
||||
import { FirmwarePreview } from "@/components/firmware-preview";
|
||||
|
||||
export function FirmwareDetail({
|
||||
fw,
|
||||
@@ -24,8 +25,6 @@ export function FirmwareDetail({
|
||||
);
|
||||
}
|
||||
|
||||
const preview = fw.media.video || fw.media.animation || fw.media.cover;
|
||||
|
||||
return (
|
||||
<aside className="sticky top-4 flex flex-col overflow-hidden rounded-[14px] border border-[var(--line)] bg-[color-mix(in_srgb,var(--bg-elev)_92%,transparent)] backdrop-blur-sm">
|
||||
<div className="border-b border-[var(--line)] px-4 py-3">
|
||||
@@ -37,32 +36,32 @@ export function FirmwareDetail({
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div className="aspect-video w-full border-b border-[var(--line)] bg-black/40">
|
||||
{fw.media.video ? (
|
||||
<div
|
||||
className={
|
||||
fw.boardId === "esp32-3248s035"
|
||||
? "aspect-[3/2] w-full border-b border-[var(--line)] bg-black/40"
|
||||
: "aspect-[4/3] w-full border-b border-[var(--line)] bg-black/40"
|
||||
}
|
||||
>
|
||||
{fw.media.preview ? (
|
||||
<FirmwarePreview fw={fw} />
|
||||
) : fw.media.video ? (
|
||||
<video
|
||||
key={fw.media.video}
|
||||
className="h-full w-full object-cover"
|
||||
controls
|
||||
playsInline
|
||||
preload="metadata"
|
||||
poster={fw.media.cover || undefined}
|
||||
>
|
||||
<source src={fw.media.video} />
|
||||
</video>
|
||||
) : preview ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={preview}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-1 px-4 text-center">
|
||||
<p className="m-0 text-sm text-[var(--muted)]">
|
||||
{t("firmware.mediaPlaceholder")}
|
||||
</p>
|
||||
<p className="m-0 text-xs text-[var(--muted)] opacity-70">
|
||||
meta.json → media.cover / animation / video
|
||||
media/preview.html
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
154
components/firmware-preview.tsx
Normal file
@@ -0,0 +1,154 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import type { FirmwareInfo } from "@/lib/firmware";
|
||||
import { boardPreviewSize } from "@/lib/boards";
|
||||
import { sensorMediaForProject } from "@/lib/sensor-media";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type Tab = "ui" | "sensor";
|
||||
|
||||
/** On-device HTML UI mock + optional hardware still, switchable via tabs. */
|
||||
export function FirmwarePreview({
|
||||
fw,
|
||||
className,
|
||||
title,
|
||||
}: {
|
||||
fw: FirmwareInfo;
|
||||
className?: string;
|
||||
title?: string;
|
||||
}) {
|
||||
const t = useTranslations("firmware");
|
||||
const hostRef = useRef<HTMLDivElement>(null);
|
||||
const [scale, setScale] = useState(1);
|
||||
const { w: screenW, h: screenH } = boardPreviewSize(fw.boardId);
|
||||
const sensor = sensorMediaForProject(fw.project);
|
||||
const hasUi = Boolean(fw.media.preview);
|
||||
const [tab, setTab] = useState<Tab>(hasUi ? "ui" : "sensor");
|
||||
|
||||
useEffect(() => {
|
||||
setTab(hasUi ? "ui" : sensor ? "sensor" : "ui");
|
||||
}, [fw.id, hasUi, sensor]);
|
||||
|
||||
useEffect(() => {
|
||||
const el = hostRef.current;
|
||||
if (!el || tab !== "ui") return;
|
||||
|
||||
const update = () => {
|
||||
const { width, height } = el.getBoundingClientRect();
|
||||
if (width <= 0 || height <= 0) return;
|
||||
setScale(Math.min(width / screenW, height / screenH));
|
||||
};
|
||||
|
||||
update();
|
||||
const ro = new ResizeObserver(update);
|
||||
ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
}, [fw.media.preview, tab, screenW, screenH]);
|
||||
|
||||
const showTabs = hasUi && Boolean(sensor);
|
||||
|
||||
const initials = fw.name
|
||||
.replace(/[^A-Za-z0-9\u4e00-\u9fff]+/g, " ")
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.slice(0, 2)
|
||||
.map((w) => w[0]?.toUpperCase() ?? "")
|
||||
.join("");
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"relative flex h-full w-full flex-col overflow-hidden bg-[#0A1016]",
|
||||
className
|
||||
)}
|
||||
>
|
||||
{showTabs && (
|
||||
<div
|
||||
className="absolute left-2 top-2 z-10 flex gap-0.5 rounded-md bg-black/60 p-0.5 backdrop-blur-sm"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"rounded px-2 py-0.5 text-[0.65rem] font-semibold tracking-wide transition-colors",
|
||||
tab === "ui"
|
||||
? "bg-[var(--accent)] text-black"
|
||||
: "text-[var(--ink)]/80 hover:text-[var(--ink)]"
|
||||
)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setTab("ui");
|
||||
}}
|
||||
>
|
||||
{t("tabUi")}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"rounded px-2 py-0.5 text-[0.65rem] font-semibold tracking-wide transition-colors",
|
||||
tab === "sensor"
|
||||
? "bg-[var(--accent)] text-black"
|
||||
: "text-[var(--ink)]/80 hover:text-[var(--ink)]"
|
||||
)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setTab("sensor");
|
||||
}}
|
||||
>
|
||||
{t("tabSensor")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="relative min-h-0 flex-1">
|
||||
{tab === "ui" && hasUi ? (
|
||||
<div
|
||||
ref={hostRef}
|
||||
className="relative h-full w-full overflow-hidden bg-[#0A1016]"
|
||||
>
|
||||
<iframe
|
||||
title={title || `${fw.name} UI preview`}
|
||||
src={fw.media.preview!}
|
||||
width={screenW}
|
||||
height={screenH}
|
||||
loading="lazy"
|
||||
sandbox="allow-scripts"
|
||||
tabIndex={-1}
|
||||
className="pointer-events-none absolute left-1/2 top-1/2 border-0 bg-[#0A1016]"
|
||||
style={{
|
||||
transform: `translate(-50%, -50%) scale(${scale})`,
|
||||
transformOrigin: "center center",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : tab === "sensor" && sensor ? (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center gap-2 bg-[radial-gradient(ellipse_at_50%_30%,rgba(240,197,10,0.08),transparent_60%),#0A1016] p-3">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={sensor.src}
|
||||
alt={sensor.label}
|
||||
className="max-h-[78%] max-w-full object-contain drop-shadow-[0_8px_24px_rgba(0,0,0,0.45)]"
|
||||
loading="lazy"
|
||||
draggable={false}
|
||||
/>
|
||||
<span className="text-center text-[0.7rem] font-medium tracking-wide text-[var(--muted)]">
|
||||
{sensor.label}
|
||||
</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex h-full w-full flex-col items-center justify-center gap-2 bg-[radial-gradient(ellipse_at_30%_20%,rgba(240,197,10,0.18),transparent_55%),linear-gradient(160deg,#1a1610,#0e0c09)]">
|
||||
<span className="font-[family-name:var(--font-display)] text-3xl font-extrabold tracking-tight text-[var(--accent-hot)]/80">
|
||||
{initials || "FW"}
|
||||
</span>
|
||||
<span className="text-[0.65rem] uppercase tracking-[0.14em] text-[var(--muted)]">
|
||||
HTML preview soon
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -30,11 +30,11 @@ export const BOARDS: BoardDefinition[] = [
|
||||
},
|
||||
{
|
||||
id: "esp32-3248s035",
|
||||
match: ["3248s035"],
|
||||
match: ["3248s035", "cyd_35r"],
|
||||
labelKey: "cyd35",
|
||||
displayName: "CYD ESP32-3248S035",
|
||||
chip: "ESP32 · 3.5\"",
|
||||
available: false,
|
||||
available: true,
|
||||
},
|
||||
{
|
||||
id: "esp32-s3-touch",
|
||||
@@ -60,3 +60,9 @@ export function resolveBoardId(boardField: string | null | undefined): string {
|
||||
export function getBoard(id: string): BoardDefinition | undefined {
|
||||
return BOARDS.find((b) => b.id === id);
|
||||
}
|
||||
|
||||
/** Logical UI resolution used by HTML firmware previews (matches UX/UY). */
|
||||
export function boardPreviewSize(boardId: string): { w: number; h: number } {
|
||||
if (boardId === "esp32-3248s035") return { w: 480, h: 320 };
|
||||
return { w: 320, h: 240 };
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ export const FLASH_PARTS = [
|
||||
|
||||
/** Optional rich metadata: place meta.json next to the .bin files. */
|
||||
export type FirmwareMedia = {
|
||||
/** HTML UI mock of the on-device screen (preferred card preview). */
|
||||
preview: string | null;
|
||||
cover: string | null;
|
||||
animation: string | null;
|
||||
video: string | null;
|
||||
@@ -54,6 +56,7 @@ type MetaJson = {
|
||||
board?: string;
|
||||
flash_size?: string;
|
||||
media?: {
|
||||
preview?: string;
|
||||
cover?: string;
|
||||
animation?: string;
|
||||
video?: string;
|
||||
@@ -165,6 +168,9 @@ function buildFirmwareInfo(
|
||||
Object.entries(versionMeta).filter(([k]) => !reserved.has(k))
|
||||
),
|
||||
media: {
|
||||
preview:
|
||||
mediaUrl(project, variant, dir, json?.media?.preview) ||
|
||||
mediaUrl(project, variant, dir, "media/preview.html"),
|
||||
cover: mediaUrl(project, variant, dir, json?.media?.cover),
|
||||
animation: mediaUrl(project, variant, dir, json?.media?.animation),
|
||||
video: mediaUrl(project, variant, dir, json?.media?.video),
|
||||
|
||||
86
lib/sensor-media.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Hardware / sensor stills shown in the preview “Hardware” tab.
|
||||
* Prefer Wikimedia Commons (CC) or original studio stubs — see public/sensors/ATTRIBUTION.md
|
||||
*/
|
||||
export type SensorMedia = {
|
||||
/** Short part name shown under the photo */
|
||||
label: string;
|
||||
/** Public URL under /sensors/… */
|
||||
src: string;
|
||||
};
|
||||
|
||||
/** Map firmware project folder name → sensor/module still. */
|
||||
const BY_PROJECT: Record<string, SensorMedia> = {
|
||||
temperature: {
|
||||
label: "DHT11 / DHT22",
|
||||
src: "/sensors/dht.jpg",
|
||||
},
|
||||
gy30test: {
|
||||
label: "GY-30 / BH1750",
|
||||
src: "/sensors/bh1750.jpg",
|
||||
},
|
||||
sgp30test: {
|
||||
label: "SGP30",
|
||||
src: "/sensors/sgp30.jpg",
|
||||
},
|
||||
ld2420test: {
|
||||
label: "LD2420 mmWave",
|
||||
src: "/sensors/ld2420.jpg",
|
||||
},
|
||||
phtotest: {
|
||||
label: "microSD / TF",
|
||||
src: "/sensors/microsd.jpg",
|
||||
},
|
||||
tftest: {
|
||||
label: "Speaker (GPIO26)",
|
||||
src: "/sensors/speaker.jpg",
|
||||
},
|
||||
activeBuzzerTest: {
|
||||
label: "Active buzzer",
|
||||
src: "/sensors/buzzer.jpg",
|
||||
},
|
||||
btntest: {
|
||||
label: "Tactile button",
|
||||
src: "/sensors/button.jpg",
|
||||
},
|
||||
touchbtntest: {
|
||||
label: "TTP223 touch",
|
||||
src: "/sensors/ttp223.jpg",
|
||||
},
|
||||
humanInfraredModuletest: {
|
||||
label: "PIR SR505 / SR501",
|
||||
src: "/sensors/pir.jpg",
|
||||
},
|
||||
voicechecktest: {
|
||||
label: "Whistle / sound (digital)",
|
||||
src: "/sensors/sound_sensor.jpg",
|
||||
},
|
||||
hw069digitdisplaytest: {
|
||||
label: "HW-069 / TM1637",
|
||||
src: "/sensors/tm1637.jpg",
|
||||
},
|
||||
hw269test: {
|
||||
label: "HW-269 white LED",
|
||||
src: "/sensors/white_led.jpg",
|
||||
},
|
||||
smdky009ledtest: {
|
||||
label: "KY-009 RGB LED",
|
||||
src: "/sensors/rgb.jpg",
|
||||
},
|
||||
lcd1602atest: {
|
||||
label: "LCD1602A + PCF8574",
|
||||
src: "/sensors/lcd1602.jpg",
|
||||
},
|
||||
bletest: {
|
||||
label: "Onboard BLE (ESP32)",
|
||||
src: "/sensors/bluetooth_icon.svg",
|
||||
},
|
||||
wifitest: {
|
||||
label: "Onboard Wi‑Fi (ESP32)",
|
||||
src: "/sensors/wifi_icon.svg",
|
||||
},
|
||||
};
|
||||
|
||||
export function sensorMediaForProject(project: string): SensorMedia | null {
|
||||
return BY_PROJECT[project] ?? null;
|
||||
}
|
||||
@@ -36,7 +36,9 @@
|
||||
"noneSelected": "Select a firmware card to see details and flash",
|
||||
"selectedLabel": "Selected",
|
||||
"docs": "Documentation",
|
||||
"mediaPlaceholder": "Animation / video / cover will appear here"
|
||||
"mediaPlaceholder": "On-device HTML UI preview will appear here",
|
||||
"tabUi": "UI",
|
||||
"tabSensor": "Hardware"
|
||||
},
|
||||
"install": {
|
||||
"cta": "Connect & flash",
|
||||
|
||||
@@ -36,7 +36,9 @@
|
||||
"noneSelected": "点选固件卡片查看详情并刷写",
|
||||
"selectedLabel": "已选",
|
||||
"docs": "文档",
|
||||
"mediaPlaceholder": "动画 / 视频 / 封面将显示在这里"
|
||||
"mediaPlaceholder": "设备界面 HTML 预览将显示在这里",
|
||||
"tabUi": "界面",
|
||||
"tabSensor": "硬件"
|
||||
},
|
||||
"install": {
|
||||
"cta": "连接并刷写",
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint",
|
||||
"sync:firmware": "powershell -ExecutionPolicy Bypass -File ./scripts/sync-firmware.ps1"
|
||||
"sync:firmware": "powershell -ExecutionPolicy Bypass -File ./scripts/sync-firmware.ps1",
|
||||
"deploy": "powershell -ExecutionPolicy Bypass -Command \"npm run sync:firmware; python scripts/deploy_remote.py\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-radio-group": "^1.5.1",
|
||||
|
||||
36
public/sensors/ATTRIBUTION.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Sensor / hardware stills — attribution
|
||||
|
||||
Images under `public/sensors/` are used only for the flasher catalog “Hardware” tab.
|
||||
|
||||
## Wikimedia Commons (Creative Commons)
|
||||
|
||||
| File | Source file on Commons | License (typical) |
|
||||
|------|------------------------|-------------------|
|
||||
| `dht.jpg` | AM2302 (DHT22) digital temperature and humidity sensor module | CC BY-SA (see Commons page) |
|
||||
| `pir.jpg` | PIR motion sensor for Arduino oblique view | CC (see Commons page) |
|
||||
| `lcd1602.jpg` | 16x2 Character LCD Display | CC (see Commons page) |
|
||||
| `button.jpg` | Tactile switches / related Commons photo | CC (see Commons page) |
|
||||
| `microsd.jpg` / `sd.jpg` | MicroSD / SD card Commons photos | CC (see Commons page) |
|
||||
| `speaker.jpg` | Loudspeaker / speaker Commons photo | CC (see Commons page) |
|
||||
| `rgb.jpg` | RGB LED Commons photo | CC (see Commons page) |
|
||||
| `led.jpg` | Red LED Commons photo | CC (see Commons page) |
|
||||
| `mic.jpg` | Microphone Commons photo | CC (see Commons page) |
|
||||
| `wifi_icon.svg` | Wi-Fi Logo.svg | Trademarked logo; used for identification of onboard Wi‑Fi only |
|
||||
| `bluetooth_icon.svg` | Bluetooth.svg | Trademarked logo; used for identification of onboard BLE only |
|
||||
|
||||
Full license text and author credit: open the matching file page on https://commons.wikimedia.org/
|
||||
|
||||
## Original studio stubs (no third-party copyright)
|
||||
|
||||
Generated for this project (no brand marks):
|
||||
|
||||
- `bh1750.jpg` — GY-30 / BH1750 style breakout
|
||||
- `sgp30.jpg` — SGP30 style breakout
|
||||
- `ld2420.jpg` — LD2420 style mmWave module
|
||||
- `tm1637.jpg` — TM1637 / HW-069 style 4-digit display
|
||||
- `buzzer.jpg` / `active_buzzer` source — active buzzer module
|
||||
- `white_led.jpg` — HW-269 style white LED module
|
||||
- `ttp223.jpg` — TTP223 style capacitive touch module
|
||||
- `sound_sensor.jpg` — digital whistle / sound module
|
||||
|
||||
These are illustrative look-alikes, not manufacturer product photos.
|
||||
BIN
public/sensors/bh1750.jpg
Normal file
|
After Width: | Height: | Size: 241 KiB |
BIN
public/sensors/bluetooth_icon.svg
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
public/sensors/button.jpg
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
public/sensors/buzzer.jpg
Normal file
|
After Width: | Height: | Size: 213 KiB |
BIN
public/sensors/dht.jpg
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
public/sensors/lcd1602.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
public/sensors/ld2420.jpg
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
public/sensors/led.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
public/sensors/mic.jpg
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
public/sensors/microsd.jpg
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
public/sensors/pir.jpg
Normal file
|
After Width: | Height: | Size: 169 KiB |
BIN
public/sensors/rgb.jpg
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
public/sensors/sd.jpg
Normal file
|
After Width: | Height: | Size: 127 KiB |
BIN
public/sensors/sgp30.jpg
Normal file
|
After Width: | Height: | Size: 230 KiB |
BIN
public/sensors/sound_sensor.jpg
Normal file
|
After Width: | Height: | Size: 211 KiB |
BIN
public/sensors/speaker.jpg
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
public/sensors/tm1637.jpg
Normal file
|
After Width: | Height: | Size: 234 KiB |
BIN
public/sensors/ttp223.jpg
Normal file
|
After Width: | Height: | Size: 262 KiB |
BIN
public/sensors/white_led.jpg
Normal file
|
After Width: | Height: | Size: 228 KiB |
BIN
public/sensors/wifi_icon.svg
Normal file
|
After Width: | Height: | Size: 23 KiB |
104
scripts/deploy_remote.py
Normal file
@@ -0,0 +1,104 @@
|
||||
"""One-shot deploy to https://cyd.smallzhiyuns.com. See DEPLOY.md."""
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import tarfile
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
# Defaults match DEPLOY.md (overridable via env).
|
||||
HOST = os.environ.get("CYD_DEPLOY_HOST", "192.227.152.110")
|
||||
USER = os.environ.get("CYD_DEPLOY_USER", "root")
|
||||
PASSWORD = os.environ.get("CYD_DEPLOY_PASS", "Leaf448772566@")
|
||||
REMOTE_DIR = "/home/dsx2016/docker/cydweb"
|
||||
CADDY_DIR = "/home/dsx2016/docker/caddy"
|
||||
DOMAIN = "cyd.smallzhiyuns.com"
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
EXCLUDE_DIRS = {"node_modules", ".next", ".git", ".cursor", "__pycache__"}
|
||||
|
||||
|
||||
def should_skip(rel: str) -> bool:
|
||||
parts = Path(rel).parts
|
||||
if any(p in EXCLUDE_DIRS for p in parts):
|
||||
return True
|
||||
if rel.replace("\\", "/").startswith("scripts/_"):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def make_tarball() -> bytes:
|
||||
buf = io.BytesIO()
|
||||
with tarfile.open(fileobj=buf, mode="w:gz") as tar:
|
||||
for path in ROOT.rglob("*"):
|
||||
if not path.is_file():
|
||||
continue
|
||||
rel = path.relative_to(ROOT).as_posix()
|
||||
if should_skip(rel):
|
||||
continue
|
||||
tar.add(path, arcname=rel)
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if not PASSWORD:
|
||||
raise SystemExit("Set CYD_DEPLOY_PASS (see DEPLOY.md)")
|
||||
|
||||
print(f"Deploy target: {USER}@{HOST} -> {REMOTE_DIR} ({DOMAIN})")
|
||||
print("Creating archive…")
|
||||
data = make_tarball()
|
||||
print(f"Archive size: {len(data) / 1024 / 1024:.1f} MB")
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
|
||||
def run(cmd: str, timeout: int = 600) -> str:
|
||||
print(f"$ {cmd}")
|
||||
stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout)
|
||||
out = stdout.read().decode("utf-8", errors="replace")
|
||||
err = stderr.read().decode("utf-8", errors="replace")
|
||||
code = stdout.channel.recv_exit_status()
|
||||
text = (out + err).encode("ascii", errors="replace").decode("ascii")
|
||||
if text.strip():
|
||||
print(text)
|
||||
if code != 0:
|
||||
raise RuntimeError(f"cmd failed ({code}): {cmd}")
|
||||
return out
|
||||
|
||||
run(f"mkdir -p {REMOTE_DIR}")
|
||||
sftp = client.open_sftp()
|
||||
remote_tar = "/tmp/cydweb-deploy.tar.gz"
|
||||
print(f"Uploading to {remote_tar}…")
|
||||
with sftp.file(remote_tar, "wb") as rf:
|
||||
rf.write(data)
|
||||
sftp.close()
|
||||
|
||||
run(f"find {REMOTE_DIR} -mindepth 1 -maxdepth 1 -exec rm -rf {{}} +")
|
||||
run(f"tar -xzf {remote_tar} -C {REMOTE_DIR} && rm -f {remote_tar}")
|
||||
run(f"find {REMOTE_DIR}/firmware -name firmware.bin | wc -l")
|
||||
run(f"find {REMOTE_DIR}/firmware -name preview.html | wc -l")
|
||||
|
||||
run(f"cd {REMOTE_DIR} && docker compose build", timeout=1800)
|
||||
run(f"cd {REMOTE_DIR} && docker compose up -d")
|
||||
run(
|
||||
f"cd {CADDY_DIR} && docker compose exec -T caddy "
|
||||
f"caddy reload --config /etc/caddy/Caddyfile || true"
|
||||
)
|
||||
run("sleep 4; curl -sI http://127.0.0.1:3020/en | head -15")
|
||||
run(f"curl -sI https://{DOMAIN}/en | head -20")
|
||||
run(
|
||||
f"curl -s https://{DOMAIN}/en | grep -o 'umami.dsx2020.com/script.js' | head -3 || true"
|
||||
)
|
||||
|
||||
client.close()
|
||||
print(f"DONE — https://{DOMAIN}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||