]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/handlers_download.py
6 from handlers_base
import *
8 class DownloadFileHandler(BaseHandler
):
10 self
.set_header("Pragma", "no-cache")
12 def head(self
, filename
):
13 self
.redirect_to_mirror(filename
)
15 def get(self
, filename
):
16 self
.redirect_to_mirror(filename
, log_download
=True)
18 def find_mirror(self
, filename
):
19 exists
= self
.mirrors
.file_exists(filename
)
21 raise tornado
.web
.HTTPError(404, "File not found: %s" % filename
)
23 # Find mirrors located near to the user.
24 # If we have not found any, we use a random one.
25 remote_location
= self
.get_remote_location()
28 mirrors
= self
.mirrors
.get_for_location(remote_location
, filename
=filename
)
31 return random
.choice(mirrors
)
33 return self
.mirrors
.get_random(filename
=filename
)
35 def redirect_to_mirror(self
, filename
, log_download
=False):
36 # Find a random mirror.
37 mirror
= self
.find_mirror(filename
)
39 # Construct the redirection URL.
40 download_url
= mirror
.build_url(filename
)
42 # Redirect the request.
43 self
.redirect(download_url
)
48 remote_location
= self
.get_remote_location()
50 country_code
= remote_location
.country
54 self
.db
.execute("INSERT INTO log_download(filename, mirror, country_code) \
55 VALUES(%s, %s, %s)", filename
, mirror
.id, country_code
)
58 class DownloadCompatHandler(BaseHandler
):
59 def get(self
, path
, url
):
60 for filename
in self
.mirrors
.get_all_files():
61 if not filename
.endswith("/%s" % url
):
64 self
.redirect("/%s" % filename
)
67 raise tornado
.web
.HTTPError(404)