Improved properties unzip handling (#447)

* Attempt to unzip a properties file when unzipping individual files

* Don't show the unzip button for properties files

* Hide properties files in zip files, and show an asterisk for images with associated properties

* Cleanup

* Have properties files expand below images in archives

* Hide bullets

* Improve layout
This commit is contained in:
Daniel Markstedt 2021-11-13 17:38:01 -08:00 committed by GitHub
parent 41c3405b99
commit 65d0a9b2e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 12 deletions

View File

@ -190,17 +190,18 @@ def unzip_file(file_name, member=False, members=False):
name = PurePath(path).name
rename_file(f"{server_info['image_dir']}/{name}", f"{CFG_DIR}/{name}")
prop_flag = True
elif member.endswith(PROPERTIES_SUFFIX):
unzip_proc = run(
["unzip", "-d", CFG_DIR, "-n", "-j", \
f"{server_info['image_dir']}/{file_name}", escape(member)], capture_output=True
)
prop_flag = True
else:
unzip_proc = run(
["unzip", "-d", server_info["image_dir"], "-n", "-j", \
f"{server_info['image_dir']}/{file_name}", escape(member)], capture_output=True
)
# Attempt to unzip a properties file in the same archive dir
unzip_prop = run(
["unzip", "-d", CFG_DIR, "-n", "-j", \
f"{server_info['image_dir']}/{file_name}", escape(member) + "." + PROPERTIES_SUFFIX], capture_output=False
)
if unzip_prop.returncode == 0:
prop_flag = True
if unzip_proc.returncode != 0:
stderr = unzip_proc.stderr.decode("utf-8")
logging.warning("Unzipping failed: %s", stderr)

View File

@ -7,7 +7,7 @@ from os import getenv, getcwd
WEB_DIR = getcwd()
# There may be a more elegant way to get the HOME dir of the user that installed RaSCSI
HOME_DIR = "/".join(WEB_DIR.split("/")[0:3])
CFG_DIR = f"{HOME_DIR}/.config/rascsi/"
CFG_DIR = f"{HOME_DIR}/.config/rascsi"
AFP_DIR = f"{HOME_DIR}/afpshare"
MAX_FILE_SIZE = getenv("MAX_FILE_SIZE", str(1024 * 1024 * 1024 * 4)) # 4gb

View File

@ -175,12 +175,12 @@
<summary>
{{ file["name"] }}
</summary>
<ul>
<ul style="list-style: none;">
{% for key in file["prop"] %}
<li>{{ key }}: {{ file['prop'][key] }}</li>
{% endfor %}
<form action="/files/download" method="post">
<input name="file" type="hidden" value="{{ CFG_DIR }}/{{ file["name"].replace(base_dir, '') }}.{{ PROPERTIES_SUFFIX }}">
<input name="file" type="hidden" value="{{ CFG_DIR }}/{{ file['name'].replace(base_dir, '') }}.{{ PROPERTIES_SUFFIX }}">
<input type="submit" value="Properties File &#8595;">
</form>
</ul>
@ -192,17 +192,34 @@
<summary>
{{ file["name"] }}
</summary>
<ul>
<ul style="list-style: none;">
{% for member in file["zip_members"] %}
</li>
{% if not member.lower().endswith(PROPERTIES_SUFFIX) %}
<li>
{% if member + "." + PROPERTIES_SUFFIX in file["zip_members"] %}
<details><summary>{{ member }}
<form action="/files/unzip" method="post">
<input name="zip_file" type="hidden" value="{{ file['name'] }}">
<input name="zip_member" type="hidden" value="{{ member }}">
<input type="submit" value="Unzip">
</form>
</summary>
<ul style="list-style: none;">
<li>
{{ member + "." + PROPERTIES_SUFFIX }}
</li>
</ul>
</details>
{% else %}
<label for="zip_member">{{ member }}</label>
<form action="/files/unzip" method="post">
<input name="zip_file" type="hidden" value="{{ file['name'] }}">
<input name="zip_member" type="hidden" value="{{ member }}">
<input type="submit" value="Unzip">
</form>
{% endif %}
</li>
{% endif %}
{% endfor %}
</ul>
</details>
@ -213,7 +230,7 @@
<td style="text-align:center">
<form action="/files/download" method="post">
<input name="file" type="hidden" value="{{ base_dir }}/{{ file['name'] }}">
<input type="submit" value="{{ file["size_mb"] }} MB &#8595;">
<input type="submit" value="{{ file['size_mb'] }} MB &#8595;">
</form>
</td>
<td>