From f016f4c8050a223800e8a26c8dca717a3d0c7a6f Mon Sep 17 00:00:00 2001 From: Aaron W Morris Date: Sun, 20 Feb 2022 21:12:23 -0500 Subject: [PATCH] update file references for image folder instead of docroot --- flask.json_template | 1 + indi_allsky/flask/forms.py | 37 +++++++++++++++++++++++++++------ indi_allsky/flask/views.py | 9 ++++++-- service/apache_indi-allsky.conf | 1 + service/nginx_astroberry_ssl | 2 +- setup.sh | 1 + 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/flask.json_template b/flask.json_template index 0f57268fe..2178a1c3c 100644 --- a/flask.json_template +++ b/flask.json_template @@ -7,6 +7,7 @@ "INDI_ALLSKY_CONFIG" : "%ALLSKY_ETC%/config.json", "INDI_ALLSKY_DOCROOT" : "%HTDOCS_FOLDER%", + "INDI_ALLSKY_IMAGE_FOLDER" : "%IMAGE_FOLDER%", "INDI_ALLSKY_STATUS" : "%DB_FOLDER%/indi_allsky_status.json", "INDI_ALLSKY_PID" : "%DB_FOLDER%/indi-allsky.pid", diff --git a/indi_allsky/flask/forms.py b/indi_allsky/flask/forms.py index ceb06737c..cf6a9007d 100644 --- a/indi_allsky/flask/forms.py +++ b/indi_allsky/flask/forms.py @@ -755,9 +755,14 @@ def getImages(self, year, month, day, hour): images_choices = [] for i in images_query: filename_p = Path(i.filename) - rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_DOCROOT']) - entry = (str(rel_filename_p), str(i.createDate.strftime('%H:%M:%S'))) + try: + rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_IMAGE_FOLDER']) + except ValueError as e: + app.logger.error('Error determining relative file name: %s', str(e)) + continue + + entry = (str(Path('images').joinpath(rel_filename_p)), str(i.createDate.strftime('%H:%M:%S'))) images_choices.append(entry) @@ -878,10 +883,15 @@ def getVideos(self, year, month, timeofday): videos_data = [] for v in videos_query: filename_p = Path(v.filename) - rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_DOCROOT']) + + try: + rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_IMAGE_FOLDER']) + except ValueError as e: + app.logger.error('Error determining relative file name: %s', str(e)) + continue entry = { - 'url' : str(rel_filename_p), + 'url' : str(Path('images').joinpath(rel_filename_p)), 'dayDate' : v.dayDate.strftime('%B %d, %Y'), 'night' : v.night, } @@ -902,8 +912,16 @@ def getVideos(self, year, month, timeofday): .order_by(IndiAllSkyDbKeogramTable.createDate.asc())\ .first() # use the oldest (asc) + if keogram_entry: - keogram_url = str(Path(keogram_entry.filename).relative_to(app.config['INDI_ALLSKY_DOCROOT'])) + keogram_p = Path(keogram_entry.filename) + + try: + rel_keogram_p = keogram_p.relative_to(app.config['INDI_ALLSKY_IMAGE_FOLDER']) + keogram_url = str(Path('images').joinpath(rel_keogram_p)) + except ValueError as e: + app.logger.error('Error determining relative file name: %s', str(e)) + keogram_url = None else: keogram_url = None @@ -918,7 +936,14 @@ def getVideos(self, year, month, timeofday): if startrail_entry: - startrail_url = str(Path(startrail_entry.filename).relative_to(app.config['INDI_ALLSKY_DOCROOT'])) + startrail_p = Path(startrail_entry.filename) + + try: + rel_startrail_p = startrail_p.relative_to(app.config['INDI_ALLSKY_IMAGE_FOLDER']) + startrail_url = str(Path('images').joinpath(rel_startrail_p)) + except ValueError as e: + app.logger.error('Error determining relative file name: %s', str(e)) + startrail_url = None else: startrail_url = None diff --git a/indi_allsky/flask/views.py b/indi_allsky/flask/views.py index 56af200b0..bb013123c 100644 --- a/indi_allsky/flask/views.py +++ b/indi_allsky/flask/views.py @@ -391,10 +391,15 @@ def getLatestImages(self, history_seconds): image_list = list() for i in latest_images: filename_p = Path(i.filename) - rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_DOCROOT']) + + try: + rel_filename_p = filename_p.relative_to(app.config['INDI_ALLSKY_IMAGE_FOLDER']) + except ValueError as e: + app.logger.error('Error determining relative file name: %s', str(e)) + continue data = { - 'file' : str(rel_filename_p), + 'file' : str(Path('images').joinpath(rel_filename_p)), 'sqm' : i.sqm, 'stars' : i.stars, } diff --git a/service/apache_indi-allsky.conf b/service/apache_indi-allsky.conf index 87f61ec8c..e0b516c61 100644 --- a/service/apache_indi-allsky.conf +++ b/service/apache_indi-allsky.conf @@ -20,6 +20,7 @@ Require all granted + Options +Indexes diff --git a/service/nginx_astroberry_ssl b/service/nginx_astroberry_ssl index c8a0c2ecd..48f3af759 100644 --- a/service/nginx_astroberry_ssl +++ b/service/nginx_astroberry_ssl @@ -23,7 +23,7 @@ server { location /indi-allsky/images { alias %IMAGE_FOLDER%; - autoindex off; + autoindex on; } location /indi-allsky/static { diff --git a/setup.sh b/setup.sh index 1afabeabf..baa833463 100755 --- a/setup.sh +++ b/setup.sh @@ -692,6 +692,7 @@ sed \ -e "s|%SECRET_KEY%|$SECRET_KEY|g" \ -e "s|%ALLSKY_ETC%|$ALLSKY_ETC|g" \ -e "s|%HTDOCS_FOLDER%|$HTDOCS_FOLDER|g" \ + -e "s|%IMAGE_FOLDER%|$IMAGE_FOLDER|g" \ -e "s|%INDISEVER_SERVICE_NAME%|$INDISEVER_SERVICE_NAME|g" \ -e "s|%ALLSKY_SERVICE_NAME%|$ALLSKY_SERVICE_NAME|g" \ -e "s|%GUNICORN_SERVICE_NAME%|$GUNICORN_SERVICE_NAME|g" \