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

URL for current latest download #289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions KerbalStuff/blueprints/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,16 @@ def _allow_download(mod: Mod) -> bool:


@mods.route('/mod/<int:mod_id>/download/<version>', defaults={'mod_name': None})
@mods.route('/mod/<int:mod_id>/download', defaults={'mod_name': None, 'version': None})
@mods.route('/mod/<int:mod_id>/<path:mod_name>/download', defaults={'version': None})
@mods.route('/mod/<int:mod_id>/<path:mod_name>/download/<version>')
@with_session
def download(mod_id: int, mod_name: str, version: str) -> Optional[werkzeug.wrappers.Response]:
def download(mod_id: int, mod_name: Optional[str], version: Optional[str]) -> Optional[werkzeug.wrappers.Response]:
mod, game = _get_mod_game_info(mod_id)
if not _allow_download(mod):
abort(401)
mod_version = ModVersion.query.filter(ModVersion.mod_id == mod_id,
ModVersion.friendly_version == version).first()
mod_version = mod.default_version if not version or version == 'download' \
else next(filter(lambda v: v.friendly_version == version, mod.versions), None)
if not mod_version:
abort(404)
download = DownloadEvent.query\
Expand Down
2 changes: 1 addition & 1 deletion templates/mod.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h1 title="{{ mod.name }}">
</div>
<div class="{% if user %}col-md-2{% else %}col-md-4{% endif %}">
<a class="btn btn-block btn-lg btn-primary piwik_download" id="download-link-primary"
href="{{ url_for("mods.download", mod_id=mod.id, mod_name=mod.name, version=latest.friendly_version) }}">
href="{{ url_for("mods.download", mod_id=mod.id, mod_name=mod.name) }}">
Download {% if latest.id in size_versions and size_versions[latest.id] is not none %} ({{ size_versions[latest.id] }}) {% endif %}</a>
</div>
{% if user %}
Expand Down
2 changes: 1 addition & 1 deletion templates/mod_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h3>
{% endif %}
</div>
<div class="col-md-8">
<a href="{{ url_for("mods.download", mod_name=mod.name, mod_id=mod.id, version=mod.default_version.friendly_version) }}" class="btn btn-block btn-lg btn-primary">Download</a>
<a href="{{ url_for("mods.download", mod_name=mod.name, mod_id=mod.id) }}" class="btn btn-block btn-lg btn-primary">Download</a>
</div>
</div>
</div>
Expand Down