feat: Add material upload script#1516
Conversation
WalkthroughA new material synchronization workflow was introduced, featuring a script to upload a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant uploadMaterials.mjs
participant BackendAPI
User->>uploadMaterials.mjs: Run "pnpm uploadMaterials"
uploadMaterials.mjs->>uploadMaterials.mjs: Load .env.local (get backend_url)
uploadMaterials.mjs->>uploadMaterials.mjs: Read bundle.json
uploadMaterials.mjs->>BackendAPI: POST /material-center/api/component/bundle/create (multipart/form-data with bundle.json)
BackendAPI-->>uploadMaterials.mjs: Respond with insertNum, updateNum
uploadMaterials.mjs->>User: Log success or error
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (5)
.env.local (1)
7-7: Fix naming convention inconsistency.The new environment variable
backend_urluses lowercase naming while other variables in the file follow UPPERCASE_WITH_UNDERSCORES convention (SQL_HOST, SQL_PORT, etc.). This inconsistency could cause confusion.Apply this diff to maintain consistency:
-backend_url=http://localhost:9090/material-center/api/component/bundle/create +BACKEND_URL=http://localhost:9090/material-center/api/component/bundle/createDon't forget to update the reference in
scripts/uploadMaterials.mjsaccordingly.scripts/uploadMaterials.mjs (1)
14-14: Update environment variable reference for consistency.The environment variable reference should be updated to match the naming convention used in other parts of the codebase.
If you apply the naming convention fix in
.env.local, update this line accordingly:-const { backend_url } = process.env +const { BACKEND_URL } = process.envAnd update the fetch call on line 29 to use
BACKEND_URL.docs/solutions/material-sync-solution.md (3)
3-8: Clarify script entry & location
pnpm uploadMaterialsis introduced without showing where the npm-script is declared or which package.json owns it. Readers who are not in the repo root will be confused.Consider adding a short line such as “该命令位于根目录 package.json 的 scripts 字段” (or a relative path) to remove ambiguity.
21-32: Inconsistent heading depthUnder “方案二” the subsection levels were demoted from
###to####, but other second-level topics (e.g. “注意事项” under 方案一) keep####. This makes 方案二’s internal TOC look one level deeper than 方案一’s, although they describe parallel concepts.Either keep them at the same depth (
###) or demote all peer sections for consistency.
49-49: Manual DB operation is error-prone – provide toolingPoint 5 directs users to “手动在数据库表 … 添加关联关系数据”. Manual SQL in production docs is risky. Consider adding:
- a ready-to-run migration SQL snippet, or
- extend the existing scripts to auto-insert the relations.
Reducing manual steps prevents data drift and on-boarding errors.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
docs/solutions/imgs/bundle_upload.pngis excluded by!**/*.pngdocs/solutions/imgs/component_create_code.pngis excluded by!**/*.png
📒 Files selected for processing (5)
.env.local(1 hunks)docs/api/backend-api/material-center.md(1 hunks)docs/solutions/material-sync-solution.md(3 hunks)package.json(1 hunks)scripts/uploadMaterials.mjs(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: gene9831
PR: opentiny/tiny-engine#1041
File: packages/plugins/datasource/src/DataSourceList.vue:138-138
Timestamp: 2025-01-14T10:06:25.508Z
Learning: PR #1041 in opentiny/tiny-engine is specifically for reverting Prettier v3 formatting to v2, without any logical code changes or syntax improvements.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/RenderMain.ts:82-88
Timestamp: 2025-01-14T08:50:50.226Z
Learning: For PR #1011, the focus is on resolving conflicts and migrating code, with architectural improvements deferred for future PRs.
package.json (3)
Learnt from: yy-wow
PR: opentiny/tiny-engine#940
File: packages/plugins/materials/src/composable/useMaterial.js:0-0
Timestamp: 2025-01-13T07:49:12.136Z
Learning: In the materials system, componentsDepsMap.scripts in materialState is used as a data store for tracking component dependencies and doesn't require Vue reactivity as changes are handled explicitly through updateCanvasDeps().
Learnt from: yy-wow
PR: opentiny/tiny-engine#940
File: packages/canvas/DesignCanvas/src/importMap.js:51-51
Timestamp: 2025-01-13T03:46:13.817Z
Learning: The `getImportMapData` function in `packages/canvas/DesignCanvas/src/importMap.js` has default parameter handling that initializes `canvasDeps` with empty arrays for `scripts` and `styles`, making additional null checks unnecessary.
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/material-function/support-collection.ts:3-15
Timestamp: 2025-01-14T06:59:02.999Z
Learning: The code in `packages/canvas/render/src/material-function/support-collection.ts` is migrated code that should not be modified at this time to maintain stability during the migration process.
docs/solutions/material-sync-solution.md (3)
Learnt from: rhlin
PR: opentiny/tiny-engine#1011
File: packages/canvas/render/src/material-function/support-collection.ts:3-15
Timestamp: 2025-01-14T06:59:02.999Z
Learning: The code in `packages/canvas/render/src/material-function/support-collection.ts` is migrated code that should not be modified at this time to maintain stability during the migration process.
Learnt from: gene9831
PR: opentiny/tiny-engine#1038
File: packages/plugins/block/index.js:24-24
Timestamp: 2025-01-14T08:42:18.574Z
Learning: In the tiny-engine project, breaking changes are documented in the changelog rather than in JSDoc comments or separate migration guides.
Learnt from: hexqi
PR: opentiny/tiny-engine#850
File: package.json:4-4
Timestamp: 2024-10-10T06:25:05.109Z
Learning: 当遇到与`canvas`包中`"type": "module"`相关的报错时,可以通过将`canvas`包中的`.eslintrc`文件改为`.cjs`后缀来解决,而无需在根目录的`package.json`中添加`"type": "module"`。
🪛 markdownlint-cli2 (0.17.2)
docs/api/backend-api/material-center.md
347-347: Emphasis used instead of a heading
(MD036, no-emphasis-as-heading)
353-353: Emphasis used instead of a heading
(MD036, no-emphasis-as-heading)
359-359: Emphasis used instead of a heading
(MD036, no-emphasis-as-heading)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: push-check
🔇 Additional comments (6)
package.json (1)
24-24: LGTM!The new npm script follows the existing naming conventions and is properly integrated into the scripts section.
docs/api/backend-api/material-center.md (4)
330-338: Use proper Markdown headings instead of bold text for consistency
PathandMethodare presented as bold paragraphs (**Path:**) rather than level-4 headings (####).
Elsewhere in the same document, section metadata is rendered with real headings, so this is inconsistent and triggers the MD036 linter error.-**Path:** /material-center/api/component/bundle/create +#### Path +/material-center/api/component/bundle/createApply the same change to Method.
[ suggest_optional_refactor ]
347-357: Mis-classified “file” – it is a form field, not a path parameter
fileis listed under “路径参数”, but the endpoint defined above (POST /component/bundle/create) contains no{file}placeholder.
The file is actually sent as the multipart/form-data part namedfile.-**路径参数** +**Form-Data 字段** -| 参数名称 | 示例 | 备注 | -| -------- | ---- | ------ | -| file | bundle.json | bundle.json文件 | +| 字段名 | 示例值 | 说明 | +| -------- | ---- | ---- | +| file | bundle.json | bundle.json 文件内容 |Moving it to the correct section avoids confusion for API consumers.
[ raise_critical_issue ]
359-368: Empty body table can be removedThe Body table is completely empty; leaving an empty HTML table hurts readability.
Either delete this block or add a line such as “无额外字段”.
[ suggest_nitpick ]
374-379: Consider documenting HTTP status codes and error schemaThe success payload is documented, but common error responses (e.g., 400 for invalid JSON, 500 for server error) are not.
Adding an errors subsection will make the API contract clearer.
[ suggest_optional_refactor ][ offer_architecture_advice ]docs/solutions/material-sync-solution.md (1)
14-14: Broken/missing image riskThe image path
./imgs/component_create_code.pngis relative to the docs file; verify that the file exists indocs/solutions/imgs/and is committed. Broken images silently degrade the doc.
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
bundle.jsonfile for material synchronization with the backend.uploadMaterials) to simplify the upload process.Documentation