From d567e181e1eaff42ab33df3f8a7a43e3df873ae0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2026 18:08:05 +0000 Subject: [PATCH] venture doodleloop: backend client --- ventures/doodleloop/time.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ventures/doodleloop/time.js diff --git a/ventures/doodleloop/time.js b/ventures/doodleloop/time.js new file mode 100644 index 0000000..7a66531 --- /dev/null +++ b/ventures/doodleloop/time.js @@ -0,0 +1,35 @@ +/* Time's backend client for a venture page. Written by Time next to index.html; the build never edits it. + Every call resolves to null when the backend can't help (no network, over the daily limit, or the page is being + checked locally), so a product uses these only for extras and works fully without them. + Time.save(obj) -> a share link (string) or null + Time.load() -> the object a share link (?s=...) carried, or null + Time.ai(prompt, {system}) -> text from a small model, or null + Time.ready -> a promise of true when the backend answers */ +(function () { + var API = "https://doodleloop.yolopreneur.lol/api/"; + var local = /^(localhost|127\.|\[::1\]|0\.0\.0\.0)/.test(location.hostname) || location.protocol === "file:"; + + function call(path, init) { + if (local) return Promise.resolve(null); + return fetch(API + path, init).then(function (r) { return r.ok ? r.json() : null; }).catch(function () { return null; }); + } + function post(path, body) { + return call(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }); + } + + window.Time = { + api: API, + ready: call("health").then(function (r) { return !!(r && r.ok); }), + save: function (obj) { + return post("items", obj).then(function (r) { return r && r.link ? r.link : null; }); + }, + load: function () { + var id = new URLSearchParams(location.search).get("s"); + return id && /^[a-z0-9]{6,32}$/.test(id) ? call("items/" + id) : Promise.resolve(null); + }, + ai: function (prompt, opts) { + return post("ai", { prompt: String(prompt || ""), system: opts && opts.system }) + .then(function (r) { return r && typeof r.text === "string" ? r.text : null; }); + } + }; +})();