This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

stigmergic / container / sync.ts
2.1 kB 63 lines
1// ─── Sync: pull vault + carry into container ────────────────────── 2// 3// vault: ob sync (Obsidian CLI) 4// carry: git pull from GitHub private repo (auth via CARRY_GITHUB_TOKEN) 5 6import { execSync } from "child_process"; 7 8const VAULT_PATH = process.env.VAULT_PATH || "/data/vault"; 9const CARRY_PATH = process.env.CARRY_PATH || "/data/carry"; 10const CARRY_GITHUB_TOKEN = process.env.CARRY_GITHUB_TOKEN || ""; 11const CARRY_BRANCH = process.env.CARRY_BRANCH || "main"; 12const CARRY_REPO = "codegod100/carry-vault"; 13 14function getCarryRemote(): string { 15 if (CARRY_GITHUB_TOKEN) { 16 return `https://${CARRY_GITHUB_TOKEN}@github.com/${CARRY_REPO}.git`; 17 } 18 return ""; 19} 20 21export async function syncVault(): Promise<void> { 22 try { 23 execSync(`ob sync ${VAULT_PATH}`, { stdio: "pipe", timeout: 60000 }); 24 console.log("[sync] vault synced via ob"); 25 } catch (e: any) { 26 console.error("[sync] vault sync failed:", e.message); 27 } 28} 29 30export async function syncCarry(): Promise<void> { 31 const remote = getCarryRemote(); 32 if (!remote) { 33 console.error("[sync] CARRY_GITHUB_TOKEN not set, skipping carry sync"); 34 return; 35 } 36 37 try { 38 // If not cloned yet, clone; otherwise pull 39 try { 40 execSync(`git -C ${CARRY_PATH} rev-parse --git-dir`, { stdio: "pipe" }); 41 execSync(`git -C ${CARRY_PATH} pull origin ${CARRY_BRANCH}`, { 42 stdio: "pipe", 43 timeout: 30000, 44 env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, 45 }); 46 console.log("[sync] carry pulled via git"); 47 } catch { 48 // Not a git repo — clone 49 execSync(`git clone --branch ${CARRY_BRANCH} --single-branch ${remote} ${CARRY_PATH}`, { 50 stdio: "pipe", 51 timeout: 60000, 52 env: { ...process.env, GIT_TERMINAL_PROMPT: "0" }, 53 }); 54 console.log("[sync] carry cloned via git"); 55 } 56 } catch (e: any) { 57 console.error("[sync] carry sync failed:", e.message); 58 } 59} 60 61export async function syncAll(): Promise<void> { 62 await Promise.all([syncVault(), syncCarry()]); 63}