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.
Files changed (25) hide show
  1. {simple_image_hosting-0.1.2/simple_image_hosting.egg-info → simple_image_hosting-0.1.3}/PKG-INFO +1 -1
  2. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/pyproject.toml +1 -1
  3. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/cli.py +1 -2
  4. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/main.py +36 -20
  5. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3/simple_image_hosting.egg-info}/PKG-INFO +1 -1
  6. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/LICENSE +0 -0
  7. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/README.md +0 -0
  8. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/setup.cfg +0 -0
  9. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/__init__.py +0 -0
  10. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/models.py +0 -0
  11. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/utils.py +0 -0
  12. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/index.html +0 -0
  13. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/app.js +0 -0
  14. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/styles.css +0 -0
  15. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/axios.min.js +0 -0
  16. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/element-plus.css +0 -0
  17. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/element-plus.full.min.js +0 -0
  18. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/heic2any.min.js +0 -0
  19. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/load-image.all.min.js +0 -0
  20. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image/web/static/vendor/vue.global.prod.js +0 -0
  21. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/SOURCES.txt +0 -0
  22. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/dependency_links.txt +0 -0
  23. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/entry_points.txt +0 -0
  24. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/requires.txt +0 -0
  25. {simple_image_hosting-0.1.2 → simple_image_hosting-0.1.3}/simple_image_hosting.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple-image-hosting
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Simple image hosting
5
5
  Author: pkufool
6
6
  License: Apache 2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simple-image-hosting"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "Simple image hosting"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
 
7
7
  import uvicorn
8
8
 
9
- from .main import _bootstrap_admin, create_app, hash_password
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
- @app.on_event("startup")
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, db: Session = Depends(get_db)):
550
- db_image = db.query(Image).filter(Image.id == image_uuid).first()
551
- if not db_image:
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
- image_path = image_disk_path(app.state.images_dir, db_image.id, db_image.file_extension)
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
- db_image = db.query(Image).filter(Image.id == image_uuid).first()
589
- if not db_image:
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=86400"},
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(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simple-image-hosting
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Simple image hosting
5
5
  Author: pkufool
6
6
  License: Apache 2.0