Przeglądaj źródła

reworked getting of resized files

Dimitri Korsch 3 lat temu
rodzic
commit
1826554889

+ 5 - 1
pycs/frontend/WebServer.py

@@ -250,7 +250,11 @@ class WebServer:
             view_func=GetFile.as_view('get_file')
         )
         self.app.add_url_rule(
-            '/data/<int:file_id>/<resolution>',
+            '/data/<int:file_id>/<int:max_width>',
+            view_func=GetResizedFile.as_view('get_resized_file_by_width')
+        )
+        self.app.add_url_rule(
+            '/data/<int:file_id>/<int:max_width>x<int:max_height>',
             view_func=GetResizedFile.as_view('get_resized_file')
         )
         self.app.add_url_rule(

+ 3 - 8
pycs/frontend/endpoints/data/GetResizedFile.py

@@ -19,22 +19,17 @@ class GetResizedFile(View):
     # pylint: disable=arguments-differ
     methods = ['GET']
 
-    def dispatch_request(self, file_id: int, resolution: str):
+    def dispatch_request(self, file_id: int, max_width: int, max_height: int = 2**24):
         # get file from database
         file = File.query.get(file_id)
         if file is None:
-            return abort(404, "file object not found")
+            abort(404, "file object not found")
 
         if not os.path.exists(file.path):
-            return abort(404, "image not found!")
+            abort(404, "image not found!")
 
         project = file.project
 
-        # extract desired resolution
-        resolution = re.split(r'[^0-9]', resolution)
-        max_width = int(resolution[0])
-        max_height = int(resolution[1]) if len(resolution) > 1 else 2 ** 24
-
         # send data
         file_directory, file_name = tpool.execute(resize_file,
                                                   project.id, file.id, max_width, max_height)