Implement order preservation for navigation links by serving correct URLs from server instead of client-side JavaScript manipulation
This commit is contained in:
parent
b6f5f31b10
commit
3dde1db8a3
14
main.py
14
main.py
@ -209,7 +209,7 @@ 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 = ""
|
navigation_data: dict, extra_meta: str = "", image_click_url: str = "", play_button: str = "", order: str = "next", delay: int = 5
|
||||||
) -> 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:
|
||||||
@ -220,8 +220,12 @@ def _render_page(
|
|||||||
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="/{next_hash}".format(next_hash=navigation_data["next_hash"]),
|
next_url="/{order}/{delay}/{next_hash}".format(
|
||||||
prev_url="/{prev_hash}".format(prev_hash=navigation_data["prev_hash"]),
|
order=order, delay=delay, next_hash=navigation_data["next_hash"]
|
||||||
|
),
|
||||||
|
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,
|
||||||
@ -240,7 +244,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)
|
return _render_page(navigation_data, play_button=play_button, order="next", delay=5)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/{order}/{delay}/{file_hash}")
|
@app.get("/{order}/{delay}/{file_hash}")
|
||||||
@ -271,7 +275,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)
|
return _render_page(navigation_data, refresh_meta, image_click_url, play_button=pause_button, order=order, 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