mirror of
https://github.com/akuker/RASCSI.git
synced 2024-09-11 18:56:58 +00:00
Rename image file in web interface (#521)
* Introduce rename_image method * Introduce rename endpoint * Better prompt text * Fix bug * Make renaming properties files work * Have current file name prefilled * Add login_required decorator * Remove unused code
This commit is contained in:
parent
986116f8d9
commit
0eb9e50d18
@ -146,6 +146,24 @@ def delete_image(file_name):
|
|||||||
return {"status": result.status, "msg": result.msg}
|
return {"status": result.status, "msg": result.msg}
|
||||||
|
|
||||||
|
|
||||||
|
def rename_image(file_name, new_file_name):
|
||||||
|
"""
|
||||||
|
Takes (str) file_name, (str) new_file_name
|
||||||
|
Sends a RENAME_IMAGE command to the server
|
||||||
|
Returns (dict) with (bool) status and (str) msg
|
||||||
|
"""
|
||||||
|
command = proto.PbCommand()
|
||||||
|
command.operation = proto.PbOperation.RENAME_IMAGE
|
||||||
|
|
||||||
|
command.params["from"] = file_name
|
||||||
|
command.params["to"] = new_file_name
|
||||||
|
|
||||||
|
data = send_pb_command(command.SerializeToString())
|
||||||
|
result = proto.PbResult()
|
||||||
|
result.ParseFromString(data)
|
||||||
|
return {"status": result.status, "msg": result.msg}
|
||||||
|
|
||||||
|
|
||||||
def delete_file(file_path):
|
def delete_file(file_path):
|
||||||
"""
|
"""
|
||||||
Takes (str) file_path with the full path to the file to delete
|
Takes (str) file_path with the full path to the file to delete
|
||||||
|
@ -277,8 +277,13 @@
|
|||||||
<input type="submit" value="Attach">
|
<input type="submit" value="Attach">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
<form action="/files/rename" method="post" onsubmit="var new_file_name = prompt('Enter new file name for \'{{ file["name"] }}\'', '{{ file['name'] }}'); if (new_file_name === null) event.preventDefault(); document.getElementById('new_file_name_{{ loop.index }}').value = new_file_name;">
|
||||||
|
<input name="file_name" type="hidden" value="{{ file['name'] }}">
|
||||||
|
<input name="new_file_name" id="new_file_name_{{ loop.index }}" type="hidden" value="">
|
||||||
|
<input type="submit" value="Rename">
|
||||||
|
</form>
|
||||||
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file \'{{ file["name"] }}\'?')">
|
<form action="/files/delete" method="post" onsubmit="return confirm('Delete file \'{{ file["name"] }}\'?')">
|
||||||
<input name="image" type="hidden" value="{{ file['name'] }}">
|
<input name="file_name" type="hidden" value="{{ file['name'] }}">
|
||||||
<input type="submit" value="Delete">
|
<input type="submit" value="Delete">
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -26,7 +26,9 @@ from file_cmds import (
|
|||||||
create_new_image,
|
create_new_image,
|
||||||
download_file_to_iso,
|
download_file_to_iso,
|
||||||
delete_image,
|
delete_image,
|
||||||
|
rename_image,
|
||||||
delete_file,
|
delete_file,
|
||||||
|
rename_file,
|
||||||
unzip_file,
|
unzip_file,
|
||||||
download_to_dir,
|
download_to_dir,
|
||||||
write_config,
|
write_config,
|
||||||
@ -869,7 +871,7 @@ def delete():
|
|||||||
"""
|
"""
|
||||||
Deletes a specified file in the images dir
|
Deletes a specified file in the images dir
|
||||||
"""
|
"""
|
||||||
file_name = request.form.get("image")
|
file_name = request.form.get("file_name")
|
||||||
|
|
||||||
process = delete_image(file_name)
|
process = delete_image(file_name)
|
||||||
if process["status"]:
|
if process["status"]:
|
||||||
@ -892,6 +894,37 @@ def delete():
|
|||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
|
@APP.route("/files/rename", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def rename():
|
||||||
|
"""
|
||||||
|
Renames a specified file in the images dir
|
||||||
|
"""
|
||||||
|
file_name = request.form.get("file_name")
|
||||||
|
new_file_name = request.form.get("new_file_name")
|
||||||
|
|
||||||
|
process = rename_image(file_name, new_file_name)
|
||||||
|
if process["status"]:
|
||||||
|
flash(f"Image file renamed to: {new_file_name}")
|
||||||
|
else:
|
||||||
|
flash(process["msg"], "error")
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
# Rename the drive properties file, if it exists
|
||||||
|
prop_file_path = f"{CFG_DIR}/{file_name}.{PROPERTIES_SUFFIX}"
|
||||||
|
new_prop_file_path = f"{CFG_DIR}/{new_file_name}.{PROPERTIES_SUFFIX}"
|
||||||
|
if Path(prop_file_path).is_file():
|
||||||
|
process = rename_file(prop_file_path, new_prop_file_path)
|
||||||
|
if process["status"]:
|
||||||
|
flash(process["msg"])
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
flash(process["msg"], "error")
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
|
||||||
@APP.route("/files/unzip", methods=["POST"])
|
@APP.route("/files/unzip", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def unzip():
|
def unzip():
|
||||||
|
Loading…
Reference in New Issue
Block a user