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

0 downloads

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.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
flags.py · 2.1 KB · 55 lines
1"""Shared feature-flag helper, served at /flags as window.dbbasicFlags.
2
3Wraps GET /api/flags (packages/app-settings): effective value = the
4caller's own user_prefs override ("flag:<name>") -> the instance-wide
5feature_flags value, resolved server-side per docs/upgrade-and-customization.md
6Rule 5. This module never talks to a collection directly -- it is a thin,
7dependency-free cache in front of that one endpoint.
8
9API:
10 await window.dbbasicFlags.load() // fetch + cache the flag map (once);
11 // safe to call again, re-fetches fresh
12 window.dbbasicFlags(name) // sync lookup: cached string value, or
13 // null if unknown / not loaded yet
14 window.dbbasicFlags.on(name) // sync boolean: true when the cached
15 // value is "on" or "true"
16
17Typical use: `await window.dbbasicFlags.load()` once on page init, then
18`window.dbbasicFlags.on("kanban_view")` anywhere in the page's render path.
19Calling `dbbasicFlags(name)` before `load()` has resolved simply returns
20null (fail dark), so gating a feature behind a flag never throws.
21
22Defined once here, so no page hand-rolls its own /api/flags fetch.
23"""
24
25_JS = r"""
26(function () {
27 let cache = null;
28 let pending = null;
29
30 async function load() {
31 if (pending) return pending;
32 pending = fetch("/api/flags", {credentials: "same-origin", headers: {accept: "application/json"}})
33 .then((res) => res.ok ? res.json() : {status: "error", flags: {}})
34 .then((data) => { cache = (data && data.flags) || {}; pending = null; return cache; })
35 .catch(() => { cache = cache || {}; pending = null; return cache; });
36 return pending;
37 }
38
39 function dbbasicFlags(name) {
40 if (!cache || !(name in cache)) return null;
41 return cache[name];
42 }
43 dbbasicFlags.load = load;
44 dbbasicFlags.on = function (name) {
45 const v = dbbasicFlags(name);
46 return v === "on" || v === "true";
47 };
48
49 window.dbbasicFlags = dbbasicFlags;
50})();
51"""
52
53
54def GET(request):
55 return {"content_type": "application/javascript; charset=utf-8", "body": _JS}