bookmarklet: use dynamic host and scheme from request headers
This commit is contained in:
parent
96603da142
commit
af6ad6d391
3 changed files with 13 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ from ._helpers import _respond, _csrf_field, _get_bookmark_token
|
|||
from .subscriptions import _count_shared_pages
|
||||
|
||||
|
||||
def handle_style_form(msg=""):
|
||||
def handle_style_form(msg="", gateway_host="", scheme="http"):
|
||||
template = get_setting("custom_template") or DEFAULT_TEMPLATE
|
||||
name = get_site_name()
|
||||
sharing = get_setting("sharing_enabled", "0")
|
||||
|
|
@ -135,7 +135,7 @@ def handle_style_form(msg=""):
|
|||
f"</form>"
|
||||
f"<h2>bookmarklet</h2>"
|
||||
f"<p>Drag this link to your bookmarks bar. Click it on any page to index it instantly.</p>"
|
||||
f'<p><a href="javascript:void(fetch(\'http://localhost:8080/bookmark?url=\'+encodeURIComponent(location.href)+\'&token={_get_bookmark_token()}\').then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
|
||||
f'<p><a href="javascript:void(fetch(\'{esc(scheme)}://{esc(gateway_host or "localhost:8080")}/bookmark?url=\'+encodeURIComponent(location.href)+\'&token={_get_bookmark_token()}\').then(r=>r.text()).then(t=>alert(t)).catch(()=>alert(\'tinyweb not running\')))">+ save to {esc(name)}</a></p>'
|
||||
f"<h2>reset</h2>"
|
||||
f'<form method="post" action="/style/reset" '
|
||||
f'onsubmit="return confirm(\'Reset the template to default? Your custom template will be lost.\')">'
|
||||
|
|
@ -153,7 +153,7 @@ def handle_style_form(msg=""):
|
|||
)
|
||||
|
||||
|
||||
def handle_style_submit(body):
|
||||
def handle_style_submit(body, gateway_host="", scheme="http"):
|
||||
template = body.get("template", [""])[0].replace("\r\n", "\n").replace("\r", "\n")
|
||||
name = body.get("site_name", ["tinyweb"])[0].strip()
|
||||
sharing = "1" if body.get("sharing_enabled") else "0"
|
||||
|
|
@ -192,7 +192,8 @@ def handle_style_submit(body):
|
|||
from handlers import forum_plugin
|
||||
if forum_enabled == "1" and forum_plugin is None:
|
||||
return handle_style_form(
|
||||
"Forum plugin not installed. Run: pip install tinyweb-forum"
|
||||
"Forum plugin not installed. Run: pip install tinyweb-forum",
|
||||
gateway_host=gateway_host, scheme=scheme,
|
||||
)
|
||||
if forum_enabled == "1":
|
||||
forum_plugin.enable()
|
||||
|
|
@ -208,7 +209,8 @@ def handle_style_submit(body):
|
|||
pass
|
||||
set_setting("forum_enabled", forum_enabled)
|
||||
templates_mod.FORUM_ENABLED = (forum_enabled == "1")
|
||||
return handle_style_form("Saved. Restart TinyWeb for mesh network changes to take effect.")
|
||||
return handle_style_form("Saved. Restart TinyWeb for mesh network changes to take effect.",
|
||||
gateway_host=gateway_host, scheme=scheme)
|
||||
|
||||
|
||||
def handle_about():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue