feat: Allow deletion of music files to be disabled in the config file. Implement #202.

This commit is contained in:
Terry Geng
2020-10-24 22:13:20 +08:00
parent a1e37629a5
commit 312599e8b3
4 changed files with 29 additions and 14 deletions

View File

@ -151,8 +151,10 @@ port = 64738
# 'upload_enabled': Enable the upload function of the web interface. # 'upload_enabled': Enable the upload function of the web interface.
# 'maximum_upload_file_size': Unit can be 'B', 'KB', 'MB', 'GB', 'TB'. # 'maximum_upload_file_size': Unit can be 'B', 'KB', 'MB', 'GB', 'TB'.
# 'delete_allowed': Allow users to delete a file from the library(hard disk).
#upload_enabled = True #upload_enabled = True
#max_upload_file_size = 30MB #max_upload_file_size = 30MB
#delete_allowded = True
# [debug] stores some debug settings. # [debug] stores some debug settings.
[debug] [debug]

View File

@ -562,6 +562,7 @@ def library_info():
return jsonify(dict( return jsonify(dict(
dirs=get_all_dirs(), dirs=get_all_dirs(),
upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True), upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True),
delete_allowed=var.config.getboolean("webinterface", "delete_allowed", fallback=True),
tags=tags, tags=tags,
max_upload_file_size=max_upload_file_size max_upload_file_size=max_upload_file_size
)) ))
@ -605,6 +606,7 @@ def library():
return redirect("./", code=302) return redirect("./", code=302)
elif request.form['action'] == 'delete': elif request.form['action'] == 'delete':
if var.config.getboolean("webinterface", "delete_allowed", fallback=True):
items = dicts_to_items(var.music_db.query_music(condition)) items = dicts_to_items(var.music_db.query_music(condition))
for item in items: for item in items:
var.playlist.remove_by_id(item.id) var.playlist.remove_by_id(item.id)
@ -621,6 +623,8 @@ def library():
time.sleep(0.1) time.sleep(0.1)
return redirect("./", code=302) return redirect("./", code=302)
else:
abort(403)
else: else:
page_count = math.ceil(total_count / ITEM_PER_PAGE) page_count = math.ceil(total_count / ITEM_PER_PAGE)

View File

@ -528,6 +528,14 @@ function displayLibraryControls(data){
$("#upload").hide(); $("#upload").hide();
} }
if (data.delete_allowed) {
$("#deleteAllowed").val("true");
$(".library-delete").show();
} else {
$("#uploadDisabled").val("false");
$(".library-delete").hide();
}
let select = $("#filter-dir"); let select = $("#filter-dir");
let dataList = $("#upload-target-dirs"); let dataList = $("#upload-target-dirs");
select.find("option").remove(); select.find("option").remove();

View File

@ -201,6 +201,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<div id="library-group" class="list-group library-group" style="overflow: auto;"> <div id="library-group" class="list-group library-group" style="overflow: auto;">
<input type="hidden" id="deleteAllowed" value="true" />
<div id="library-item-loading" class="list-group-item library-item"> <div id="library-item-loading" class="list-group-item library-item">
<img style="margin: auto; width: 35px;" src="static/image/loading.svg" <img style="margin: auto; width: 35px;" src="static/image/loading.svg"
alt="{{ tr('aria_spinner') }}" /> alt="{{ tr('aria_spinner') }}" />
@ -267,7 +268,7 @@
aria-label="{{ tr('download_song_from_library') }}"> aria-label="{{ tr('download_song_from_library') }}">
<i class="fas fa-download" aria-hidden="true"></i> <i class="fas fa-download" aria-hidden="true"></i>
</button> </button>
<button class="library-item-trash btn btn-danger btn-sm btn-space" type="button" <button class="library-item-trash btn btn-danger btn-sm btn-space library-delete" type="button"
aria-label="{{ tr('remove_song_from_library') }}"> aria-label="{{ tr('remove_song_from_library') }}">
<i class="fas fa-trash-alt"></i> <i class="fas fa-trash-alt"></i>
</button> </button>
@ -296,7 +297,7 @@
<button id="library-download-btn" type="button" class="btn btn-secondary mr-1"> <button id="library-download-btn" type="button" class="btn btn-secondary mr-1">
<i class="fas fa-download" aria-hidden="true"></i>{{ tr('download_all') }} <i class="fas fa-download" aria-hidden="true"></i>{{ tr('download_all') }}
</button> </button>
<button type="button" class="btn btn-danger mr-1" data-toggle="modal" <button type="button" class="btn btn-danger mr-1 library-delete" data-toggle="modal"
data-target="#deleteWarningModal"> data-target="#deleteWarningModal">
<i class="fas fa-trash-alt" aria-hidden="true"></i>{{ tr('delete_all') }} <i class="fas fa-trash-alt" aria-hidden="true"></i>{{ tr('delete_all') }}
</button> </button>