added filesize config
This commit is contained in:
parent
ec4bb32fc1
commit
2885764c51
3
htt.conf
3
htt.conf
@ -1,4 +1,5 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
cleartime = 10
|
cleartime = 10
|
||||||
domain = localhost:8170
|
domain = localhost:8170
|
||||||
port = 8170
|
port = 8170
|
||||||
|
filesizemb = 200
|
11
start.py
11
start.py
@ -10,7 +10,8 @@ config.read('htt.conf')
|
|||||||
domain = str(config['DEFAULT']['domain'])
|
domain = str(config['DEFAULT']['domain'])
|
||||||
MAINTENANCE_INTERVAL_MINUTES = float(config['DEFAULT']['cleartime'])
|
MAINTENANCE_INTERVAL_MINUTES = float(config['DEFAULT']['cleartime'])
|
||||||
port = int(config['DEFAULT']['port'])
|
port = int(config['DEFAULT']['port'])
|
||||||
|
maxfilesize = int(config['DEFAULT']['filesizemb'])
|
||||||
|
maxfilesize = maxfilesize * 10 * 1024 * 1024
|
||||||
def popup(mesage,link="",file="popup.html"):
|
def popup(mesage,link="",file="popup.html"):
|
||||||
out = load(file)
|
out = load(file)
|
||||||
out = out.replace("<popuphere>",str(mesage))
|
out = out.replace("<popuphere>",str(mesage))
|
||||||
@ -67,6 +68,14 @@ class FileUploadApp:
|
|||||||
def upload(self, file):
|
def upload(self, file):
|
||||||
clear_cache()
|
clear_cache()
|
||||||
try:
|
try:
|
||||||
|
# test file size
|
||||||
|
file_size = 0
|
||||||
|
file.file.seek(0, os.SEEK_END) # Seek to the end of the file
|
||||||
|
file_size = file.file.tell() # Get the current position (file size)
|
||||||
|
file.file.seek(0)
|
||||||
|
if file_size > MAX_FILE_SIZE:
|
||||||
|
return popup(f"This file is to large, max size is is {maxfilesize}")
|
||||||
|
|
||||||
# Find the lowest unused number as the identifier
|
# Find the lowest unused number as the identifier
|
||||||
existing_ids = set(int(folder) for folder in os.listdir(self.upload_dir) if folder.isdigit())
|
existing_ids = set(int(folder) for folder in os.listdir(self.upload_dir) if folder.isdigit())
|
||||||
ident = 1 # Start checking from 1
|
ident = 1 # Start checking from 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user