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

Implement Dropbox export (#82) #393

Merged
merged 22 commits into from Nov 3, 2018
Merged

Conversation

matheusfaustino
Copy link
Contributor

@matheusfaustino matheusfaustino commented Jun 2, 2018

Hello guys,

First of all, thank you for your work and for this addon. I'm sending my initial implementation of a Dropbox integration, related to the issue #82, to see if you guys are interested in this feature, if it's following the coding standards of the project and if I have to change something in the implementation.

After this one, I'll work on the Google Drive integration, so I will use it as an experiment to the Google Drive integration.

Thanks for your time.

Best,

EDIT:

Ow, you have to create an app in dropbox and get the app key to test the implementation

@tophf
Copy link
Member

tophf commented Jun 2, 2018

Don't use await/async since we support old browsers, use URLSearchParams API, chromeLocal and chromeSync wrappers, find a different way to pass the parameters like messaging because redirecting location.href is weird. Find a way not to use web_accessible_resources. There are more nits I'll pick on in a few days.

@matheusfaustino
Copy link
Contributor Author

Hi @tophf, thanks for the review. I will fix the things this week and update the PR.
location.href is weird, I though in using window.open, but it didn't work, I'll try again.
Unfortunetely, without web_accessible_resources dropbox doesn't redirect back the user, then I can't get the access token from dropbox.

Which are the browsers the project supports? (I'm going to update the README to help others)

@prototype99
Copy link

if there are any I've missed feel free to say, however my understanding is it's only chrome, Firefox and opera

@tophf
Copy link
Member

tophf commented Jun 6, 2018

  • Firefox 48+ and its forks/derivatives with WebExtensions support
  • Chrome 49+ and the multitude of its forks/derivatives

@matheusfaustino
Copy link
Contributor Author

matheusfaustino commented Jun 8, 2018

Hi @tophf, I dove into URLSearchParams API and the way dropbox passes the parameters isn't supported by the APi, that is why they use a custom function to handle that:

https://github.com/dropbox/dropbox-sdk-js/blob/a88a138c0c3260c3537f30f94b003c1cf64f2fbd/examples/javascript/utils.js

I tried a lot of way, but without success. Here is a URL to "test":

moz-extension://c418f0ff-99ea-4a45-9571-3529b786ae18/dropbox-oauth.html#access_token=3Y4Z58CKMaoAAAAAAAA4SalyqKgxb_pg31RmjlDCaTJaKl8MAuUvmS7GZ1vyyE1J&token_type=bearer&uid=40150504&account_id=dbid%3AAADMZqIhjR7zFV8TpyEymvwjdI0jc4c2uRY

edit: typo

@tophf
Copy link
Member

tophf commented Jun 9, 2018

It works with anything you feed it, but of course in this case you need to extract the hash part first: const params = new URLSearchParams(new URL(entireUrl).hash)

@tophf
Copy link
Member

tophf commented Jun 9, 2018

As for web_accessible_resource, this is really something I'd like to avoid. Look for an alternative solution e.g. chrome.identity.launchWebAuthFlow etc.

@matheusfaustino
Copy link
Contributor Author

I will try to find another way instead of web_accessible_resource ^^. I know that some addons have an open url to validate. Is there a server for Stylus?

@tophf
Copy link
Member

tophf commented Jun 9, 2018

No, we don't have a server.

… api and get rid of web_accessible_resources
@matheusfaustino
Copy link
Contributor Author

matheusfaustino commented Jun 9, 2018

Hello @tophf, thank you very much for the tip about identity.launchWebAuthFlow that just worked perfectly. Now, there is no web_accessible_resources. I didn't know about launchWebAuthFlow, I really need to update myself about it.

If you think there is room for improvement, just tell me, please.

I think would be good if the user has some feedback when the file is uploading, but I couldn't find a nice way to do that.

edit: typo

@matheusfaustino
Copy link
Contributor Author

matheusfaustino commented Jun 18, 2018

I was thinking about using the current dialog to show that it's uploading the file and then close it automatically when it's done. What do you guys think?

@tophf
Copy link
Member

tophf commented Jun 18, 2018

Progress reporting is a good thing especially when the style database is 5MB or more. I think we'll also need a built-in gzip or zip in a pure js worker, but not necessarily in this PR.

@matheusfaustino
Copy link
Contributor Author

Yeah, I'm going to work on the progress reporting.

About gzip/zip I think it's very interesting idea. I found some libs that can help:

If I'd pick one, I'd choose jszip because the api is cleaner than the others. But we can discuss it better.
If we gonna implement the compression, I think we should do that before this PR, because we won't need to implement backward compatibility with decompression and compression version of it.

@matheusfaustino
Copy link
Contributor Author

I googled about progress bar on dropbox sdk and sadly they don't have anything to track the upload (dropbox/dropbox-sdk-js#157).
I could try simulate a progress bar by separating the file into severals chunks and upload it individually (filesUploadSession*), but maybe it would increase too much the integration complexity.

@DanaMW
Copy link

DanaMW commented Jun 19, 2018

I have been known to be wrong once in awhile but you could do it the old fashioned way and get the file size on start and simply have a small routine do the math yourself. I think dropbox is wrong on one count they have to keep track of how much is uploaded or blocks sent so that might allow you to get a progress indicator. Just thinking out loud. In the v1 API, the upload_chunk method returned an offset value - which is essentially the number of bytes uploaded.
Update
Found this maybe it will help: (Sorry if I need to climb back in my hole just yell, I am married to a redhead I am used to it):
https://www.dropboxforum.com/t5/API-Support-Feedback/measuring-the-amount-of-file-uploaded/td-p/272349

@matheusfaustino
Copy link
Contributor Author

Hi @DanaMW, thank you for your comment. That was what I said in my last statement about filesUploadSession* functions, maybe it wasn't clear, sorry.

I don't know if it's worth to create a more complex mechanism to upload a file just for a progress bar. Maybe just a couple of messages + compression would solve the problem better.

@DanaMW
Copy link

DanaMW commented Jun 20, 2018

Hi again on my machine using tampermonkey it all happens so fast you might not even get the bar drawn before it was done lol. Nice to meet you and have fun here man you picked a good crew.

@matheusfaustino
Copy link
Contributor Author

Hello guys, finally I had some time to implement the compression and decompression of the styles for the export and also I added some messages in the process. I hope you like.
If you need anything else, just tell me.

@Mottie
Copy link
Member

Mottie commented Jul 16, 2018

We've started including a LICENSE text file along with any vendor libraries. Please add it.

@matheusfaustino
Copy link
Contributor Author

Hi @Mottie, no problem, I added it now. Thanks.

@matheusfaustino
Copy link
Contributor Author

To resolve the conflict, do you prefer rebase or merge?

@tophf
Copy link
Member

tophf commented Jul 16, 2018

You can merge the master, we'll simply squash the PR into one commit later.

@matheusfaustino
Copy link
Contributor Author

Merge done ^^

@Mottie
Copy link
Member

Mottie commented Sep 12, 2018

Please rebase with the master... there are conflicts, so we can't just push the button 😉

@Mottie
Copy link
Member

Mottie commented Sep 12, 2018

Odd, I'm still seeing the conflicts message.

@matheusfaustino
Copy link
Contributor Author

Ops... my bad. I thought I had merged already.

@matheusfaustino
Copy link
Contributor Author

hmmm... that is weird. Let me see the commits hash from the master on github.

@matheusfaustino
Copy link
Contributor Author

Well, the last commit (e128498) is merged too.

@Mottie
Copy link
Member

Mottie commented Sep 12, 2018

I'm gonna let @tophf merge this PR anyway... I didn't look at the code, I've only tested it 😉

@matheusfaustino
Copy link
Contributor Author

Ok ^^ Thanks for testing :) you helped a lot

@narcolepticinsomniac
Copy link
Member

I see no conflicts anymore, but yeah, better to wait for tophf to give it the green light.

@Kenya-West
Copy link

@matheusfaustino please, make the same for OneDrive!

@matheusfaustino
Copy link
Contributor Author

Hi @Kenya-West , I'll look into the documentation to see how hard is to implement OneDrive, I personally don't use it, but if it's not that hard, why not?

@Kenya-West
Copy link

Hi @Kenya-West , I'll look into the documentation to see how hard is to implement OneDrive, I personally don't use it, but if it's not that hard, why not?

I think, OneDrive API is included in Microsoft Graph API, see graph.microsoft.com or dev.onedrive.com. I personally didn't work with Microsoft Graph, but I know, that Microsoft Graph is supporting both v1 and v2 versions. v1 has more APIs specific for Personal accounts and Work accounts, while v2 unifies Personal and Work accounts and offers single API queries, no matter business, school or personal subscription user is on. Despite v2 has a bit less functionality, it is very common action to upload and download files from/to specific folder in OneDrive, so this API method should exist in v2.

I suggest you to look at Tampermonkey's source code if possible. and probably Office Online add-on.

I will also investigate deep into this, but with no guarantees - I don't have experience in developing browser extensions (but I developed some Angular components just for run).

@matheusfaustino
Copy link
Contributor Author

Hi @tophf , how are you? I hope you're doing well.

Do you need something else from me? bye glhf

@mikhoul
Copy link

mikhoul commented Oct 1, 2018

@matheusfaustino commented on 1 oct. 2018 à 08:34 UTC−4:

Hi @tophf , how are you? I hope you're doing well.

Do you need something else from me? bye glhf

I really hope it will be merged soon 😄

@tophf
Copy link
Member

tophf commented Oct 2, 2018

I got tired so in the foreseeable time span I'm not working on Stylus except maybe on some trivial occasional stuff like CSSLint/parserlib. Mottie will handle the PR, I think.

@Mottie
Copy link
Member

Mottie commented Oct 2, 2018

Yeah, I'll take care of it soon... I've been busy with work.

@matheusfaustino
Copy link
Contributor Author

Hello, don't worry. I don't want to give trouble, it's just to know which step we are ^^ if you need something, please ping me :)

@Mottie Mottie merged commit 79c6506 into openstyles:master Nov 3, 2018
@narcolepticinsomniac
Copy link
Member

@matheusfaustino Are you working on this again right now?

@matheusfaustino
Copy link
Contributor Author

@narcolepticinsomniac I'm about to work on it. Actually, I'm testing the integration with OneDrive.
Yesterday, I fixed the url of Firefox's addon in dropbox settings

@narcolepticinsomniac
Copy link
Member

In the future, just give me a heads up on Discord or here if you're gonna log in to the account. I got a security alert, and you didn't respond to the ping, so I changed the password. I can DM you the new one if you need it.

@matheusfaustino
Copy link
Contributor Author

I'm sorry, I took the liberty of doing that, my bad. Ok, if I need it, I ping you. thanks ^^

@narcolepticinsomniac
Copy link
Member

It's all good. Mottie's got it too if I'm not around.

@narcolepticinsomniac
Copy link
Member

@matheusfaustino Check Discord.

@Mottie
Copy link
Member

Mottie commented Dec 9, 2018

I'm working on the issue now... essentially, Dropbox has locked our app because we never applied to put our Dropbox app into "production" after we reached 50 users. I'm filling out the form now.

@matheusfaustino
Copy link
Contributor Author

Hi @narcolepticinsomniac sorry I had some problems this weekend. I going to download the discord app to be in touch ^^
Thanks @Mottie , I'm working on that tutorial to test the dropbox implementation.

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.

None yet

9 participants