mirror of
https://github.com/akuker/RASCSI.git
synced 2025-02-20 00:29:18 +00:00
Improve error handling of unzip method; clean up unused code
This commit is contained in:
parent
b4562e23cc
commit
ff13408bc9
@ -63,11 +63,14 @@ def delete_file(file_name):
|
|||||||
|
|
||||||
|
|
||||||
def unzip_file(file_name):
|
def unzip_file(file_name):
|
||||||
import zipfile
|
from zipfile import ZipFile, is_zipfile
|
||||||
|
|
||||||
with zipfile.ZipFile(base_dir + file_name, "r") as zip_ref:
|
if is_zipfile(file_name):
|
||||||
zip_ref.extractall(base_dir)
|
with zipfile.ZipFile(base_dir + file_name, "r") as zip_ref:
|
||||||
return True
|
zip_ref.extractall(base_dir)
|
||||||
|
return {"status": True, "msg": f"{file_name} unzipped"}
|
||||||
|
else:
|
||||||
|
return {"status": False, "msg": f"{file_name} is not a zip file"}
|
||||||
|
|
||||||
|
|
||||||
def download_file_to_iso(scsi_id, url):
|
def download_file_to_iso(scsi_id, url):
|
||||||
|
@ -12,4 +12,3 @@ zope.event==4.5.0
|
|||||||
zope.interface==5.1.2
|
zope.interface==5.1.2
|
||||||
protobuf==3.17.3
|
protobuf==3.17.3
|
||||||
pydrop==0.0.6
|
pydrop==0.0.6
|
||||||
zipfile
|
|
@ -91,10 +91,10 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for file in files %}
|
{% for file in files %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{file["name"].replace(base_dir, '')}}</td>
|
<td>{{file["name"]}}</td>
|
||||||
<td style="text-align:center">
|
<td style="text-align:center">
|
||||||
<form action="/files/download" method="post">
|
<form action="/files/download" method="post">
|
||||||
<input type="hidden" name="image" value="{{file["name"].replace(base_dir, '')}}">
|
<input type="hidden" name="image" value="{{file["name"]}}">
|
||||||
<input type="submit" value="{{file["size_mb"]}} MB ↓" />
|
<input type="submit" value="{{file["size_mb"]}} MB ↓" />
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
@ -107,20 +107,12 @@
|
|||||||
<option value="{{id}}">{{id}}</option>
|
<option value="{{id}}">{{id}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
{% if not file["name"].lower().endswith(archive_file_suffix) %}
|
|
||||||
<input type="submit" value="Attach" />
|
<input type="submit" value="Attach" />
|
||||||
{% endif %}
|
|
||||||
</form>
|
</form>
|
||||||
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file?')">
|
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file?')">
|
||||||
<input type="hidden" name="image" value="{{file["name"].replace(base_dir, '')}}">
|
<input type="hidden" name="image" value="{{file["name"]}}">
|
||||||
<input type="submit" value="Delete" />
|
<input type="submit" value="Delete" />
|
||||||
</form>
|
</form>
|
||||||
{% if file["name"].lower().endswith(archive_file_suffix) %}
|
|
||||||
<form action="/files/unzip" method="post">
|
|
||||||
<input type="hidden" name="image" value="{{file["name"].replace(base_dir, '')}}">
|
|
||||||
<input type="submit" value="Unzip" />
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -527,11 +527,7 @@ def upload_file():
|
|||||||
log.debug(f"Chunk {current_chunk + 1} of {total_chunks} "
|
log.debug(f"Chunk {current_chunk + 1} of {total_chunks} "
|
||||||
f"for file {file.filename} completed.")
|
f"for file {file.filename} completed.")
|
||||||
|
|
||||||
from zipfile import ZipFile, is_zipfile
|
if unzip_file(filename):
|
||||||
if is_zipfile(save_path):
|
|
||||||
with ZipFile(save_path, 'r') as z:
|
|
||||||
z.extractall(path=app.config["UPLOAD_FOLDER"])
|
|
||||||
delete_file(filename)
|
|
||||||
return make_response(("File upload and unzip successful!", 200))
|
return make_response(("File upload and unzip successful!", 200))
|
||||||
else:
|
else:
|
||||||
return make_response(("File upload successful!", 200))
|
return make_response(("File upload successful!", 200))
|
||||||
@ -594,19 +590,6 @@ def delete():
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/files/unzip", methods=["POST"])
|
|
||||||
def unzip():
|
|
||||||
image = request.form.get("image")
|
|
||||||
|
|
||||||
if unzip_file(image):
|
|
||||||
flash("Unzipped file " + image)
|
|
||||||
return redirect(url_for("index"))
|
|
||||||
else:
|
|
||||||
flash("Failed to unzip " + image, "error")
|
|
||||||
return redirect(url_for("index"))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.secret_key = "rascsi_is_awesome_insecure_secret_key"
|
app.secret_key = "rascsi_is_awesome_insecure_secret_key"
|
||||||
app.config["SESSION_TYPE"] = "filesystem"
|
app.config["SESSION_TYPE"] = "filesystem"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user