Skip to content

feat: Add material upload script#1516

Merged
hexqi merged 5 commits intoopentiny:developfrom
lu-yg:feat/materials
Jul 25, 2025
Merged

feat: Add material upload script#1516
hexqi merged 5 commits intoopentiny:developfrom
lu-yg:feat/materials

Conversation

@lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Jul 11, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added a new script to upload a local bundle.json file for material synchronization with the backend.
    • Introduced an npm script (uploadMaterials) to simplify the upload process.
  • Documentation

    • Expanded API documentation with details on the new material synchronization endpoint.
    • Added a recommended solution guide for uploading materials, including configuration instructions and best practices.
    • Improved structure and notes in the material synchronization solution documentation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

A new material synchronization workflow was introduced, featuring a script to upload a bundle.json file to a backend API endpoint. Documentation was updated to describe the new API, elaborate on the synchronization solution, and clarify configuration steps. Supporting changes were made to environment configuration and npm scripts.

Changes

File(s) Change Summary
.env.local Added backend_url variable pointing to the material-center bundle create API.
docs/api/backend-api/material-center.md Documented new POST API endpoint /material-center/api/component/bundle/create for uploading bundle.json to sync materials.
docs/solutions/material-sync-solution.md Added new recommended upload-based sync method, clarified versioning/config, improved structure, and added notes for manual steps.
package.json Added uploadMaterials script to run scripts/uploadMaterials.mjs.
scripts/uploadMaterials.mjs New script to upload bundle.json via multipart/form-data POST to backend, using env config and custom logging.

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
Loading

Poem

A bundle hops from disk to cloud,
With scripts and docs that cheer aloud.
New endpoints open, configs align,
Materials sync—oh, how divine!
The rabbit logs, the upload’s done,
Versioned bits beneath the sun.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 11, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (5)
.env.local (1)

7-7: Fix naming convention inconsistency.

The new environment variable backend_url uses 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/create

Don't forget to update the reference in scripts/uploadMaterials.mjs accordingly.

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.env

And 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 uploadMaterials is 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 depth

Under “方案二” 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 tooling

Point 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e93aa6 and df06dd3.

⛔ Files ignored due to path filters (2)
  • docs/solutions/imgs/bundle_upload.png is excluded by !**/*.png
  • docs/solutions/imgs/component_create_code.png is 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

Path and Method are 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/create

Apply the same change to Method.
[ suggest_optional_refactor ]


347-357: Mis-classified “file” – it is a form field, not a path parameter

file is 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 named file.

-**路径参数**
+**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 removed

The 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 schema

The 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 risk

The image path ./imgs/component_create_code.png is relative to the docs file; verify that the file exists in docs/solutions/imgs/ and is committed. Broken images silently degrade the doc.

@hexqi hexqi added this to the v2.8.0 milestone Jul 22, 2025
@hexqi hexqi merged commit ffa37d7 into opentiny:develop Jul 25, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants