Download backend/gitlab/worm-chain.mjs from Snapkitty/snapkitty-clojure-lisp-bridge: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/backend/gitlab/worm-chain.mjs
- Command line
-
hf download hf://Snapkitty/snapkitty-clojure-lisp-bridge/backend/gitlab/worm-chain.mjs
-
curl -L -o worm-chain.mjs https://huggingface.co/Snapkitty/snapkitty-clojure-lisp-bridge/resolve/main/backend/gitlab/worm-chain.mjs
1.06 kB
| import { createHash } from 'crypto' | |
| import { appendFile, readFile, mkdir } from 'fs/promises' | |
| import { existsSync } from 'fs' | |
| import { join } from 'path' | |
| const WORM_DIR = join(process.cwd(), '.worm') | |
| const WORM_FILE = join(WORM_DIR, 'gitlab_chain.jsonl') | |
| let prevHash = '0'.repeat(64) | |
| async function ensureDir() { | |
| if (!existsSync(WORM_DIR)) await mkdir(WORM_DIR, { recursive: true }) | |
| } | |
| export async function wormSeal(data) { | |
| await ensureDir() | |
| const ts = Date.now() | |
| const this_hash = createHash('sha256') | |
| .update(`${prevHash}:${ts}:${JSON.stringify(data)}`) | |
| .digest('hex') | |
| const entry = { ts, prev_hash: prevHash, this_hash, ...data } | |
| await appendFile(WORM_FILE, JSON.stringify(entry) + '\n') | |
| prevHash = this_hash | |
| return entry | |
| } | |
| export async function readWorm(limit = 20) { | |
| await ensureDir() | |
| try { | |
| const lines = (await readFile(WORM_FILE, 'utf8')) | |
| .split('\n').filter(Boolean).map(l => JSON.parse(l)) | |
| return lines.slice(-limit).reverse() | |
| } catch { return [] } | |
| } | |