From 92a20f4f584c39617bd809a7fd350c18d68584a6 Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 11 Jul 2019 09:16:14 -0700 Subject: [PATCH] tune max upload size --- .dockerignore | 3 ++- README.md | 14 +++++++------- photoapp/daemon.py | 7 ++++++- photoapp/thumb.py | 47 +++++++++++++++++++++++----------------------- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/.dockerignore b/.dockerignore index 13525a4..2658560 100644 --- a/.dockerignore +++ b/.dockerignore @@ -12,4 +12,5 @@ styles/mincss/ testenv/ source/ source_copy/ -raws/ \ No newline at end of file +raws/ +*.sql diff --git a/README.md b/README.md index 9f51879..583580d 100644 --- a/README.md +++ b/README.md @@ -114,19 +114,19 @@ This would ingest all the files listed in `shas.txt` that aren't already in the Roadmap ------- -- Stateless aka docker support - - Migration path - - open database - - copy files table to memory - - recreate files table - - insert into the new table, with replaced paths, generating a list of files moves at the same time - - migrate files to the new storage according to the list - Flesh out CLI: + - Relink function - make a photo a member of another photo - Config that is saved somewhere + - Album features - Support additional fields on upload like title description tags etc - delete features - tag features + - Tag on import - modify features (tags & images) + - "Batch" tag on import + - Generate a tag on import + - Save it in config and re-use it (if passing --same-batch) + - photos imported as a batch will be under 1 tag - Longer term ideas: - "fast ingest" method that touches the db/storage directly. This would scale better than the API ingest. - Dynamic svg placeholder for images we can't open diff --git a/photoapp/daemon.py b/photoapp/daemon.py index dc6a7f5..7f45426 100644 --- a/photoapp/daemon.py +++ b/photoapp/daemon.py @@ -432,6 +432,10 @@ def main(): default=os.environ.get("DATABASE_URL")), parser.add_argument('--debug', action="store_true", help="enable development options") + tunables = parser.add_argument_group(title="tunables") + tunables.add_argument('--max-upload', help="maximum file upload size accepted in bytes", + default=1024**3, type=int) + args = parser.parse_args() if not args.database: @@ -493,7 +497,8 @@ def main(): 'server.socket_host': '0.0.0.0', 'server.show_tracebacks': True, 'log.screen': False, - 'engine.autoreload.on': args.debug + 'engine.autoreload.on': args.debug, + 'server.max_request_body_size': args.max_upload }) # Setup signal handling and run it. diff --git a/photoapp/thumb.py b/photoapp/thumb.py index 7bffe1c..53ce463 100644 --- a/photoapp/thumb.py +++ b/photoapp/thumb.py @@ -38,33 +38,34 @@ class ThumbGenerator(object): return os.path.abspath(dest) if photo.width is None: # todo better detection of images that PIL can't open return None - if photo.uuid not in self._failed_thumbs_cache[style]: - thumb_width, thumb_height, flip_ok = styles[style] - i_width = photo.width - i_height = photo.height - im_is_rotated = photo.orientation % 2 != 0 or i_height > i_width + if photo.uuid in self._failed_thumbs_cache[style]: + return None - if im_is_rotated and flip_ok: - thumb_width, thumb_height = thumb_height, thumb_width + thumb_width, thumb_height, flip_ok = styles[style] + i_width = photo.width + i_height = photo.height + im_is_rotated = photo.orientation % 2 != 0 or i_height > i_width - thumb_width = min(thumb_width, i_width if i_width > 0 else 999999999) # TODO do we even have photo.width if PIL can't read the image? - thumb_height = min(thumb_height, i_height if i_height > 0 else 999999999) # TODO this seems bad + if im_is_rotated and flip_ok: + thumb_width, thumb_height = thumb_height, thumb_width - # TODO have the subprocess download the file - with tempfile.TemporaryDirectory() as tmpdir: - fpath = os.path.join(tmpdir, "image") - with self.library.storage.open(photo.path, 'rb') as fsrc: - with open(fpath, 'wb') as fdest: - copyfileobj(fsrc, fdest) + thumb_width = min(thumb_width, i_width if i_width > 0 else 999999999) # TODO do we even have photo.width if PIL can't read the image? + thumb_height = min(thumb_height, i_height if i_height > 0 else 999999999) # TODO this seems bad - p = Process(target=self.gen_thumb, args=(fpath, dest, thumb_width, thumb_height, photo.orientation)) - p.start() - p.join() - if p.exitcode != 0: - self._failed_thumbs_cache[style][photo.uuid] = True # dont retry failed generations - return None - return os.path.abspath(dest) - return None + # TODO have the subprocess download the file + with tempfile.TemporaryDirectory() as tmpdir: + fpath = os.path.join(tmpdir, "image") + with self.library.storage.open(photo.path, 'rb') as fsrc: + with open(fpath, 'wb') as fdest: + copyfileobj(fsrc, fdest) + + p = Process(target=self.gen_thumb, args=(fpath, dest, thumb_width, thumb_height, photo.orientation)) + p.start() + p.join() + if p.exitcode != 0: + self._failed_thumbs_cache[style][photo.uuid] = True # dont retry failed generations + return None + return os.path.abspath(dest) @staticmethod def gen_thumb(src_img, dest_img, width, height, rotation):