Skip to content
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(create secret) add file upload support #11

Merged
merged 1 commit into from
Aug 25, 2021

Conversation

elysee15
Copy link
Contributor

@elysee15 elysee15 commented Aug 25, 2021

Capture d’écran 2021-08-25 à 16 36 24

@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #11 (47bf96b) into main (194ef12) will decrease coverage by 1.74%.
The diff coverage is 36.36%.

❗ Current head 47bf96b differs from pull request most recent head b41fc04. Consider uploading reports for the commit b41fc04 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main      #11      +/-   ##
==========================================
- Coverage   58.13%   56.39%   -1.75%     
==========================================
  Files          43       49       +6     
  Lines        1070     1158      +88     
  Branches       55       75      +20     
==========================================
+ Hits          622      653      +31     
- Misses        373      428      +55     
- Partials       75       77       +2     
Impacted Files Coverage Δ
web/src/pages/CreateSecret.tsx 7.14% <0.00%> (-1.95%) ⬇️
web/src/routes/index.tsx 84.61% <ø> (ø)
web/src/styles/footerStyles.ts 100.00% <ø> (ø)
web/src/utils/utils.ts 4.76% <0.00%> (-3.58%) ⬇️
web/src/components/ShowFile.tsx 13.33% <13.33%> (ø)
web/src/components/CreateSecretFormTabs.tsx 22.22% <22.22%> (ø)
web/src/components/TabPanel.tsx 25.00% <25.00%> (ø)
web/src/components/ShowSecret.tsx 41.66% <55.55%> (+2.38%) ⬆️
web/src/components/Dropzone.tsx 69.56% <69.56%> (ø)
web/src/components/CreateSecretForm.tsx 78.94% <100.00%> (-1.06%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 194ef12...b41fc04. Read the comment docs.

@elysee15 elysee15 requested a review from bbengfort August 25, 2021 10:22
Copy link
Contributor

@bbengfort bbengfort left a comment

Choose a reason for hiding this comment

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

@elysee15 this looks really good - I like the initiative you took to create a new root page to select the secret type; I think you're right that there need to be two different forms, governed by some navigation function. I think the dropzone you put together is very cool and the file upload works perfectly!

My concern is that it makes the create secret forms feel like two separate applications rather than the same one with the same primary concerns (the only thing that is different is file vs. message). Also, to change from file to message and back you'd have to navigate two times, once back home, then to the form you'd like to use.

My proposal is that instead of a SecretType component, we have the forms be wrapped inside of Tabs. This will make the form feel like one thing and make it easier to switch back and forth between the two with only a single click. What do you think?

Also, I had some comments on the file download; I suppose downloading isn't implemented yet in this PR? Can we make sure another ticket is added for that?

function encodeFileToBase64(file: File): Promise<string | ArrayBuffer | null> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
Copy link
Contributor

Choose a reason for hiding this comment

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

This function returns the file in the following format:

data:text/csv;base64,Im5ldHdvcmsiLCJhbGlhc2VzIgoiYmNoX2NoYWluIiw=

Note the prefix data:text/csv;base64 -- unfortunately this is not handled by the the CLI program, which expects completely base64 encoded text.

$ whisper fetch [mytoken]
illegal base64 data at input byte 4

We will want the web UI and the CLI to work together seamlessly. This means we either need to:

  1. Adapt the CLI to read and write data URL format
  2. Adapt the UI to manage base64 encoded data only without the prefix

My preference is choice 2 since there is a file size limit and this adds extra data. However, this depends on how you intend to to download the file in the future; if the download requires the data URL - then I'm happy to go with choice 1. Let me know your thoughts and we'll create a ticket to manage this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll verify it and let you know

function dataURLtoFile(dataurl: string, filename?: string): File {
const fileName = filename || "";
const arr = dataurl.split(",");
const mime = (arr[0].match(/:(.*?);/) as string[])[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the question really to my other comment is do you need the mimetype in the data for the download to function correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use the mimetype to set the file format

<Route path="/maintainance" exact component={MaintainancePage} />
{status.status === Status.maintainance ? <Redirect to="/maintainance" /> : null}
<Route path="/secret/:token" exact component={ShowSecret} />
<Route path="/" exact component={CreateSecret} />
<Route path="/create-secret" exact component={CreateSecret} />
Copy link
Contributor

Choose a reason for hiding this comment

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

If we go the tabs route, it would be nice to have the create secret component back to /

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay

{ value: "168h", label: "7 days" }
];

export { FILE_SIZE, LIFETIME_OPTIONS };
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to have these constants in one place!


const FILE_SIZE = 64 * 1024;

const StyledDropzone: React.FC<StyledDropzoneProps> = ({ form }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I very much like the dropzone for the file upload - nice work!

@elysee15
Copy link
Contributor Author

I planned to make a commit for download part after this PR

@bbengfort
Copy link
Contributor

@elysee15 if we need to hold off on the base64 encoding question until the next PR that's fine with me. Let's just make sure there is a ticket in Monday with commentary.

@elysee15 elysee15 force-pushed the feat/add-file-upload-support branch from fd4222c to e035434 Compare August 25, 2021 16:06
@elysee15 elysee15 force-pushed the feat/add-file-upload-support branch from e035434 to b41fc04 Compare August 25, 2021 16:36
Copy link
Contributor

@bbengfort bbengfort left a comment

Choose a reason for hiding this comment

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

@elysee15 thank you for updating to the tabs, looks great! I'm getting an error on fetch file, but I think you're working on that in #13 so go ahead and merge this when you're ready!

@elysee15 elysee15 merged commit 652cf39 into main Aug 25, 2021
@elysee15 elysee15 deleted the feat/add-file-upload-support branch August 25, 2021 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants