8b95dd0dc1
- admin-vue 新增「记录与版本 → 教程管理」页(menuKey admin_tutorial):
zip 浏览器直传 MinIO(presign → PUT 带进度 → confirm 落库)+ 列表/下载/删除,
最新一条标「当前生效」;补操作指引与 align-tutorial 守卫测试。
- frontend-vue 工具台「立即下载教程」进页面取 /api/tutorial/latest(最新上传优先),
接口异常或无记录回退历史固定直链,按钮不失效。
- Java 侧 tutorial 模块与 V119 迁移已在 de9686ec 提交并上线(2026-09-13)。
vue-tsc + 两端单测(工具台 695 / 后台 1617)通过;生产已实测
presign→PUT→confirm→latest 切换→删除回落全链路。
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
/** 教程包列表加载模型:解析 /api/admin/tutorials data.items(snake);纯逻辑。 */
|
|
import { unwrap } from '../../api/envelope.ts'
|
|
import { type TutorialPackageItem, type TutorialPackageList } from './tutorial-dto.ts'
|
|
|
|
function text(value: unknown): string {
|
|
return typeof value === 'string' ? value.trim() : ''
|
|
}
|
|
|
|
function numberOrNull(value: unknown): number | null {
|
|
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
|
}
|
|
|
|
/** 解析单条教程包行;缺 id 视为无效。 */
|
|
export function toTutorialPackageItem(raw: unknown): TutorialPackageItem | null {
|
|
if (!raw || typeof raw !== 'object') return null
|
|
const r = raw as Record<string, unknown>
|
|
const id = numberOrNull(r.id)
|
|
if (id === null) return null
|
|
return {
|
|
id,
|
|
fileName: text(r.file_name ?? r.fileName),
|
|
objectKey: text(r.object_key ?? r.objectKey),
|
|
fileSize: numberOrNull(r.file_size ?? r.fileSize) ?? 0,
|
|
fileUrl: text(r.file_url ?? r.fileUrl),
|
|
createdAt: text(r.created_at ?? r.createdAt),
|
|
}
|
|
}
|
|
|
|
/** 归一化教程包列表负载为前端结果;缺省回空列表。 */
|
|
export function parseTutorialPackageList(payload: unknown): TutorialPackageList {
|
|
const data = unwrap<unknown>(payload)
|
|
const record = data && typeof data === 'object' ? (data as Record<string, unknown>) : {}
|
|
const items = Array.isArray(record.items)
|
|
? record.items.map((raw) => toTutorialPackageItem(raw)).filter((item): item is TutorialPackageItem => item !== null)
|
|
: []
|
|
return { items }
|
|
}
|
|
|
|
/** 上传成功后返回的新记录行(data.item);无 item 回 null。 */
|
|
export function parseTutorialPackageUpload(payload: unknown): TutorialPackageItem | null {
|
|
const data = unwrap<unknown>(payload)
|
|
if (!data || typeof data !== 'object') return null
|
|
const item = (data as Record<string, unknown>).item
|
|
return item ? toTutorialPackageItem(item) : null
|
|
}
|
|
|
|
/** 字节数展示:0=未知展示为 -,其余按 KB/MB/GB 人性化。 */
|
|
export function formatFileSize(bytes: number): string {
|
|
if (!Number.isFinite(bytes) || bytes <= 0) return '—'
|
|
if (bytes < 1024) return `${bytes} B`
|
|
const units = ['KB', 'MB', 'GB']
|
|
let value = bytes / 1024
|
|
let unitIndex = 0
|
|
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
value /= 1024
|
|
unitIndex += 1
|
|
}
|
|
return `${value >= 100 ? value.toFixed(0) : value.toFixed(1)} ${units[unitIndex]}`
|
|
}
|