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

Debug download.html example. #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ruffin--
Copy link

@ruffin-- ruffin-- commented Sep 6, 2022

This PR makes download.html [nearly] functional. The previous version did not work.

I've made a few fixes and changes, including adding several convenience features.

  1. Fixed typos in downloadfile function
    • The fileid was ignored; value had been hard-coded, which wouldn't work.
    • console.logs referenced "uploads"; now says download.
  2. Auth token is now saved in localStorage so that you don't have to get a token each time.
  3. access_token was assigned but unused; it's now trivially used.
  4. locationid was assigned but unused. It's saved to localStorage now, but is essentially unused.
  5. listFiles is now recursive through folders.
  6. lifeFiles reads a maxdepth from the ui to limit the folder depth used.
    • Default is 2 to include Demo Audio 2.mp3 if using a client_id with all folder access.
  7. Message displayed explaining "private" apps if no files are found for the pCloudSampleApp client_id.
  8. Double-quotes as requested by .prettierrc.

I realize this is slightly more complicated than a simplest case, but is the minimum I think you could give to demonstrate something approaching real-world usage. At just under 150 lines with html, it's not horrible. It is both folder & file listing plus download.


client_ids and private vs. all folder access

I noticed that there were two client_id values being used throughout the example folder:

  1. new_APP, client_id of "3dunsTvYJsu", ALL FOLDERS access
  2. pCloudSampleApp, client_id of "p1WznE2dEPm", private access only

I included both in the code here, though the pCloundSampleApp client_id is hooked up by default. That does mean a user needs to put files in its app folder, which is why I added the message in case the app-specific folder is empty, as mentioned above.


Strange server behavior

There are a few other things I'd clean up in a perfect world. I'd remove parent-scoped variables and change variable names to camelCase, for instance. But this seems to work fairly well, except...

The download doesn't seem to work! There's a CORS error, which means pCloud would need to change settings on the API side for this to work from a browser using the example code, even fixed.

It'll work from node, of course, or something else that isn't worried about CORS, but not from a browser on a non-pCloud domain.

download.html:1 Access to XMLHttpRequest at 
'https://vc828.pcloud.com/[value removed]/Demo%20Audio%202.mp3' 
from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.

I'll open an issue for that and reference it here. EDIT: Looks like it's been open a while, and the answer is that getfilelink isn't supposed to work with CORS. :sigh:

This method can't be used from web applications. Referrer is restricted to pcloud.com.

If true, we should probably remove download.html, right?

I've also noticed I have to sign-in twice in the OAuth interface to get a token with the examples. That's strange, though it doesn't prevent the app from eventually functioning.

Thank you!

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.

1 participant