Fix bad download file names

Fixes #116
This commit is contained in:
rubenwardy 2021-05-04 22:06:31 +01:00
parent f4792ac537
commit e9161610c4
2 changed files with 10 additions and 4 deletions

@ -872,6 +872,9 @@ class PackageRelease(db.Model):
def __init__(self): def __init__(self):
self.releaseDate = datetime.datetime.now() self.releaseDate = datetime.datetime.now()
def getDownloadFileName(self):
return f"{self.package.name}_{self.id}.zip"
def approve(self, user): def approve(self, user):
if not self.checkPerm(user, Permission.APPROVE_RELEASE): if not self.checkPerm(user, Permission.APPROVE_RELEASE):
return False return False

@ -25,7 +25,6 @@
{% set package_warning="Non-free media" %} {% set package_warning="Non-free media" %}
{% endif %} {% endif %}
{% set release = package.getDownloadRelease() %} {% set release = package.getDownloadRelease() %}
<main> <main>
{% set cover_image = package.cover_image.url or package.getMainScreenshotURL() %} {% set cover_image = package.cover_image.url or package.getMainScreenshotURL() %}
<header class="jumbotron pb-3" <header class="jumbotron pb-3"
@ -94,7 +93,8 @@
{{ package.author.display_name }} {{ package.author.display_name }}
</span> </span>
</a> </a>
<a class="btn" rel="nofollow" href="{{ package.getDownloadURL() }}" title="{{ _("Downloads") }}"> <a class="btn" rel="nofollow" href="{{ package.getDownloadURL() }}" title="{{ _("Downloads") }}"
download="{{ release.getDownloadFileName() }}">
<i class="fas fa-download"></i> <i class="fas fa-download"></i>
<span class="count">{{ package.downloads }}</span> <span class="count">{{ package.downloads }}</span>
</a> </a>
@ -151,7 +151,7 @@
{% endif %} {% endif %}
<div class="btn-group btn-group-horizontal col-md-auto"> <div class="btn-group btn-group-horizontal col-md-auto">
{% if release %} {% if release %}
<a class="btn btn-download" rel="nofollow" <a class="btn btn-download" rel="nofollow" download="{{ release.getDownloadFileName() }}"
href="{{ package.getDownloadURL() }}"> href="{{ package.getDownloadURL() }}">
{{ _("Download") }} {{ _("Download") }}
</a> </a>
@ -466,7 +466,10 @@
{% if not rel.approved %}<i>{% endif %} {% if not rel.approved %}<i>{% endif %}
<a href="{{ rel.getDownloadURL() }}" rel="nofollow">{{ rel.title }}</a> <a href="{{ rel.getDownloadURL() }}" rel="nofollow"
download="{{ rel.getDownloadFileName() }}">
{{ rel.title }}
</a>
<span style="color:#ddd;"> <span style="color:#ddd;">
{% if rel.min_rel and rel.max_rel %} {% if rel.min_rel and rel.max_rel %}