[+] Backend sdk

This commit is contained in:
2024-12-17 00:26:41 -05:00
parent b01a4446ef
commit 058e6675a3
3 changed files with 13 additions and 7 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ async def get_puzzle(id: str):
tf = data / f"{id}.json" tf = data / f"{id}.json"
if not tf.exists(): if not tf.exists():
return {"error": "Puzzle not found"} return {"error": "Puzzle not found"}
return tf.read_text() return json.loads(tf.read_text())
# Getting / redirects to main page # Getting / redirects to main page
+3 -4
View File
@@ -9,10 +9,9 @@
const params = new URLSearchParams(location.search) const params = new URLSearchParams(location.search)
// Can pass in puzzle data from props // Can pass in puzzle data from props
interface Props { puzzleData?: { id: string, rows: number, cols: number, interface Props { puzzleId?: string, puzzleData?: Checkpoint }
numbers: i8s, nMask: i8s, hColors: i8s, vColors: i8s, colors: string[] } } export let { puzzleId, puzzleData }: Props = {}
export let { puzzleData }: Props = {} const pid = puzzleId ?? 'slitherlink'
const pid = puzzleData?.id ?? 'slitherlink'
// Main variables // Main variables
const [rows, cols] = [+(puzzleData?.rows ?? params.get('size') ?? 40), +(puzzleData?.cols ?? params.get('size') ?? 40)] const [rows, cols] = [+(puzzleData?.rows ?? params.get('size') ?? 40), +(puzzleData?.cols ?? params.get('size') ?? 40)]
+9 -2
View File
@@ -1,11 +1,13 @@
export type i8s = Int8Array export type i8s = Int8Array
export interface Checkpoint { hStates: i8s, vStates: i8s, hColors: i8s, vColors: i8s, numbers: i8s, nMask: i8s, colors: string[] } export interface Checkpoint { rows: number, cols: number,
hStates: i8s, vStates: i8s, hColors: i8s, vColors: i8s, numbers: i8s, nMask: i8s, colors: string[] }
export const cfg = { export const cfg = {
cellW: 20, cellW: 20,
lineW: 4, lineW: 4,
totalW: 24 totalW: 24,
backend: "https://slither0.hydev.org",
} }
export const eStates = { export const eStates = {
@@ -67,3 +69,8 @@ export const Fmt = {
return `${d ? `${d}d ` : ''}${h ? `${h}:` : ''}${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}` return `${d ? `${d}d ` : ''}${h ? `${h}:` : ''}${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`
} }
} }
export const Backend = {
get: (id: string) => fetch(`${cfg.backend}/${id}`).then(r => r.text()).then(JsonTy.parse),
post: (data: Checkpoint) => fetch(`${cfg.backend}/`, { method: "post", body: JsonTy.stringify(data) }),
}