feat(ota): 新增获取各「型号+灰度」分组全局最大版本号接口

- 后端新增 /api/ota/latest-versions 接口,返回所有型号和灰度的最大版本号
- 添加数据库查询,基于全量数据分组聚合版本号,避免分页误判最新版本
- 前端新增 fetchGetOtaLatestVersions 接口调用该后端接口
- 在 OTA 页面加入全局最新版本数据加载与缓存,用于 latest 标签判断
- 修改标签判定逻辑,避免仅基于当前页数据导致的错误标记
- 调用时机调整,增删改 OTA 后刷新全局最新版本数据保持同步
This commit is contained in:
eafonyang
2026-08-17 15:11:50 +08:00
parent 952b8bb76e
commit 19ea48ffc8
4 changed files with 56 additions and 10 deletions
+24 -1
View File
@@ -1,5 +1,5 @@
import { Router, type Request, type Response, type Router as RouterType } from 'express';
import { eq, gt, like, and, desc, count } from 'drizzle-orm';
import { eq, gt, like, and, desc, count, max } from 'drizzle-orm';
import multer from 'multer';
import { db } from '../config/database.js';
import { otas } from '../schemas/index.js';
@@ -159,6 +159,29 @@ router.get('/api/ota/', async (req: Request, res: Response) => {
}
});
// GET /api/ota/latest-versions —— 各「型号+灰度」分组的全局最大版本号
// 供前端 latest / latest beta 标签判断:必须基于全量数据,
// 否则分页后「当前页内」的最大版本会被误标为 latest
router.get('/api/ota/latest-versions', async (_req: Request, res: Response) => {
try {
const rows = await db
.select({ model: otas.model, beta: otas.beta, maxVerCode: max(otas.verCode) })
.from(otas)
.groupBy(otas.model, otas.beta);
const items = rows.map(r => ({
model: r.model ?? '',
beta: r.beta ?? 0,
ver_code: Number(r.maxVerCode),
}));
res.json(ApiResponse.success({ items }));
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
logger.error(`Error getting OTA latest versions: ${msg}`);
res.json(ApiResponse.error('error'));
}
});
// GET /api/ota/:ota_id
router.get('/api/ota/:ota_id', async (req: Request, res: Response) => {
try {