Implemented JeLuF's suggestion & added pagination basics

This commit is contained in:
ManInDark 2023-08-12 16:23:36 +02:00
parent 216ecce506
commit ff75adab7f
No known key found for this signature in database
GPG Key ID: 72EC12A5B2D62779
3 changed files with 9 additions and 6 deletions

View File

@ -100,13 +100,14 @@ def init():
raise HTTPException(status_code=404, detail="Image not found")
@server_api.get("/all_images")
def get_all_images(prompt: str = "", model: str = "", db: Session = Depends(get_db)):
def get_all_images(prompt: str = "", model: str = "", page = 0, db: Session = Depends(get_db)):
from easydiffusion.easydb.mappings import GalleryImage
images = db.query(GalleryImage)
if prompt != "":
images = images.filter(GalleryImage.path.like("%"+prompt+"%"))
if model != "":
images = images.filter(GalleryImage.use_stable_diffusion_model.like("%"+model+"%"))
images = images.offset(page*50).limit(50)
return images.all()
@server_api.get("/single_image")

View File

@ -520,6 +520,7 @@
<div id="gallery-search">
<textarea id="gallery-prompt-search" onkeydown="gallery_keyDown_handler(event)" placeholder="Search for a prompt..."></textarea>
<textarea id="gallery-model-search" onkeydown="gallery_keyDown_handler(event)" placeholder="Search for a model..."></textarea>
<input type="hidden" id="gallery-page" name="page" value="0">
<button class="primaryButton" onclick="refreshGallery()">Refresh</button>
</div>
<div class="gallery">

View File

@ -3110,12 +3110,13 @@ function galleryImage(item) {
function refreshGallery() {
let container = document.getElementById("imagecontainer")
let promptsearchfield = document.getElementById("gallery-prompt-search").value
let promptsearch = promptsearchfield.length > 0 ? "prompt=" + promptsearchfield + "&" : ""
let modelsearchfield = document.getElementById("gallery-model-search").value
let modelsearch = modelsearchfield.length > 0 ? "model=" + modelsearchfield + "&" : ""
params = new URLSearchParams({
prompt: document.getElementById("gallery-prompt-search").value,
model: document.getElementById("gallery-model-search").value,
page: document.getElementById("gallery-page").value
})
container.innerHTML=""
fetch('/all_images?' + promptsearch + modelsearch)
fetch('/all_images?' + params)
.then(response => response.json())
.then(json => {
console.log(json)