GithubHelp home page GithubHelp logo

Comments (12)

loilo avatar loilo commented on May 30, 2024 1

Side note: I've taken a look on this, but this is currently technically impossible due to raw.githubusercontent.com returning 403 answers for OPTIONS requests. However, those requests are inevitably made by the browser as preflight requests when making authorized calls with a bearer token attached.

This problem has been reported to GitHub relatively recently and at least they are aware.

However, until this changes, it will not be possible to do a purely client-side XHR request to private resources.

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024 1

Sounds good to me. Going to take a look soon — got another PR regarding error handling to land first (i.e. in a few seconds, be prepared 😁).

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

That said, file contents could still be fetched via the GitHub API.

@fregante What would be your shot at this? Would you wait for GitHub to change their CORS behavior or make requests to the GitHub API? I'd happily implement anything. 😄

from download-directory.github.io.

fregante avatar fregante commented on May 30, 2024

That said, file contents could still be fetched via the GitHub API.

The GitHub API is limited (filesize) so this change would break downloading some larger files.

impossible due to raw.githubusercontent.com returning 403 answers for OPTIONS requests

When does this happen? How are you passing the authorization? Pre-flight doesn't happen if we use simple requests

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

Pre-flight does happen though if we're trying to authenticate with a bearer token (Authorization header → not a simple request). This seems to be the only working authentication mechanism for our case.

When private files are shown in the browser, GitHub appends a token GET parameter, however this does not seem to use regular access tokens — at least I'm getting 404 errors when I'm trying to use my access token in that place. (The token itself is fine, I can use it to e.g. grab the file when using it as a bearer token.)

from download-directory.github.io.

fregante avatar fregante commented on May 30, 2024

This seems to be the only working authentication mechanism for our case.

Yeah, HTTP authentication via URL and XMLHttpRequest.open doesn't seem to be supported anymore. curl https://[email protected]/file.ext works but not in the browser.

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

Yep, those are the approaches I've tried as well. Seems that we're stuck with waiting for GitHub on this one.

from download-directory.github.io.

fregante avatar fregante commented on May 30, 2024

What do you think about implementing the API as a fallback for private repos? I think it'd have to check whether all the files are under 1MB as well; thankfully this info is available in the list API call.

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

We can use GitHub's blob API to fetch files up to 100 MB. However, we need the files' sha hashes for that. list-github-dir-content actually fetches that data but does only return the file names.

To avoid redundant requests: Would you copy the list functionality over to this project or extend the list package with an option to include file details in the returned array?

from download-directory.github.io.

fregante avatar fregante commented on May 30, 2024

list-github-dir-content exists only because of download-directory.github.io. Since it doesn't have tests, download-directory.github.io serves as a "live test."

In short, I'd extend it rather than copy it here.


If you want to send a PR there, we could add a flag to get the whole file object instead of just the path

- files.push(item.path);
+ if (getWholeData) {
+ 	files.push(item);
+ } else {
+ 	files.push(item.path);
+ }

Thoughts?


With a new flag however I'd suggest changing its API(s) to:

viaTreesApi({
	user: '',
	repository: '',
	ref: '',
	directory: '',
	token: '',

	getWholeData: false // new, name TBD
})

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

Exactly how I'd have done it, nice. Going to submit a PR. Suggested names: detailed, withDetails, includeDetails, withMetadata, includeMetadata?

from download-directory.github.io.

loilo avatar loilo commented on May 30, 2024

I don't like either of my suggestions. detailed is not self-explaining enough IMO and all of the others indicate that metadata is sent alongside the file names, not in their place.

from download-directory.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.