Skip to content
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
13 changes: 12 additions & 1 deletion wp1-frontend/src/components/MyLists.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
v-else-if="item.z_url && !hasDeletedZim(item)"
:class="{ 'outdated-zim': hasOutdatedZim(item) }"
>
<a :href="item.z_url">Download ZIM</a>
<a href="#" @click.prevent="downloadZim(item)">Download ZIM</a>
<span
v-if="hasOutdatedZim(item)"
data-toggle="tooltip"
Expand Down Expand Up @@ -269,6 +269,17 @@ export default {
localDate: function (date) {
return localDate(date);
},
downloadZim: async function (item) {
const response = await fetch(item.z_url);
if (response.status === 410) {
this.$router.push({
path: `/selections/${item.id}/zim`,
query: { expired: true },
});
} else {
window.location.href = item.z_url;
}
},
},
created: function () {
this.getLists();
Expand Down
17 changes: 14 additions & 3 deletions wp1-frontend/src/components/ZimFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
page and the My Selections page will automatically update with a URL
to download your ZIM file once it is ready.
</p>
<p v-if="isDeleted && status == 'FILE_READY'" class="errors">
<p
v-if="forceExpiredDisplay || (isDeleted && status == 'FILE_READY')"
class="errors"
>
Your ZIM file has expired and needs to be re-created. ZIM file
download links are only valid for 2 weeks. You can re-create your
ZIM file with the button below.
Expand All @@ -108,7 +111,8 @@
<div
v-if="
!activeSchedule &&
(status === 'NOT_REQUESTED' ||
(forceExpiredDisplay ||
status === 'NOT_REQUESTED' ||
status === 'FAILED' ||
(status != 'REQUESTED' && isDeleted))
"
Expand Down Expand Up @@ -294,7 +298,10 @@
</div>
</div>
<div
v-else-if="status === 'FILE_READY' || status === 'REQUESTED'"
v-else-if="
!forceExpiredDisplay &&
(status === 'FILE_READY' || status === 'REQUESTED')
"
class="row"
>
<div class="col-lg-6 col-md-9 mx-4">
Expand Down Expand Up @@ -364,11 +371,15 @@ export default {
repetitionPeriodInMonths: 1,
numberOfRepetitions: 1,
scheduleEmail: '',
forceExpiredDisplay: false,
};
},
created: async function () {
await this.getBuilder();
await this.getStatus();
if (this.$route.query.expired) {
this.forceExpiredDisplay = true;
}
await this.loadUserEmail();
this.ready = true;
},
Expand Down
5 changes: 5 additions & 0 deletions wp1/web/builders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import requests

import flask

Expand Down Expand Up @@ -356,6 +357,10 @@ def latest_zim_file_for_builder(builder_id):
if not url:
flask.abort(404)

head = requests.head(url)
if head.status_code == 404:
flask.abort(410)

return flask.redirect(url, code=302)


Expand Down
18 changes: 17 additions & 1 deletion wp1/web/builders_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,9 @@ def test_zimfarm_status(self):
"wp1.logic.builder.zimfarm.zim_file_url_for_task_id",
return_value="http://fake-file-host.fake/1234/file.zim",
)
def test_latest_zim_file_for_builder(self, mock_zimfarm):
@patch("wp1.web.builders.requests.head")
def test_latest_zim_file_for_builder(self, mock_head, mock_zimfarm):
mock_head.return_value.status_code = 200
builder_id = self._insert_builder()
self._insert_selections(builder_id)
self.app = create_app()
Expand All @@ -1306,6 +1308,20 @@ def test_latest_zim_file_for_builder_404(self):
rv = client.get("/v1/builders/abcd-1234/zim/latest")
self.assertEqual("404 NOT FOUND", rv.status)

@patch(
"wp1.logic.builder.zimfarm.zim_file_url_for_task_id",
return_value="http://fake-file-host.fake/1234/file.zim",
)
@patch("wp1.web.builders.requests.head")
def test_latest_zim_file_for_builder_410(self, mock_head, mock_zimfarm):
mock_head.return_value.status_code = 404
builder_id = self._insert_builder()
self._insert_selections(builder_id)
self.app = create_app()
with self.app.test_client() as client:
rv = client.get("/v1/builders/%s/zim/latest" % builder_id)
self.assertEqual("410 GONE", rv.status)

def test_latest_selection_article_count_for_builder(self):
builder_id = self._insert_builder()
self._insert_selections(builder_id)
Expand Down
Loading