Compare commits

..

2 Commits

Author SHA1 Message Date
b772ce8b7e Updated two extensions.
All checks were successful
RUpload build / Build (push) Successful in 1m1s
2024-12-01 10:27:41 +01:00
8b925f852d Code style optimizations 2024-12-01 10:21:20 +01:00
4 changed files with 23 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,20 @@
import aiohttp
from aiohttp import web
import asyncio
import pathlib
from aiohttp import web
MAX_FILE_SIZE = 1024 * 1024 * 50 # 50Mb
UPLOAD_FOLDER_QUOTA = 10 * 1024 * 1024 * 1024 # 10Gb
UPLOAD_URL = "/"
UPLOAD_PATH = "uploads"
class Rupload(web.Application):
def __init__(
self,
upload_url: str = "/uploads/",
upload_path: str = "uploads",
max_file_size: int = 1024 * 1024 * 50,
upload_folder_quota: int = 10 * 1024 * 1024 * 1024,
upload_url: str = UPLOAD_URL,
upload_path: str = UPLOAD_PATH,
max_file_size: int = MAX_FILE_SIZE,
upload_folder_quota: int = UPLOAD_FOLDER_QUOTA,
):
self.upload_path = upload_path.rstrip("/")
self.max_file_size = max_file_size
@ -176,6 +180,8 @@ def get_images(path):
".gif",
".jpeg",
".bmp",
".webp",
".svg",
]:
images.append(image)
return images
@ -247,9 +253,7 @@ async def handle_upload(request: web.Request):
print(f"File {filename} deleted.")
return web.Response(
status=413,
text="File is too large. Maximum file size is {} bytes.".format(
app.max_file_size
),
text=f"File is too large. Maximum file size is {app.max_file_size} bytes.",
)
f.write(chunk)
print(f"File {filename} uploaded successfully.")
@ -281,7 +285,9 @@ async def handle_index(request: web.Request):
message += f'<a href="{url}">'
message += f"{url}</a>"
if not message:
message = "Any file type is allowed thus also binary/executable or source files."
message = (
"Any file type is allowed thus also binary/executable or source files."
)
if message:
message += "<br /><br />"
html_content = html_content.replace("[message]", message)
@ -289,10 +295,10 @@ async def handle_index(request: web.Request):
def create_app(
upload_url: str = "/",
upload_path: str = "upload",
max_file_size: int = 1024 * 1024 * 50,
upload_folder_quota: int = 10 * 1024 * 1024 * 1024,
upload_url: str = UPLOAD_URL,
upload_path: str = UPLOAD_PATH,
max_file_size: int = MAX_FILE_SIZE,
upload_folder_quota: int = UPLOAD_FOLDER_QUOTA,
):
app = Rupload(
upload_url=upload_url,

View File

@ -1,5 +1,7 @@
import argparse
from aiohttp import web
from rupload.app import create_app