Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 49 minutes ago History
urls.py · 5.8 KB · 145 lines
1"""site_urls -- every URL this server answers, compiled: /urls.
2
3The sibling of /flow. Routing here has three sources and all of them are
4inspectable -- convention (a site_* object's file IS its URL), the
5site_routes collection (patterned routes as data), and the views
6collection (generated pages declare their route) -- plus the fixed core
7API surface, whose paths are constants in http_api_contract by design.
8Because none of it hides in code, the site map is compiled, not
9maintained: install a package and its URLs appear here; delete a page
10object and its convention URL vanishes. A hand-written sitemap is wrong
11within a week; this one cannot be.
12
13Each row says WHERE the URL comes from (convention | route | view | core),
14what serves it, and -- for routes that shadow or are shadowed -- notes
15that convention wins over data (docs/site-routing.md's precedence,
16verified the hard way).
17
18Signed-in users only, same courtesy as /flow: the complete map of a
19server's surface is reconnaissance data.
20"""
21
22import html
23import os
24from pathlib import Path
25
26import http_api_contract
27import object_namespace
28import object_records
29
30
31def _base_dir():
32 return os.environ.get("DBBASIC_DATA_DIR", "data")
33
34
35def _esc(value):
36 return html.escape(str(value or ""))
37
38
39def _safe_records(collection):
40 try:
41 # access: URL map: route patterns only, no record content
42 return object_records.read_collection_records(collection, base_dir=_base_dir())
43 except Exception:
44 return []
45
46
47def _convention_pages():
48 """site_* objects whose file IS their URL (/notes -> site_notes)."""
49 out = []
50 for root in object_namespace.get_object_roots():
51 site_dir = Path(root) / "site"
52 if not site_dir.exists():
53 continue
54 for path in sorted(site_dir.glob("*.py")):
55 name = path.stem
56 if name.startswith("_"):
57 continue
58 url = "/" if name == "home" else "/" + name.replace("_", "-")
59 out.append({"url": url, "serves": f"site_{name}", "source": "convention"})
60 return out
61
62
63def _core_api_rows():
64 """The fixed platform surface: contract constants, not discovery."""
65 rows = [
66 (http_api_contract.SEARCH_PATH, "global search"),
67 (http_api_contract.MCP_PATH, "MCP: agents operate the server as tools"),
68 (http_api_contract.WEBHOOKS_PATH + "/{name}", "raw-body webhooks (webhook_{name} objects)"),
69 ("/api/schema/{collection}", "schema as contract: clients build their own UI"),
70 ("/collections/{collection}/records", "the JSON records API"),
71 ("/objects/{object_id}", "direct object execution"),
72 ("/ws", "realtime push (permission-filtered signals)"),
73 ("/login", "session login"),
74 (http_api_contract.DAEMON_STATUS_PATH, "daemon posture (admin token)"),
75 (http_api_contract.DAEMON_SCHEDULER_TASKS_PATH, "scheduler task CRUD (admin token)"),
76 ]
77 return [{"url": u, "serves": what, "source": "core"} for u, what in rows]
78
79
80def GET(request):
81 identity = request.get("_identity") or {}
82 if not identity.get("user_id"):
83 body = ('<p class="hint"><a href="/login?next=/urls">Sign in</a> to see the map of '
84 "every URL this server answers.</p>")
85 else:
86 rows = []
87 rows += _convention_pages()
88 for r in _safe_records("site_routes"):
89 rows.append({"url": r.get("pattern", ""), "serves": r.get("object_id", ""),
90 "source": "route"})
91 for v in _safe_records("views"):
92 if v.get("route"):
93 rows.append({"url": v["route"], "serves": f"view: {v.get('id')}",
94 "source": "view"})
95 rows += _core_api_rows()
96
97 # Convention beats data: where both claim a URL, say so instead of
98 # listing two rows that look equally live.
99 convention_urls = {r["url"] for r in rows if r["source"] == "convention"}
100 seen = set()
101 table = []
102 for r in sorted(rows, key=lambda x: (x["url"], x["source"])):
103 key = (r["url"], r["serves"])
104 if key in seen:
105 continue
106 seen.add(key)
107 shadowed = (r["source"] in ("route", "view")
108 and r["url"] in convention_urls)
109 note = ('<span class="warn">shadowed: a convention page object wins for this '
110 'URL</span>' if shadowed else "")
111 table.append(
112 f"<tr><td><code><a href='{_esc(r['url'])}'>{_esc(r['url'])}</a></code></td>"
113 f"<td>{_esc(r['serves'])}</td><td>{_esc(r['source'])}</td><td>{note}</td></tr>")
114 body = f"""
115<div class="breadcrumb"><a href="/">Home</a> / URLs</div>
116<h1>Every URL this server answers</h1>
117<p class="muted">Compiled from convention (a page object's file is its URL), the
118site_routes and views collections, and the fixed core API. Nothing here is
119hand-maintained, so nothing here can be stale. {len(table)} entries.</p>
120<table><thead><tr><th>URL</th><th>serves</th><th>source</th><th></th></tr></thead>
121<tbody>{''.join(table)}</tbody></table>
122<p class="muted">Precedence when sources overlap: convention page objects win, then
123site_routes patterns match as fallback (docs/site-routing.md).</p>
124"""
125
126 return {"content_type": "text/html; charset=utf-8", "body": f"""<!doctype html>
127<html lang="en">
128<head>
129<meta charset="utf-8">
130<meta name="viewport" content="width=device-width, initial-scale=1">
131<title>URLs</title>
132<link rel="stylesheet" href="/style">
133<style>
134.wrap {{ max-width: 960px; margin: 0 auto; padding: 1.25rem; }}
135table {{ width: 100%; border-collapse: collapse; }}
136td, th {{ text-align: left; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--line, #333); }}
137.muted {{ color: var(--muted, #999); }}
138.warn {{ color: var(--warning, #f1b747); font-size: 0.8rem; }}
139</style>
140</head>
141<body>
142<script src="/nav"></script>
143<div class="wrap">{body}</div>
144</body>
145</html>"""}