feat: Allow deletion of music files to be disabled in the config file. Implement #202.
This commit is contained in:
@ -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]
|
||||||
|
28
interface.py
28
interface.py
@ -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,22 +606,25 @@ def library():
|
|||||||
|
|
||||||
return redirect("./", code=302)
|
return redirect("./", code=302)
|
||||||
elif request.form['action'] == 'delete':
|
elif request.form['action'] == 'delete':
|
||||||
items = dicts_to_items(var.music_db.query_music(condition))
|
if var.config.getboolean("webinterface", "delete_allowed", fallback=True):
|
||||||
for item in items:
|
items = dicts_to_items(var.music_db.query_music(condition))
|
||||||
var.playlist.remove_by_id(item.id)
|
for item in items:
|
||||||
item = var.cache.get_item_by_id(item.id)
|
var.playlist.remove_by_id(item.id)
|
||||||
|
item = var.cache.get_item_by_id(item.id)
|
||||||
|
|
||||||
if os.path.isfile(item.uri()):
|
if os.path.isfile(item.uri()):
|
||||||
log.info("web: delete file " + item.uri())
|
log.info("web: delete file " + item.uri())
|
||||||
os.remove(item.uri())
|
os.remove(item.uri())
|
||||||
|
|
||||||
var.cache.free_and_delete(item.id)
|
var.cache.free_and_delete(item.id)
|
||||||
|
|
||||||
if len(os.listdir(var.music_folder + request.form['dir'])) == 0:
|
if len(os.listdir(var.music_folder + request.form['dir'])) == 0:
|
||||||
os.rmdir(var.music_folder + request.form['dir'])
|
os.rmdir(var.music_folder + request.form['dir'])
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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>
|
||||||
|
Reference in New Issue
Block a user