download the first element if no <FILE> was set in URL
Closed this issue ยท 13 comments
Hi there,
First thanks for the clever lib you made! ๐ really nice!
i wanted to add an enhancement, when passing empty <FILE>
in url, we are getting error, (which is obvious) but instead, could we make it download the first file by default (if there is existing files already)?
so, this url:
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/
will download the first file in release (since it's null) if it exist.
this feature could be awesome!
For more enhancement, we could play around with it:
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/0/
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/1/
will respectively download files by indexes in the release files.
(testing by regex, if it ends with "%d/")
if this wasn't accepted, could you at least make the wabpage accept it as a query?
so, this url:
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/?index=0
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/?index=1
will always download files by indexes instead of returning error!
like that, we will never add the file names and URLs becomes static!! ๐
Hi, thanks for taking the time to get in contact. The use-case seems to be clearly understandable by me.
I would like to keep in mind that this is hosted by github pages which means, the base-url can be
https://USER.github.io/ or https://USER.github.io/download_latest/ so that using 2 elements in the url does not make it clear what is the case, also if hosted on other domains. Assumptions are not made and not specified.
Given this, I prefer this as an implementation:
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/?index=0
This can also be extended with other parameters such as regex, ...
This would be a new feature.
when passing empty in url, we are getting error
This would be an error report. Would you like to specify the error and the console log? Would it be better to discuss this in this feature request or would it be good to open a new issue? I understand that many people will only upload one release file, so this could also be a feature request. What would you like to do? By the way, your contributions are welcome.
yes i'm ok with that, i need that feature on. any implementation could work.
you asked about my console, i think nothing could be important there, since it's code logic issue, but here it is anyway.
link: https://pastebin.com/9Fw1gH1K
(my wanted results are different, but this is a default release i have tested with, i didn't yet posted any releases in my project, looking forward for global solution )
i have already investigated with your code, i think applying changes to this function should do it (if assetName is null, we download first element if release.assets.length > 0 when index query is set)
link: https://github.com/niccokunzmann/download_latest/blob/master/_includes/github.js#L14-L31
if needed, here is a smart implementation of getting query by key from URL if needed:
/**
* get href query param by key
*/
function getQueryParam(param) {
var result = window.location.search.match(
new RegExp("(\\?|&)" + param + "(\\[\\])?=([^&]*)")
);
return result ? result[3] : false;
}
I agree that this would be the correct position for modification.
I would recommend dispatching in the function redirectToReleaseFile to
redirectToReleaseFileNamed and redirectToReleaseFileWithIndex depending on what is given.
yes, that could be way too clear! ๐
ping me when changes are submitted to master, looking forward to test it live!
i'm not expert at github, i know just the basics. could you please do it?
No. I can teach you. Here are some starters: http://try.github.io/ If you have questions, you can ask me.
@chlegou We now have this interface: https://github.com/niccokunzmann/download_latest/blob/master/_includes/common.js#L46
We can still use something like ?download=first
.
Thanks for it, but What if we wanted the second, third or n item?
I have implemented it this way: ?index=0..n
When index is set, it download the file with that index from the latest release files.
If not set, it automatically bind the first file.
If a file name was set, it will behave normally as you made it.
I believed that this way, it's working way dynamic in my case.
Link: https://github.com/chlegou/download_latest/blob/8720051371b81c94ec629bc64e37342c7440b8ef/_includes/github.js#L35
See it in action: https://chlegou.github.io/bitbot/ (the Github download button)
I hope you find it useful and implement it also ;)
Done! ;)
it's for you to resolve conflicts then. ;p
@chlegou Thank you for your contribution. I checked and it works fine. I will close this issue now. If you like to comment, feel free to do so.