Download common.js from jaynesmax/studio: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/jaynesmax/studio/resolve/main/common.js
- Command line
-
hf download hf://spaces/jaynesmax/studio/common.js
-
curl -L -o common.js https://huggingface.co/spaces/jaynesmax/studio/resolve/main/common.js
1.43 kB
| import { CONFIG } from "./config.js"; | |
| import { createClient } from "https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2.45.4/+esm"; | |
| export const sb = createClient(CONFIG.SUPABASE_URL, CONFIG.SUPABASE_ANON_KEY); | |
| export const h = s => String(s ?? "").replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); | |
| export async function getSettings() { | |
| const { data, error } = await sb.from("settings").select("key,value"); | |
| if (error) console.error(error); | |
| const s = {}; | |
| (data || []).forEach(r => (s[r.key] = r.value)); | |
| return s; | |
| } | |
| export function saveSetting(key, value) { | |
| return sb.from("settings").upsert({ key, value }); | |
| } | |
| // Bila nenosiri: ukurasa wa studio unaonyeshwa moja kwa moja. | |
| // Hakikisha /studio imelindwa kwenye hosting yako (password protection au Cloudflare Access). | |
| export async function requireAdmin(gate, app) { | |
| gate.hidden = true; | |
| app.hidden = false; | |
| } | |
| // Kipindi kinachocheza sasa hivi: (saa - epoch) mod jumla, sawa na build_jaynestv.py | |
| export function nowPlaying(sch, nowMs = Date.now()) { | |
| const items = sch?.items; | |
| if (!items?.length || !sch.total) return null; | |
| const epoch = Date.parse(sch.epoch) / 1000; | |
| let t = (((nowMs / 1000 - epoch) % sch.total) + sch.total) % sch.total; | |
| let i = 0; | |
| while (i < items.length - 1 && t >= items[i].dur) { t -= items[i].dur; i++; } | |
| return { cur: items[i], next: items[(i + 1) % items.length] }; | |
| } | |