feat: add config item for maximum upload file size
This commit is contained in:
parent
aca002d08d
commit
fae93d99e0
15
command.py
15
command.py
@ -199,17 +199,14 @@ def cmd_play(bot, user, text, command, parameter):
|
|||||||
index = int(params[0])
|
index = int(params[0])
|
||||||
else:
|
else:
|
||||||
bot.send_msg(constants.strings('invalid_index', index=parameter), text)
|
bot.send_msg(constants.strings('invalid_index', index=parameter), text)
|
||||||
|
return
|
||||||
|
|
||||||
if len(params) > 1:
|
if len(params) > 1:
|
||||||
_start_at = params[1]
|
try:
|
||||||
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", _start_at, flags=re.IGNORECASE)
|
start_at = util.parse_time(params[1])
|
||||||
if match:
|
except ValueError:
|
||||||
if match[1] is None and match[2] is None:
|
bot.send_msg(constants.strings('bad_parameter', command=command), text)
|
||||||
start_at = float(match[3])
|
return
|
||||||
elif match[2] is None:
|
|
||||||
start_at = float(match[3]) + 60 * int(match[1])
|
|
||||||
else:
|
|
||||||
start_at = float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2])
|
|
||||||
|
|
||||||
if len(var.playlist) > 0:
|
if len(var.playlist) > 0:
|
||||||
if index != -1:
|
if index != -1:
|
||||||
|
@ -104,6 +104,9 @@ access_address = http://127.0.0.1:8181
|
|||||||
|
|
||||||
flask_secret = ChangeThisPassword
|
flask_secret = ChangeThisPassword
|
||||||
|
|
||||||
|
upload_enabled = True
|
||||||
|
maximum_upload_file_size = 30M
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
# Set ffmpeg to True if you want to display DEBUG level log of ffmpeg.
|
# Set ffmpeg to True if you want to display DEBUG level log of ffmpeg.
|
||||||
ffmpeg = False
|
ffmpeg = False
|
||||||
|
@ -140,6 +140,11 @@ port = 64738
|
|||||||
# !! YOU NEED TO CHANGE IT IF auth_method IS 'token'!!
|
# !! YOU NEED TO CHANGE IT IF auth_method IS 'token'!!
|
||||||
# flask_secret = ChangeThisPassword
|
# flask_secret = ChangeThisPassword
|
||||||
|
|
||||||
|
# 'upload_enabled': Enable the upload function of the web interface.
|
||||||
|
# 'maximum_upload_file_size': Unit can be 'B', 'KB', 'MB', 'GB', 'TB'.
|
||||||
|
#upload_enabled = True
|
||||||
|
#maximum_upload_file_size = 30MB
|
||||||
|
|
||||||
# [debug] stores some debug settings.
|
# [debug] stores some debug settings.
|
||||||
[debug]
|
[debug]
|
||||||
# 'ffmpeg': Set ffmpeg to True if you want to display DEBUG level log of ffmpeg.
|
# 'ffmpeg': Set ffmpeg to True if you want to display DEBUG level log of ffmpeg.
|
||||||
|
@ -187,10 +187,13 @@ def index():
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
tags_color_lookup = build_tags_color_lookup()
|
tags_color_lookup = build_tags_color_lookup()
|
||||||
|
max_upload_file_size = util.parse_file_size(var.config.get("webinterface", "max_upload_file_size", fallback="30MB"))
|
||||||
|
|
||||||
return render_template('index.html',
|
return render_template('index.html',
|
||||||
dirs=get_all_dirs(),
|
dirs=get_all_dirs(),
|
||||||
|
upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True),
|
||||||
tags_color_lookup=tags_color_lookup,
|
tags_color_lookup=tags_color_lookup,
|
||||||
|
max_upload_file_size=max_upload_file_size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -614,6 +617,9 @@ def library():
|
|||||||
def upload():
|
def upload():
|
||||||
global log
|
global log
|
||||||
|
|
||||||
|
if not var.config.getboolean("webinterface", "upload_enabled", fallback=True):
|
||||||
|
abort(403)
|
||||||
|
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
if not file:
|
if not file:
|
||||||
abort(400)
|
abort(400)
|
||||||
|
@ -327,7 +327,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if upload_enabled %}
|
||||||
|
|
||||||
<div id="upload" class="container mb-3">
|
<div id="upload" class="container mb-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -375,6 +375,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="container mb-5">
|
<div class="container mb-5">
|
||||||
<div class="card-deck">
|
<div class="card-deck">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@ -543,7 +545,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" id="maxUploadFileSize" value="31457280" />
|
<input type="hidden" id="maxUploadFileSize" value="{{ max_upload_file_size }}" />
|
||||||
|
|
||||||
<script src="static/js/jquery-3.5.1.min.js"></script>
|
<script src="static/js/jquery-3.5.1.min.js"></script>
|
||||||
<script src="static/js/popper.min.js"></script>
|
<script src="static/js/popper.min.js"></script>
|
||||||
|
26
util.py
26
util.py
@ -353,6 +353,32 @@ def get_media_duration(path):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def parse_time(human):
|
||||||
|
match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", human, flags=re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
if match[1] is None and match[2] is None:
|
||||||
|
return float(match[3])
|
||||||
|
elif match[2] is None:
|
||||||
|
return float(match[3]) + 60 * int(match[1])
|
||||||
|
else:
|
||||||
|
return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2])
|
||||||
|
else:
|
||||||
|
raise ValueError("Invalid time string given.")
|
||||||
|
|
||||||
|
|
||||||
|
def parse_file_size(human):
|
||||||
|
units = {"B": 1, "KB": 1024, "MB": 1024*1024, "GB": 1024*1024*1024, "TB": 1024*1024*1024*1024,
|
||||||
|
"K": 1024, "M": 1024*1024, "G": 1024*1024*1024, "T": 1024*1024*1024*1024}
|
||||||
|
match = re.search("(\d+(?:\.\d*)?)\s*([A-Za-z]+)", human, flags=re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
num = float(match[1])
|
||||||
|
unit = match[2].upper()
|
||||||
|
if unit in units:
|
||||||
|
return int(num * units[unit])
|
||||||
|
|
||||||
|
raise ValueError("Invalid file size given.")
|
||||||
|
|
||||||
|
|
||||||
class LoggerIOWrapper(io.TextIOWrapper):
|
class LoggerIOWrapper(io.TextIOWrapper):
|
||||||
def __init__(self, logger: logging.Logger, logging_level, fallback_io_buffer):
|
def __init__(self, logger: logging.Logger, logging_level, fallback_io_buffer):
|
||||||
super().__init__(fallback_io_buffer, write_through=True)
|
super().__init__(fallback_io_buffer, write_through=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user