fix(search): the live-search tooltip says what a search costs

It always said a live search spends the shared API quota, while the default source (the website's
own endpoint, scrape) spends none — the owner avoided a free search because of it. /api/me now names
the running search_source, and the tooltip names the cost under it: none for scrape (the enrich step
costs a unit or two), 100 units a page for the official API.
This commit is contained in:
2026-10-04 17:53:19 +02:00
parent ce8ccfc3c0
commit 0e077b84c8
8 changed files with 85 additions and 3 deletions
+3
View File
@@ -148,6 +148,9 @@ def get_me(
"google_enabled": google_enabled(db),
# Whether the optional Plex module is enabled (UI shows the Plex feed source when so).
"plex_enabled": sysconfig.get_bool(db, "plex_enabled"),
# Which live-search source runs, so the search button can say what a search costs: "scrape"
# spends no API quota, "api" spends 100 units a page.
"search_source": sysconfig.get_str(db, "search_source"),
"can_read": has_read_scope(user),
"can_write": has_write_scope(user),
"pending_invites": pending_invites,
+26
View File
@@ -0,0 +1,26 @@
"""`/api/me` names the live-search source, so the search button's tooltip can say what a search costs
under the source that actually runs (the default website source spends no API quota)."""
from app import sysconfig
_PW = "correct horse battery"
def _me(client):
r = client.get("/api/me")
assert r.status_code == 200 and r.json()["authenticated"] is True
return r.json()
def test_me_names_the_running_search_source(client, db, make_user):
# /api/me resolves its user through optional_current_user, which the as_user override does not
# cover — so sign in for real (see test_me_email_flag).
user = make_user(password=_PW)
login = client.post("/auth/password-login", json={"email": user.email, "password": _PW})
assert login.status_code == 200
assert _me(client)["search_source"] == "scrape" # the default
sysconfig.set_value(db, "search_source", "api")
db.commit()
assert _me(client)["search_source"] == "api"