-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
metadata export #15421
Merged
Merged
metadata export #15421
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/suite/src/views/settings/SettingsDebug/Metadata.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Button } from '@trezor/components'; | ||
|
||
import { ActionColumn, SectionItem, TextColumn } from 'src/components/suite'; | ||
import { useDispatch } from 'src/hooks/suite'; | ||
import { exportMetadataToLocalFile } from 'src/actions/suite/metadataActions'; | ||
|
||
export const Metadata = () => { | ||
const dispatch = useDispatch(); | ||
const [exporting, setExporting] = useState(false); | ||
|
||
const onClick = () => { | ||
setExporting(true); | ||
dispatch(exportMetadataToLocalFile()).finally(() => { | ||
setExporting(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<SectionItem data-testid="@settings/debug/metadata"> | ||
<TextColumn | ||
title="Export" | ||
description="Export labeling files to your computer. You may use this to transfer your labeling files from your Google drive account to your Dropbox account." | ||
/> | ||
<ActionColumn> | ||
<Button onClick={onClick} isDisabled={exporting} isLoading={exporting}> | ||
Export | ||
</Button> | ||
</ActionColumn> | ||
</SectionItem> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export const createZip = (buffers: { name: string; content: ArrayBuffer }[]) => { | ||
const fileEntries: ArrayBuffer[] = []; | ||
const centralDirectory: ArrayBuffer[] = []; | ||
let offset = 0; | ||
|
||
buffers.forEach(({ name, content }) => { | ||
const fileData = content; | ||
const fileHeader = new Uint8Array(30 + name.length); | ||
const localFileHeader = new DataView(fileHeader.buffer); | ||
|
||
// Local file header signature | ||
localFileHeader.setUint32(0, 0x04034b50, true); // "PK\3\4" | ||
localFileHeader.setUint16(4, 0x0, true); // Version needed to extract | ||
localFileHeader.setUint16(6, 0x0, true); // General purpose bit flag | ||
localFileHeader.setUint16(8, 0x0, true); // Compression method (none) | ||
localFileHeader.setUint16(10, 0x0, true); // File last mod time | ||
localFileHeader.setUint16(12, 0x0, true); // File last mod date | ||
localFileHeader.setUint32(14, 0, true); // CRC-32 (skipped for simplicity) | ||
localFileHeader.setUint32(18, fileData.byteLength, true); // Compressed size | ||
localFileHeader.setUint32(22, fileData.byteLength, true); // Uncompressed size | ||
localFileHeader.setUint16(26, name.length, true); // Filename length | ||
|
||
// Filename | ||
fileHeader.set(new TextEncoder().encode(name), 30); | ||
|
||
fileEntries.push(fileHeader, fileData); | ||
|
||
// Central directory | ||
const centralHeader = new Uint8Array(46 + name.length); | ||
const centralView = new DataView(centralHeader.buffer); | ||
|
||
centralView.setUint32(0, 0x02014b50, true); // "PK\1\2" | ||
centralView.setUint16(4, 0x0, true); // Version made by | ||
centralView.setUint16(6, 0x0, true); // Version needed to extract | ||
centralView.setUint16(8, 0x0, true); // General purpose bit flag | ||
centralView.setUint16(10, 0x0, true); // Compression method (none) | ||
centralView.setUint16(12, 0x0, true); // File last mod time | ||
centralView.setUint16(14, 0x0, true); // File last mod date | ||
centralView.setUint32(16, 0, true); // CRC-32 | ||
centralView.setUint32(20, fileData.byteLength, true); // Compressed size | ||
centralView.setUint32(24, fileData.byteLength, true); // Uncompressed size | ||
centralView.setUint16(28, name.length, true); // Filename length | ||
centralView.setUint32(42, offset, true); // Offset of local header | ||
|
||
centralHeader.set(new TextEncoder().encode(name), 46); | ||
|
||
centralDirectory.push(centralHeader); | ||
offset += fileHeader.length + fileData.byteLength; | ||
}); | ||
|
||
// End of central directory record | ||
const eocd = new Uint8Array(22); | ||
const eocdView = new DataView(eocd.buffer); | ||
|
||
eocdView.setUint32(0, 0x06054b50, true); // "PK\5\6" | ||
eocdView.setUint16(8, centralDirectory.length, true); // Total number of entries | ||
eocdView.setUint16(10, centralDirectory.length, true); // Total number of entries | ||
eocdView.setUint32( | ||
12, | ||
centralDirectory.reduce((sum, cd) => sum + cd.byteLength, 0), | ||
true, | ||
); // Size of central directory | ||
eocdView.setUint32(16, offset, true); // Offset of start of central directory | ||
|
||
return new Blob([...fileEntries, ...centralDirectory, eocd], { | ||
type: 'application/zip', | ||
}); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: This is not translated but I guess for it is fine for debug menu
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.
yeah that should be good for now.