mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-06-20 18:08:00 +02:00
Added serving of images that are in the DB
This commit is contained in:
parent
d48f566389
commit
9cfc7511b4
@ -1,6 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import Depends, FastAPI, HTTPException, Response, File
|
||||
from fastapi.responses import FileResponse
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from easydiffusion.easydb import crud, models, schemas
|
||||
@ -88,6 +89,18 @@ def init():
|
||||
result.data = base64.encodestring(result.data)
|
||||
return result
|
||||
|
||||
@server_api.get("/image/{image_path:path}")
|
||||
def get_image(image_path: str, db: Session = Depends(get_db)):
|
||||
from easydiffusion.easydb.mappings import Image
|
||||
image_path = image_path.replace("/", "\\")
|
||||
amount = len(db.query(Image).filter(Image.path == image_path).all())
|
||||
print(image_path, amount)
|
||||
if amount > 0:
|
||||
image = db.query(Image).filter(Image.path == image_path).first()
|
||||
return FileResponse(image.path)
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Image not found")
|
||||
|
||||
|
||||
def get_filename_from_url(url):
|
||||
path = urlparse(url).path
|
||||
|
Loading…
x
Reference in New Issue
Block a user