Fix order preservation: navigation keys now properly maintain current mode (next/random/browse) instead of forcing timer mode
This commit is contained in:
parent
3dde1db8a3
commit
4cf492c37a
29
main.py
29
main.py
@ -209,23 +209,34 @@ def _get_navigation_data(file_hash: str):
|
|||||||
|
|
||||||
|
|
||||||
def _render_page(
|
def _render_page(
|
||||||
navigation_data: dict, extra_meta: str = "", image_click_url: str = "", play_button: str = "", order: str = "next", delay: int = 5
|
navigation_data: dict, extra_meta: str = "", image_click_url: str = "", play_button: str = "", current_order: str | None = None, current_delay: int | None = None
|
||||||
) -> HTMLResponse:
|
) -> HTMLResponse:
|
||||||
"""Render the frontend page with navigation data"""
|
"""Render the frontend page with navigation data"""
|
||||||
with open("frontend.html", "r") as f:
|
with open("frontend.html", "r") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
template = string.Template(content)
|
template = string.Template(content)
|
||||||
|
|
||||||
|
# Generate navigation URLs based on current mode
|
||||||
|
if current_order is not None:
|
||||||
|
# Timer mode: preserve current order and delay
|
||||||
|
next_url = "/{order}/{delay}/{next_hash}".format(
|
||||||
|
order=current_order, delay=current_delay, next_hash=navigation_data["next_hash"]
|
||||||
|
)
|
||||||
|
prev_url = "/{order}/{delay}/{prev_hash}".format(
|
||||||
|
order=current_order, delay=current_delay, prev_hash=navigation_data["prev_hash"]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Browse mode: generate browse mode URLs
|
||||||
|
next_url = "/{next_hash}".format(next_hash=navigation_data["next_hash"])
|
||||||
|
prev_url = "/{prev_hash}".format(prev_hash=navigation_data["prev_hash"])
|
||||||
|
|
||||||
content = template.substitute(
|
content = template.substitute(
|
||||||
img_url="/api/{file_hash}/data".format(file_hash=navigation_data["file_hash"]),
|
img_url="/api/{file_hash}/data".format(file_hash=navigation_data["file_hash"]),
|
||||||
image_click_url=image_click_url
|
image_click_url=image_click_url
|
||||||
or "/{next_random_hash}".format(next_random_hash=navigation_data["next_random_hash"]),
|
or "/{next_random_hash}".format(next_random_hash=navigation_data["next_random_hash"]),
|
||||||
next_url="/{order}/{delay}/{next_hash}".format(
|
next_url=next_url,
|
||||||
order=order, delay=delay, next_hash=navigation_data["next_hash"]
|
prev_url=prev_url,
|
||||||
),
|
|
||||||
prev_url="/{order}/{delay}/{prev_hash}".format(
|
|
||||||
order=order, delay=delay, prev_hash=navigation_data["prev_hash"]
|
|
||||||
),
|
|
||||||
filename=navigation_data["filename"],
|
filename=navigation_data["filename"],
|
||||||
extra_meta=extra_meta,
|
extra_meta=extra_meta,
|
||||||
play_button=play_button,
|
play_button=play_button,
|
||||||
@ -244,7 +255,7 @@ async def hash_page(file_hash: str, username: str = Depends(get_current_username
|
|||||||
play_button = '<a href="/next/5/{file_hash}" class="play-btn" title="Play next 5">⏵</a>'.format(
|
play_button = '<a href="/next/5/{file_hash}" class="play-btn" title="Play next 5">⏵</a>'.format(
|
||||||
file_hash=file_hash
|
file_hash=file_hash
|
||||||
)
|
)
|
||||||
return _render_page(navigation_data, play_button=play_button, order="next", delay=5)
|
return _render_page(navigation_data, play_button=play_button, current_order=None, current_delay=None)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/{order}/{delay}/{file_hash}")
|
@app.get("/{order}/{delay}/{file_hash}")
|
||||||
@ -275,7 +286,7 @@ async def hash_page_with_refresh(order: str, delay: int, file_hash: str, usernam
|
|||||||
file_hash=file_hash
|
file_hash=file_hash
|
||||||
)
|
)
|
||||||
|
|
||||||
return _render_page(navigation_data, refresh_meta, image_click_url, play_button=pause_button, order=order, delay=delay)
|
return _render_page(navigation_data, refresh_meta, image_click_url, play_button=pause_button, current_order=order, current_delay=delay)
|
||||||
|
|
||||||
|
|
||||||
def _find_indexer_for_hash(file_hash: str):
|
def _find_indexer_for_hash(file_hash: str):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user