-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(download-code): support download zip for not support browsers #703
Conversation
WalkthroughThe recent changes reflect a shift in how the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Browser
participant Utils
participant Zip
User->>Browser: Initiates file download
Browser->>Utils: Check for File System Access
alt Supported
Utils->>Zip: Create ZIP file
Zip-->>Utils: Return ZIP handle
Utils->>Browser: Prompt to save ZIP
else Not Supported
Utils->>Zip: Fallback to ZIP creation
Zip-->>Utils: Return ZIP handle
Utils->>Browser: Prompt to save ZIP
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- packages/design-core/package.json (1 hunks)
- packages/utils/package.json (1 hunks)
- packages/utils/src/fs/fszip.js (1 hunks)
- packages/utils/src/fs/index.js (3 hunks)
Files skipped from review due to trivial changes (1)
- packages/design-core/package.json
Additional comments not posted (10)
packages/utils/package.json (1)
33-35
: Dependency addition approved.The addition of the
jszip
dependency is necessary for the new ZIP file handling functionality.packages/utils/src/fs/fszip.js (4)
1-11
: File header approved.The file header includes appropriate copyright and license information.
13-14
: Import statement approved.The import statement for
jszip
is correct and necessary for the functionality.
16-29
: FunctionsaveAsZip
looks good.The function correctly creates a download link for the ZIP file and triggers the download.
31-36
: FunctioncreateZip
looks good.The function correctly initializes a new
JSZIP
instance.packages/utils/src/fs/index.js (5)
15-16
: Import statement approved.The import statement for
createZip
andwriteZip
is correct and necessary for the new functionality.
18-19
: ConstantisSupportFileSystemAccess
looks good.The constant correctly checks for the availability of the File System Access API and ensures the code is not running in an iframe.
29-30
: FunctiongetUserBaseDirHandle
fallback looks good.The function correctly uses
createZip
as a fallback whenshowOpenFilePicker
is not available.
182-186
: FunctionwriteFiles
fallback looks good.The function correctly uses
writeZip
as a fallback when the File System Access API is not supported.
192-192
: FunctionwriteFiles
approved.The function correctly writes files using the appropriate directory handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Inline review comments failed to post
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/utils/src/fs/fszip.js (1 hunks)
- packages/utils/src/fs/index.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/utils/src/fs/fszip.js
Additional comments not posted (2)
packages/utils/src/fs/index.js (2)
Line range hint
139-167
:
LGTM!The function implementation is well-structured and does not require any changes.
18-19
: LGTM! But verify the constant usage in the codebase.The code changes are approved.
However, ensure that all usages of
isSupportFileSystemAccess
are correctly handled.Verification successful
The usage of
isSupportFileSystemAccess
is correctly handled within the codebase.The constant is used in an if-statement to ensure that certain operations are only performed if the file system access is supported.
packages/utils/src/fs/index.js
: Lines whereisSupportFileSystemAccess
is defined and used.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `isSupportFileSystemAccess` in the codebase. # Test: Search for the constant usage. Expect: Proper handling of the constant. rg --type python -A 5 $'isSupportFileSystemAccess'Length of output: 80
Script:
#!/bin/bash # Description: Verify all usages of `isSupportFileSystemAccess` in the codebase. # Test: Search for the constant usage. Expect: Proper handling of the constant. rg --type js -A 5 'isSupportFileSystemAccess'Length of output: 776
Comments failed to post (2)
packages/utils/src/fs/index.js
28-29: Add error handling and logging.
The function correctly implements a fallback mechanism but could benefit from additional error handling and logging.
- if (!window.showOpenFilePicker) { - return createZip() - } + if (!window.showOpenFilePicker) { + console.warn('File System Access API not supported, creating zip handle as fallback.') + try { + return createZip() + } catch (error) { + console.error('Error creating zip handle:', error) + throw error + } + }Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.if (!window.showOpenFilePicker) { console.warn('File System Access API not supported, creating zip handle as fallback.') try { return createZip() } catch (error) { console.error('Error creating zip handle:', error) throw error } }
178-183: Add error handling and logging.
The function correctly implements a fallback mechanism but could benefit from additional error handling and logging.
- if (!filesInfo?.length) { - return - } + if (!filesInfo?.length) { + console.warn('No files to write.') + return + } - if (!isSupportFileSystemAccess) { - const zipInfo = { zipName, zipHandle: supportZipCache && baseDirHandle } - await writeZip(filesInfo, zipInfo) - return - } + if (!isSupportFileSystemAccess) { + console.warn('File System Access API not supported, using zip fallback.') + try { + const zipInfo = { zipName, zipHandle: supportZipCache && baseDirHandle } + await writeZip(filesInfo, zipInfo) + } catch (error) { + console.error('Error writing zip files:', error) + throw error + } + return + }Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.export const writeFiles = async ( baseDirHandle, filesInfo, zipName = 'tiny-engine-generate-code', supportZipCache = true ) => { if (!filesInfo?.length) { console.warn('No files to write.') return } if (!isSupportFileSystemAccess) { console.warn('File System Access API not supported, using zip fallback.') try { const zipInfo = { zipName, zipHandle: supportZipCache && baseDirHandle } await writeZip(filesInfo, zipInfo) } catch (error) { console.error('Error writing zip files:', error) throw error } return }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/utils/src/fs/fszip.js (1 hunks)
- packages/utils/src/fs/index.js (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- packages/utils/src/fs/fszip.js
- packages/utils/src/fs/index.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/utils/src/fs/fszip.js (1 hunks)
Additional comments not posted (2)
packages/utils/src/fs/fszip.js (2)
21-29
: LGTM!The
saveAs
function correctly handles the download process.
34-36
: LGTM!The
createZip
function correctly returns a new instance ofJSZIP
.
* fix(mockServer): mockServer page preview can't render element-plus element (#503) * fix(style): fix render error caused by inline style breaks (#526) * fix(metaComp): fix bug where metaHtmlText could set value to incorret schema children (#473) * fix(vue-generator): fix globalstate codegen error (#547) * fix(material): add componentsMap to app Schema after material build (#527) * fix: slot params missing double quote (#605) * fix: slot params missing double quote * fix: exclude nodemodule test case * fix: 修复onMouseover拼写错误 (#662) * fix: esbuild install failed on node v16 (#668) * fix: esbuild install failed on nodev16 * fix: esbuild install failed on nodev16 * fix: builtin components can't generate import statement with genSFCWithDefaultPlugin method (#656) * fix: esbuild install failed on nodev16 (#671) * fix: esbuild install failed on nodev16 * fix: esbuild install failed on nodev16 * fix: remove deps on root pkg.json * fix(preview): multiple nested blocks cannot preview #663 (#665) * fix(material): add missing componentsMap to mockServer (#701) * fix(setting): fix bindEvent dialog visible can't work on tinyvue 3.17 (#715) * feat(download-code): support download zip for not support browsers (#703) * feat(download-code): support download zip for not support browsers * feat(download-code): support download zip for not support browsers - review * feat(download-code): support download zip for not support browsers - review * docs: update milestone (#728) * docs: update milestone * fix: tab * fix: abaolute canvas init inlineStyle should be string (#730) * fix(download): Optimize download logic and adapt to iframe (#739) * fix(download): Optimize download logic and adapt to iframe * feat(cdn): change cdn from onmicrosoft to unpkg (#750) * fix: 隐藏画布根节点的包裹元素的操作选项 (#492) * fix(script): translate log (#549) * fix: translate log * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: reset spacing cannot generate correct source code (#657) * fix: jsx slot modelvalue can't update value (#734) * fix: jsx slot modelvalue can't update value * fix: add unit test for updateModel event * fix(canvas): absolute dnd update position to schema. close #664 (#751) * fix(generate-vue):修复出码文件选择界面打包后样式丢失问题 (#789) Co-authored-by: wangwenbing <11535041@qq.com> * fix(stylePanel): fix setting border-radius could not work on first time (#481) * fix(common): fix verify required (#787) * fix: mixed lifeCyclesContent when empty lifecycles (#810) close #806 修复生命周期为空时,取当前页面schema生命周期值的 bug --------- Co-authored-by: chilingling <26962197+chilingling@users.noreply.github.com> Co-authored-by: yeser <631300329@qq.com> Co-authored-by: wenmine <wwmmail@foxmail.com> Co-authored-by: Gene <Pacify.98@gmail.com> Co-authored-by: yaoyun8 <142570291+yaoyun8@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: bwrong <ibwrong@foxmail.com> Co-authored-by: wangwenbing <11535041@qq.com> Co-authored-by: Xie Jay <xiejay97@gmail.com>
…pentiny#703) * feat(download-code): support download zip for not support browsers * feat(download-code): support download zip for not support browsers - review * feat(download-code): support download zip for not support browsers - review
* fix(mockServer): mockServer page preview can't render element-plus element (opentiny#503) * fix(style): fix render error caused by inline style breaks (opentiny#526) * fix(metaComp): fix bug where metaHtmlText could set value to incorret schema children (opentiny#473) * fix(vue-generator): fix globalstate codegen error (opentiny#547) * fix(material): add componentsMap to app Schema after material build (opentiny#527) * fix: slot params missing double quote (opentiny#605) * fix: slot params missing double quote * fix: exclude nodemodule test case * fix: 修复onMouseover拼写错误 (opentiny#662) * fix: esbuild install failed on node v16 (opentiny#668) * fix: esbuild install failed on nodev16 * fix: esbuild install failed on nodev16 * fix: builtin components can't generate import statement with genSFCWithDefaultPlugin method (opentiny#656) * fix: esbuild install failed on nodev16 (opentiny#671) * fix: esbuild install failed on nodev16 * fix: esbuild install failed on nodev16 * fix: remove deps on root pkg.json * fix(preview): multiple nested blocks cannot preview opentiny#663 (opentiny#665) * fix(material): add missing componentsMap to mockServer (opentiny#701) * fix(setting): fix bindEvent dialog visible can't work on tinyvue 3.17 (opentiny#715) * feat(download-code): support download zip for not support browsers (opentiny#703) * feat(download-code): support download zip for not support browsers * feat(download-code): support download zip for not support browsers - review * feat(download-code): support download zip for not support browsers - review * docs: update milestone (opentiny#728) * docs: update milestone * fix: tab * fix: abaolute canvas init inlineStyle should be string (opentiny#730) * fix(download): Optimize download logic and adapt to iframe (opentiny#739) * fix(download): Optimize download logic and adapt to iframe * feat(cdn): change cdn from onmicrosoft to unpkg (opentiny#750) * fix: 隐藏画布根节点的包裹元素的操作选项 (opentiny#492) * fix(script): translate log (opentiny#549) * fix: translate log * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update scripts/connection.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: reset spacing cannot generate correct source code (opentiny#657) * fix: jsx slot modelvalue can't update value (opentiny#734) * fix: jsx slot modelvalue can't update value * fix: add unit test for updateModel event * fix(canvas): absolute dnd update position to schema. close opentiny#664 (opentiny#751) * fix(generate-vue):修复出码文件选择界面打包后样式丢失问题 (opentiny#789) Co-authored-by: wangwenbing <11535041@qq.com> * fix(stylePanel): fix setting border-radius could not work on first time (opentiny#481) * fix(common): fix verify required (opentiny#787) * fix: mixed lifeCyclesContent when empty lifecycles (opentiny#810) close opentiny#806 修复生命周期为空时,取当前页面schema生命周期值的 bug --------- Co-authored-by: chilingling <26962197+chilingling@users.noreply.github.com> Co-authored-by: yeser <631300329@qq.com> Co-authored-by: wenmine <wwmmail@foxmail.com> Co-authored-by: Gene <Pacify.98@gmail.com> Co-authored-by: yaoyun8 <142570291+yaoyun8@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: bwrong <ibwrong@foxmail.com> Co-authored-by: wangwenbing <11535041@qq.com> Co-authored-by: Xie Jay <xiejay97@gmail.com>
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?
对于不支持 file system api的浏览器以及内嵌的iframe,提供下载zip的功能
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Chores