modified: clients/awk/sync/src/un.awk

modified:   clients/c/src/un.c
	modified:   clients/clojure/sync/src/un.clj
	modified:   clients/cobol/sync/src/un.cob
	modified:   clients/cpp/sync/src/un.cpp
	modified:   clients/crystal/sync/src/un.cr
	modified:   clients/d/sync/src/un.d
	modified:   clients/dart/sync/src/un.dart
	modified:   clients/elixir/sync/src/un.ex
	modified:   clients/erlang/sync/src/un.erl
	modified:   clients/forth/sync/src/un.forth
	modified:   clients/fortran/sync/src/un.f90
	modified:   clients/fsharp/sync/src/un.fs
	modified:   clients/haskell/sync/src/un.hs
	modified:   clients/julia/sync/src/un.jl
	modified:   clients/kotlin/sync/src/un.kt
	modified:   clients/lisp/sync/src/un.lisp
	modified:   clients/nim/sync/src/un.nim
	modified:   clients/ocaml/sync/src/un.ml
	modified:   clients/powershell/sync/src/un.ps1
	modified:   clients/prolog/sync/src/un.pro
	modified:   clients/r/sync/src/un.r
	modified:   clients/scheme/sync/src/un.scm
	modified:   clients/tcl/sync/src/un.tcl
	modified:   clients/typescript/sync/src/un.ts
	modified:   clients/v/sync/src/un.v
	modified:   clients/zig/sync/src/un.zig
This commit is contained in:
russell@unturf.com 2026-01-17 12:01:42 -05:00
parent cc7674f7d7
commit 1077543b7c
27 changed files with 1952 additions and 192 deletions

View file

@ -65,6 +65,8 @@
(def portal-base "https://unsandbox.com")
(def languages-cache-ttl 3600) ;; 1 hour in seconds
(def ext-map
{".hs" "haskell" ".ml" "ocaml" ".clj" "clojure" ".scm" "scheme"
".lisp" "commonlisp" ".erl" "erlang" ".ex" "elixir" ".exs" "elixir"
@ -518,9 +520,42 @@
(let [api-key (get-api-key)]
(validate-key api-key extend?)))
(defn get-languages-cache-path []
(let [home (System/getenv "HOME")]
(str home "/.unsandbox/languages.json")))
(defn load-languages-cache []
(let [cache-path (get-languages-cache-path)]
(when (.exists (io/file cache-path))
(try
(let [content (slurp cache-path)
timestamp (extract-field "timestamp" content)]
(when timestamp
(let [cache-time (Long/parseLong timestamp)
now (quot (System/currentTimeMillis) 1000)]
(when (< (- now cache-time) languages-cache-ttl)
content))))
(catch Exception _ nil)))))
(defn save-languages-cache [languages-json]
(let [cache-path (get-languages-cache-path)
cache-dir (.getParent (io/file cache-path))]
(.mkdirs (io/file cache-dir))
(let [timestamp (quot (System/currentTimeMillis) 1000)
cache-content (str "{\"languages\":" languages-json ",\"timestamp\":" timestamp "}")]
(spit cache-path cache-content))))
(defn languages-command [json-output?]
(let [api-key (get-api-key)
response (curl-get api-key "/languages")]
;; Try cache first
cached (load-languages-cache)
response (if cached
cached
(let [resp (curl-get api-key "/languages")]
;; Extract and cache the languages array
(when-let [match (re-find #"\"languages\":\s*\[([^\]]*)\]" resp)]
(save-languages-cache (str "[" (second match) "]")))
resp))]
(if json-output?
;; Extract language names and output as JSON array
(let [langs (re-seq #"\"name\":\"([^\"]+)\"" response)