Compare commits
65
Commits
main
..
b772ce8b7e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b772ce8b7e | ||
|
|
8b925f852d | ||
|
|
600edca8cd | ||
|
|
368e99da32 | ||
|
|
e4331976d9 | ||
|
|
2c1f519da7 | ||
|
|
96fd9fd4a7 | ||
|
|
96e154f9a3 | ||
|
|
b7daa3ad0f | ||
|
|
ed1090c773 | ||
|
|
9f20c461e4 | ||
|
|
a4f9bd7727 | ||
|
|
54f58cbfc5 | ||
|
|
3b09f661d6 | ||
|
|
401f33411c | ||
|
|
34f3adc00c | ||
|
|
795b12f3c6 | ||
|
|
b498f198cd | ||
|
|
46be4e34bf | ||
|
|
f3a7cebbbe | ||
|
|
5be04344cc | ||
|
|
f47e26143c | ||
|
|
719fa93abc | ||
|
|
7a42012129 | ||
|
|
5570265eaa | ||
|
|
d86b8ac5a0 | ||
|
|
df141e57ca | ||
|
|
c91dc264f5 | ||
|
|
52e1149f74 | ||
|
|
30d7ed5118 | ||
|
|
c6386eb794 | ||
|
|
bad8e011ce | ||
|
|
78874deb56 | ||
|
|
0b958e3800 | ||
|
|
49f69cb688 | ||
|
|
9600f64eb9 | ||
|
|
ec489ab30f | ||
|
|
304d163464 | ||
|
|
a51c3739c9 | ||
|
|
a7aabcd36f | ||
|
|
03c8fb02a7 | ||
|
|
3ee5232f49 | ||
|
|
fb2a733f4c | ||
|
|
85fe10b7cd | ||
|
|
235cdc628b | ||
|
|
8bfa141a85 | ||
|
|
36ef6d7e4d | ||
|
|
9209e43b8b | ||
|
|
28300cb055 | ||
|
|
a875616522 | ||
|
|
37b9907334 | ||
|
|
d79664fdc5 | ||
|
|
ad1243afb7 | ||
|
|
d6d31a0500 | ||
|
|
983d4d668f | ||
|
|
2f6ecfe06d | ||
|
|
254cb6004b | ||
|
|
e0fcf53788 | ||
|
|
456e3c0823 | ||
|
|
5f518c8df7 | ||
|
|
15869d6537 | ||
|
|
3bd46cb640 | ||
|
|
1ed30e0d80 | ||
|
|
67d91a42e5 | ||
|
|
3e72ecab20 |
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -16,7 +16,6 @@ python_requires = >=3.7
|
|||||||
install_requires =
|
install_requires =
|
||||||
aiohttp==3.10.10
|
aiohttp==3.10.10
|
||||||
dataset==1.6.2
|
dataset==1.6.2
|
||||||
pillow
|
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where = src
|
where = src
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Metadata-Version: 2.4
|
Metadata-Version: 2.1
|
||||||
Name: rupload
|
Name: rupload
|
||||||
Version: 1.3.37
|
Version: 1.3.37
|
||||||
Summary: upload tool
|
Summary: upload tool
|
||||||
@@ -9,7 +9,6 @@ Requires-Python: >=3.7
|
|||||||
Description-Content-Type: text/markdown
|
Description-Content-Type: text/markdown
|
||||||
Requires-Dist: aiohttp==3.10.10
|
Requires-Dist: aiohttp==3.10.10
|
||||||
Requires-Dist: dataset==1.6.2
|
Requires-Dist: dataset==1.6.2
|
||||||
Requires-Dist: pillow
|
|
||||||
|
|
||||||
# RUpload
|
# RUpload
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
aiohttp==3.10.10
|
aiohttp==3.10.10
|
||||||
dataset==1.6.2
|
dataset==1.6.2
|
||||||
pillow
|
|
||||||
|
|||||||
+4
-27
@@ -2,7 +2,7 @@ import pathlib
|
|||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
MAX_FILE_SIZE = 1024 * 1024 * 300 # 50Mb
|
MAX_FILE_SIZE = 1024 * 1024 * 50 # 50Mb
|
||||||
UPLOAD_FOLDER_QUOTA = 10 * 1024 * 1024 * 1024 # 10Gb
|
UPLOAD_FOLDER_QUOTA = 10 * 1024 * 1024 * 1024 # 10Gb
|
||||||
UPLOAD_URL = "/"
|
UPLOAD_URL = "/"
|
||||||
UPLOAD_PATH = "uploads"
|
UPLOAD_PATH = "uploads"
|
||||||
@@ -174,7 +174,7 @@ def format_size(size):
|
|||||||
def get_images(path):
|
def get_images(path):
|
||||||
images = []
|
images = []
|
||||||
for image in pathlib.Path(path).iterdir():
|
for image in pathlib.Path(path).iterdir():
|
||||||
if image.is_file() and image.suffix.lower() in [
|
if image.is_file() and image.suffix in [
|
||||||
".png",
|
".png",
|
||||||
".jpg",
|
".jpg",
|
||||||
".gif",
|
".gif",
|
||||||
@@ -200,8 +200,7 @@ def create_images_html(url, image_paths):
|
|||||||
images_html = ""
|
images_html = ""
|
||||||
for image_path in image_paths:
|
for image_path in image_paths:
|
||||||
path = url.rstrip("/") + "/" + image_path.name
|
path = url.rstrip("/") + "/" + image_path.name
|
||||||
thumbnail_path = "/thumbnail/" + url.strip("/") + "/" + image_path.name
|
images_html += f'<a href="{path}"><img class="thumbnail" src="{path}" alt="{image_path.name}" /></a>\n'
|
||||||
images_html += f'<a href="{path}"><img class="thumbnail" src="{thumbnail_path}" alt="{image_path.name}" /></a>\n'
|
|
||||||
return images_html
|
return images_html
|
||||||
|
|
||||||
|
|
||||||
@@ -268,27 +267,6 @@ async def handle_upload(request: web.Request):
|
|||||||
return web.Response(status=400, text="No file uploaded.")
|
return web.Response(status=400, text="No file uploaded.")
|
||||||
|
|
||||||
|
|
||||||
async def handle_thumbnail(request: web.Request):
|
|
||||||
path = request.match_info["path"]
|
|
||||||
|
|
||||||
safe_path = pathlib.Path(request.app.upload_path).joinpath(pathlib.Path(path).name)
|
|
||||||
|
|
||||||
if not safe_path.is_file():
|
|
||||||
return web.Response(status=400, text="Invalid file type.")
|
|
||||||
|
|
||||||
|
|
||||||
thumbnail_path = pathlib.Path(request.app.upload_path).joinpath(".thumbnail").joinpath(pathlib.Path(safe_path).name)
|
|
||||||
if not thumbnail_path.parent.exists():
|
|
||||||
thumbnail_path.parent.mkdir(exist_ok=True,parents=False)
|
|
||||||
|
|
||||||
if not thumbnail_path.exists():
|
|
||||||
from PIL import Image
|
|
||||||
image = Image.open(safe_path)
|
|
||||||
image.thumbnail((200, 200))
|
|
||||||
image.save(thumbnail_path)
|
|
||||||
|
|
||||||
return web.FileResponse(thumbnail_path)
|
|
||||||
|
|
||||||
async def handle_index(request: web.Request):
|
async def handle_index(request: web.Request):
|
||||||
image_paths = get_images(request.app.upload_path)
|
image_paths = get_images(request.app.upload_path)
|
||||||
images_html = create_images_html(
|
images_html = create_images_html(
|
||||||
@@ -330,11 +308,10 @@ def create_app(
|
|||||||
)
|
)
|
||||||
pathlib.Path(upload_path).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(upload_path).mkdir(parents=True, exist_ok=True)
|
||||||
app.add_routes(
|
app.add_routes(
|
||||||
[
|
[
|
||||||
web.get("/", handle_index),
|
web.get("/", handle_index),
|
||||||
web.post("/upload", handle_upload),
|
web.post("/upload", handle_upload),
|
||||||
web.static("/", upload_path),
|
web.static("/", upload_path),
|
||||||
web.get("/thumbnail/{path:.*}", handle_thumbnail),
|
|
||||||
web.static("/uploads", upload_path),
|
web.static("/uploads", upload_path),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user