feat(models): 模型压缩包自动转换 + 默认模型写进源码;首次启动 .env 引导;HOST 默认 0.0.0.0
需求 1:模型上传支持压缩包(MMD 模型包) - common/zip-reader.ts:纯 TS 极简 ZIP 读取器(EOCD/中央目录、STORE+DEFLATE、 ZIP64 大小字段、Shift-JIS/GBK 文件名回退、拒绝 zip-slip 与加密条目) - models/model-convert.ts:解压 → 选主模型(指名字/最浅/最大)→ Assimp 导出 FBX → **assimp info 回读校验**(Assimp 对带蒙皮大骨架模型会写出损坏文件: 实测 714 骨骼 PMX 导出退出码 11、产物回读报 FBX-DOM no Objects dictionary found) → 失败自动回退 GLB;两种都失败则 422 - models/glb-textures.ts:把 Assimp 写成外部 URI 的贴图内嵌进 GLB 的 BIN chunk, 保证模型库里单文件即可加载(否则是白模) - 溯源:压缩包原件存为 model-archive 资产;models 新增 source_asset_id / conversion_note(迁移 1789450000000-AddModelConversionFields,已在真实库上 验证 up/down 可逆) - 默认模型:转换成功且 autoDefault 不为 false → is_primary=1 + published, 并把身份(名称/格式/产物 sha256)写进源码 src/config/default-model.ts; resolveDefaultModelId 增加 DEFAULT_MODEL_ID 与源码种子两步(按 sha256 匹配, 换库仍有效),实测库中有 2 个 VRM 时默认模型仍解析为该 GLB - scripts/import-default-model.mjs:运维 CLI(上传 zip 并写源码 / --write-source-only) - 修复 multipart 中文文件名乱码(upload.util.decodeUploadName) - DTO/契约新增 conversionNote、fileSha256;管理端 accept 增加 .zip 并展示转换来源 需求 2:首次启动 .env 引导 - deploy/init-env.sh:交互式逐项填写 8 个键(回车保留默认、口令不回显不加引号、 端口校验、mysql2 连通性自检且口令只经环境变量传递、只改这 8 个键并保留模板注释、 chmod 600、结尾打码摘要);--force/--check/-y/-i/--skip-db-check 等开关; 非交互(-y、OPENDANCE_NONINTERACTIVE、stdin 关闭)绝不提问、读取带超时 - install.sh 缺 .env 时改为调用引导,失败才 die 需求 3:默认监听 0.0.0.0 - 代码默认值、两份 .env 模板、install.sh、init-env.sh 五处一致,并新增测试守护 (未设置 HOST 时为 0.0.0.0;两份模板都写着 HOST=0.0.0.0) 契约:rest-api / data-models / model-formats → 0.3.0,database → 0.2.0(另两库已同步) 验证:125 项单测通过(7 文件);契约 6 项与 29 条路由一致;typecheck/build 通过; 真实包端到端 HTTP 201 / 0.89s / format=glb / isPrimary=true / published; GLB 1,152,464 字节、1 mesh / 240 nodes / 1 skin(238 joints) / 2 张内嵌贴图; 迁移 revert→run 实测可逆且数据无损恢复
This commit is contained in:
+28
-2
@@ -1,7 +1,7 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: OpenDance Studio Web 管理服务端 API
|
||||
version: 0.2.0
|
||||
version: 0.3.0
|
||||
description: |
|
||||
OpenDance Studio 的唯一数据源与契约权威。
|
||||
契约版本见 contracts/VERSION。字段语义见 contracts/data-models.md。
|
||||
@@ -317,7 +317,22 @@ paths:
|
||||
schema: { $ref: '#/components/schemas/ModelPage' }
|
||||
post:
|
||||
tags: [models]
|
||||
summary: 上传模型 + 来源信息(VRM 优先)
|
||||
summary: 上传模型 + 来源信息(VRM 优先;支持 MMD 模型压缩包自动转换)
|
||||
description: |
|
||||
`file` 为单个文件:
|
||||
|
||||
- `.vrm` / `.glb` / `.gltf` / `.fbx`:直接入库,`format` 由扩展名决定
|
||||
- `.zip`:视为 MMD 模型包。服务端解压 → 选取 `.pmx`
|
||||
(优先 `MODEL_CONVERT_PMX` 指定的名字,默认 `Hatsune Miku.pmx`;
|
||||
否则取目录最浅、文件最大者)→ 调 Assimp 导出 **FBX**,
|
||||
导出后**回读校验**(Assimp 的 FBX 导出器对带蒙皮的大骨架模型会写出损坏文件),
|
||||
失败自动回退 **GLB**,并把过程写入 `conversionNote`。
|
||||
GLB 产物会把 Assimp 写成外部 URI 的贴图内嵌进二进制块,保证单文件可用。
|
||||
压缩包原件作为 `model-archive` 资产留存以便溯源。
|
||||
|
||||
转换成功且 `autoDefault` 不为 false 时,该模型会被置为全局默认模型
|
||||
(`isPrimary=1` + `status=published`),并把身份(名称/格式/产物 sha256)
|
||||
写进源码 `web-server/src/config/default-model.ts`。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
@@ -329,6 +344,9 @@ paths:
|
||||
file: { type: string, format: binary }
|
||||
name: { type: string }
|
||||
isPrimary: { type: boolean }
|
||||
autoDefault:
|
||||
type: boolean
|
||||
description: 仅对 `.zip` 生效;转换成功后是否自动设为默认模型,默认 true
|
||||
sourceType: { $ref: '#/components/schemas/SourceType' }
|
||||
sourceName: { type: string }
|
||||
sourceUrl: { type: string }
|
||||
@@ -749,6 +767,14 @@ components:
|
||||
fileUrl: { type: string, nullable: true }
|
||||
fileSize: { type: integer, nullable: true }
|
||||
thumbnailUrl: { type: string, nullable: true }
|
||||
conversionNote:
|
||||
type: string
|
||||
nullable: true
|
||||
description: 由压缩包转换而来时的说明;直传模型为 null
|
||||
fileSha256:
|
||||
type: string
|
||||
nullable: true
|
||||
description: 模型文件(转换产物)的 sha256,用于换库后定位默认模型
|
||||
status: { $ref: '#/components/schemas/PublishStatus' }
|
||||
createdAt: { type: string, format: date-time }
|
||||
updatedAt: { type: string, format: date-time }
|
||||
|
||||
Reference in New Issue
Block a user