From 46d67365ba9d58d74446b75936580be3b4b9e315 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 25 Aug 2021 23:21:11 -0700 Subject: [PATCH] misc thumbservice todos --- README.md | 5 +++-- photoapp/thumbserver.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2fee9e8..cbd0741 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ more information. Optional: Photolib uses a secondary service to generate thumbnails for video files. After the above installation instructions are complete, run `photothumbd` on a differnet port with the same arguments. On first run, it will create -a user for internal communications and log the username/password. This username/password must be used in the -`--thumb-service` for `photoappd`. +a user for internal communications and log the username/password or you can set `THUMBSERVICE_INITIAL_PASSWORD_HASH` to +the sha256 hash of the desired password. This username/password must be used in the `--thumb-service` option +for `photoappd`. Commands diff --git a/photoapp/thumbserver.py b/photoapp/thumbserver.py index 6c57274..803eb67 100644 --- a/photoapp/thumbserver.py +++ b/photoapp/thumbserver.py @@ -20,7 +20,7 @@ from photoapp.common import pwhash from photoapp.dbsession import DatabaseSession from photoapp.thumb import thumb_path, image_file_style from photoapp.webutils import validate_password -from photoapp.utils import genpw +from photoapp.utils import genpw, get_extension THUMBSERVICE_USER_INTERNAL = "_thumbservice" @@ -112,10 +112,13 @@ def setup_thumb_user(engine): if u: return - password = genpw() + password_hash = os.environ.get("THUMBSERVICE_INITIAL_PASSWORD_HASH") + if not password_hash: + password = genpw() + logging.warning("created thumbserver user: %s:%s", THUMBSERVICE_USER_INTERNAL, password) + password_hash = pwhash(password) - logging.warning("created thumbserver user: %s:%s", THUMBSERVICE_USER_INTERNAL, password) - s.add(User(name=THUMBSERVICE_USER_INTERNAL, password=pwhash(password))) + s.add(User(name=THUMBSERVICE_USER_INTERNAL, password=password_hash)) s.commit() @@ -188,8 +191,9 @@ class ThumbWorker(Thread): return # download the image - local_src_path = os.path.join(tmpdir, image.fname) # TODO fname isn't sanitized? use temp. + local_src_path = os.path.join(tmpdir, "input.{}".format(get_extension(image.fname))) thumb_tmp_path = os.path.join(tmpdir, "thumb.jpg") + # TODO simplify low level operations like this with ( self.library.open(image.path, "rb") as src, open(local_src_path, "wb") as dest, @@ -265,7 +269,7 @@ def main(): parser = argparse.ArgumentParser(description="Photod photo server") parser.add_argument('-p', '--port', help="tcp port to listen on", - default=int(os.environ.get("THUMB_SERVICE_PORT", 8081)), type=int) + default=int(os.environ.get("THUMBSERVICE_PORT", 8081)), type=int) parser.add_argument('-l', '--library', default=os.environ.get("STORAGE_URL"), help="library path") parser.add_argument('-c', '--cache', default=os.environ.get("CACHE_URL"), help="cache url") # https://docs.sqlalchemy.org/en/13/core/engines.html