]> git.ipfire.org Git - ipfire.org.git/commitdiff
Move download handlers into new module
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2018 12:02:52 +0000 (13:02 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 1 Sep 2018 12:02:52 +0000 (13:02 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/web/__init__.py
src/web/download.py
src/web/handlers.py
src/web/handlers_download.py [deleted file]

index bd0b71d7a86d4cbbbefe7aa6f310811fa9118361..0e4719e7e678cf10892eb73dd757d9b1290c4caf 100644 (file)
@@ -81,7 +81,6 @@ web_PYTHON = \
        src/web/handlers_admin.py \
        src/web/handlers_base.py \
        src/web/handlers_boot.py \
-       src/web/handlers_download.py \
        src/web/handlers_fireinfo.py \
        src/web/handlers_iuse.py \
        src/web/handlers_mirrors.py \
index 2db2a1a2ab09741f819f5751b427c7ec8ab22c4d..6c3d547976ce9aaa2a5dcb10c166a8636546a8cb 100644 (file)
@@ -134,8 +134,8 @@ class Application(tornado.web.Application):
 
                # downloads.ipfire.org
                self.add_handlers(r"downloads?(\.dev)?\.ipfire\.org", [
-                       (r"/(iso|torrent)/(.*)", DownloadCompatHandler),
-                       (r"/(.*)", DownloadFileHandler),
+                       (r"/", tornado.web.RedirectHandler, { "url" : "https://www.ipfire.org/" }),
+                       (r"/(.*)", download.FileHandler),
                ])
 
                # mirrors.ipfire.org
index 689d2ebdda60cde1685865e8ecd1214fd078b3fa..fd18a147ea296f8d4281ec7426651190f58e8ac0 100644 (file)
@@ -1,5 +1,6 @@
 #!/usr/bin/python
 
+import random
 import tornado.web
 
 from . import handlers_base as base
@@ -24,6 +25,56 @@ class ReleaseHandler(base.BaseHandler):
                self.render("download/release.html", release=release)
 
 
+class FileHandler(base.BaseHandler):
+       def prepare(self):
+               self.set_header("Pragma", "no-cache")
+
+       def head(self, filename):
+               self.redirect_to_mirror(filename)
+
+       def get(self, filename):
+               self.redirect_to_mirror(filename, log_download=True)
+
+       def find_mirror(self, filename):
+               exists = self.mirrors.file_exists(filename)
+               if not exists:
+                       raise tornado.web.HTTPError(404, "File not found: %s" % filename)
+
+               # Find mirrors located near to the user.
+               # If we have not found any, we use a random one.
+               remote_location = self.get_remote_location()
+
+               if remote_location:
+                       mirrors = self.mirrors.get_for_location(remote_location, filename=filename)
+
+                       if mirrors:
+                               return random.choice(mirrors)
+
+               return self.mirrors.get_random(filename=filename)
+
+       def redirect_to_mirror(self, filename, log_download=False):
+               # Find a random mirror.
+               mirror = self.find_mirror(filename)
+
+               # Construct the redirection URL.
+               download_url = mirror.build_url(filename)
+
+               # Redirect the request.
+               self.redirect(download_url)
+
+               if not log_download:
+                       return
+
+               remote_location = self.get_remote_location()
+               if remote_location:
+                       country_code = remote_location.country
+               else:
+                       country_code = None
+
+               self.db.execute("INSERT INTO log_download(filename, mirror, country_code) \
+                       VALUES(%s, %s, %s)", filename, mirror.id, country_code)
+
+
 class ButtonModule(ui_modules.UIModule):
        def render(self, release):
                for arch in release.arches:
index 27ba74944ee10832cc84b016290fa8902322c4a9..6a86e3dd8c7ae5c6c22f440c5db5bc85b80f8758 100644 (file)
@@ -20,7 +20,6 @@ from handlers_accounts import *
 from handlers_admin import *
 from handlers_base import *
 from handlers_boot import *
-from handlers_download import *
 from handlers_fireinfo import *
 from handlers_iuse import *
 from handlers_mirrors import *
diff --git a/src/web/handlers_download.py b/src/web/handlers_download.py
deleted file mode 100644 (file)
index 11a0985..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/python
-
-import random
-import tornado.web
-
-from handlers_base import *
-
-class DownloadFileHandler(BaseHandler):
-       def prepare(self):
-               self.set_header("Pragma", "no-cache")
-
-       def head(self, filename):
-               self.redirect_to_mirror(filename)
-
-       def get(self, filename):
-               self.redirect_to_mirror(filename, log_download=True)
-
-       def find_mirror(self, filename):
-               exists = self.mirrors.file_exists(filename)
-               if not exists:
-                       raise tornado.web.HTTPError(404, "File not found: %s" % filename)
-
-               # Find mirrors located near to the user.
-               # If we have not found any, we use a random one.
-               remote_location = self.get_remote_location()
-
-               if remote_location:
-                       mirrors = self.mirrors.get_for_location(remote_location, filename=filename)
-
-                       if mirrors:
-                               return random.choice(mirrors)
-
-               return self.mirrors.get_random(filename=filename)
-
-       def redirect_to_mirror(self, filename, log_download=False):
-               # Find a random mirror.
-               mirror = self.find_mirror(filename)
-
-               # Construct the redirection URL.
-               download_url = mirror.build_url(filename)
-
-               # Redirect the request.
-               self.redirect(download_url)
-
-               if not log_download:
-                       return
-
-               remote_location = self.get_remote_location()
-               if remote_location:
-                       country_code = remote_location.country
-               else:
-                       country_code = None
-
-               self.db.execute("INSERT INTO log_download(filename, mirror, country_code) \
-                       VALUES(%s, %s, %s)", filename, mirror.id, country_code)
-
-
-class DownloadCompatHandler(BaseHandler):
-       def get(self, path, url):
-               for filename in self.mirrors.get_all_files():
-                       if not filename.endswith("/%s" % url):
-                               continue
-
-                       self.redirect("/%s" % filename)
-                       return
-
-               raise tornado.web.HTTPError(404)