simple-image-hosting 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simple_image_hosting-0.1.2/simple_image_hosting.egg-info → simple_image_hosting-0.1.3}/PKG-INFO +1 -1
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/pyproject.toml +1 -1
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/cli.py +1 -2
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/main.py +36 -20
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3/simple_image_hosting.egg-info}/PKG-INFO +1 -1
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/LICENSE +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/README.md +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/setup.cfg +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/__init__.py +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/models.py +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/utils.py +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/index.html +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/app.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/styles.css +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/axios.min.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/element-plus.css +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/element-plus.full.min.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/heic2any.min.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/load-image.all.min.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/vue.global.prod.js +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/SOURCES.txt +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/dependency_links.txt +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/entry_points.txt +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/requires.txt +0 -0
- {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/top_level.txt +0 -0
|
@@ -6,7 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
import uvicorn
|
|
8
8
|
|
|
9
|
-
from .main import
|
|
9
|
+
from .main import create_app, hash_password
|
|
10
10
|
from .models import DEFAULT_COMPRESS_QUALITY, User, create_session_factory
|
|
11
11
|
|
|
12
12
|
|
|
@@ -100,7 +100,6 @@ def run_serve(args: argparse.Namespace) -> None:
|
|
|
100
100
|
database_url=args.database_url,
|
|
101
101
|
base_path=args.base_path,
|
|
102
102
|
)
|
|
103
|
-
_bootstrap_admin(app)
|
|
104
103
|
uvicorn.run(app, host=args.host, port=args.port, reload=args.reload)
|
|
105
104
|
|
|
106
105
|
|
|
@@ -131,6 +131,19 @@ def image_disk_path(images_dir: Path, image_id: str, extension: str) -> Path:
|
|
|
131
131
|
return images_dir / f"{generate_uuid_filename(image_id)}.{extension}"
|
|
132
132
|
|
|
133
133
|
|
|
134
|
+
def find_image_file(images_dir: Path, image_id: str) -> Optional[Path]:
|
|
135
|
+
"""Locate an image on disk by scanning the directory, skipping the database."""
|
|
136
|
+
base = images_dir / generate_uuid_filename(image_id)
|
|
137
|
+
parent = base.parent
|
|
138
|
+
if not parent.is_dir():
|
|
139
|
+
return None
|
|
140
|
+
stem = base.name
|
|
141
|
+
for entry in parent.iterdir():
|
|
142
|
+
if entry.is_file() and entry.stem == stem and entry.suffix.lstrip(".") in ALLOWED_EXTENSIONS:
|
|
143
|
+
return entry
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
|
|
134
147
|
def normalize_path_prefix(value: Optional[str]) -> str:
|
|
135
148
|
if not value:
|
|
136
149
|
return ""
|
|
@@ -286,10 +299,7 @@ def create_app(
|
|
|
286
299
|
db_path=None if app.state.database_url else app.state.db_path,
|
|
287
300
|
)
|
|
288
301
|
|
|
289
|
-
|
|
290
|
-
def _startup_bootstrap_admin() -> None:
|
|
291
|
-
_bootstrap_admin(app)
|
|
292
|
-
|
|
302
|
+
_bootstrap_admin(app)
|
|
293
303
|
_register_routes(app)
|
|
294
304
|
if not resolved_base_path:
|
|
295
305
|
return app
|
|
@@ -546,16 +556,21 @@ def _register_routes(app: FastAPI) -> None:
|
|
|
546
556
|
|
|
547
557
|
|
|
548
558
|
@app.get("/image/{image_uuid}", response_class=FileResponse)
|
|
549
|
-
def get_image(image_uuid: str
|
|
550
|
-
|
|
551
|
-
if not
|
|
559
|
+
def get_image(image_uuid: str):
|
|
560
|
+
image_path = find_image_file(app.state.images_dir, image_uuid)
|
|
561
|
+
if not image_path:
|
|
552
562
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image not found")
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
if not image_path.exists():
|
|
556
|
-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image file not found")
|
|
557
|
-
media_type = IMAGE_MEDIA_TYPES.get(normalize_image_extension(db_image.file_extension), "application/octet-stream")
|
|
563
|
+
ext = normalize_image_extension(image_path.suffix.lstrip("."))
|
|
564
|
+
media_type = IMAGE_MEDIA_TYPES.get(ext, "application/octet-stream")
|
|
558
565
|
return FileResponse(path=image_path, media_type=media_type)
|
|
566
|
+
# db_image = db.query(Image).filter(Image.id == image_uuid).first()
|
|
567
|
+
# if not db_image:
|
|
568
|
+
# raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image not found")
|
|
569
|
+
# image_path = image_disk_path(app.state.images_dir, db_image.id, db_image.file_extension)
|
|
570
|
+
# if not image_path.exists():
|
|
571
|
+
# raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image file not found")
|
|
572
|
+
# media_type = IMAGE_MEDIA_TYPES.get(normalize_image_extension(db_image.file_extension), "application/octet-stream")
|
|
573
|
+
# return FileResponse(path=image_path, media_type=media_type)
|
|
559
574
|
|
|
560
575
|
|
|
561
576
|
@app.get("/download/{image_uuid}")
|
|
@@ -583,16 +598,11 @@ def _register_routes(app: FastAPI) -> None:
|
|
|
583
598
|
image_uuid: str,
|
|
584
599
|
size: int = Query(default=160, ge=48, le=512),
|
|
585
600
|
quality: int = Query(default=75, ge=40, le=95),
|
|
586
|
-
db: Session = Depends(get_db),
|
|
587
601
|
):
|
|
588
|
-
|
|
589
|
-
if not
|
|
602
|
+
image_path = find_image_file(app.state.images_dir, image_uuid)
|
|
603
|
+
if not image_path:
|
|
590
604
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image not found")
|
|
591
605
|
|
|
592
|
-
image_path = image_disk_path(app.state.images_dir, db_image.id, db_image.file_extension)
|
|
593
|
-
if not image_path.exists():
|
|
594
|
-
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image file not found")
|
|
595
|
-
|
|
596
606
|
try:
|
|
597
607
|
with open(image_path, "rb") as source_file:
|
|
598
608
|
image_data = source_file.read()
|
|
@@ -603,8 +613,14 @@ def _register_routes(app: FastAPI) -> None:
|
|
|
603
613
|
return Response(
|
|
604
614
|
content=thumbnail_data,
|
|
605
615
|
media_type="image/jpeg",
|
|
606
|
-
headers={"Cache-Control": "public, max-age=
|
|
616
|
+
headers={"Cache-Control": "public, max-age=2592000"},
|
|
607
617
|
)
|
|
618
|
+
# db_image = db.query(Image).filter(Image.id == image_uuid).first()
|
|
619
|
+
# if not db_image:
|
|
620
|
+
# raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image not found")
|
|
621
|
+
# image_path = image_disk_path(app.state.images_dir, db_image.id, db_image.file_extension)
|
|
622
|
+
# if not image_path.exists():
|
|
623
|
+
# raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Image file not found")
|
|
608
624
|
|
|
609
625
|
|
|
610
626
|
def list_user_images(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/styles.css
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|