Spaces:
Paused
Paused
Download direct_push.js from dimensionalpulsar/caja: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/spaces/dimensionalpulsar/caja/resolve/main/direct_push.js
- Command line
-
hf download hf://spaces/dimensionalpulsar/caja/direct_push.js
-
curl -L -o direct_push.js https://huggingface.co/spaces/dimensionalpulsar/caja/resolve/main/direct_push.js
1.9 kB
| import fs from 'fs'; | |
| import path from 'path'; | |
| const TOKEN = process.env.HF_TOKEN || "hf_TOKEN_PLACEHOLDER"; | |
| const REPO = "dimensionalpulsar/caja"; | |
| const IGNORE_FILES = ['.git', 'node_modules', 'dist', '.env']; | |
| function getFiles(dir, baseDir = dir) { | |
| let results = []; | |
| const list = fs.readdirSync(dir); | |
| list.forEach(file => { | |
| if (IGNORE_FILES.includes(file)) return; | |
| const fullPath = path.join(dir, file); | |
| const stat = fs.statSync(fullPath); | |
| if (stat && stat.isDirectory()) { | |
| results = results.concat(getFiles(fullPath, baseDir)); | |
| } else { | |
| const relativePath = path.relative(baseDir, fullPath).replace(/\\/g, '/'); | |
| results.push({ fullPath, relativePath }); | |
| } | |
| }); | |
| return results; | |
| } | |
| async function doPush() { | |
| console.log(`Starting push to Hugging Face Space: ${REPO}...`); | |
| const projectDir = process.cwd(); | |
| const files = getFiles(projectDir); | |
| const operations = []; | |
| for (const file of files) { | |
| const buffer = fs.readFileSync(file.fullPath); | |
| operations.push({ | |
| action: "addOrUpdate", | |
| path: file.relativePath, | |
| content: buffer.toString('base64'), | |
| encoding: "base64" | |
| }); | |
| } | |
| const commitUrl = `https://huggingface.co/api/spaces/${REPO}/commit/main`; | |
| try { | |
| const response = await fetch(commitUrl, { | |
| method: "POST", | |
| headers: { | |
| "Authorization": `Bearer ${TOKEN}`, | |
| "Content-Type": "application/json" | |
| }, | |
| body: JSON.stringify({ | |
| summary: "Push PrestaCaja React System to Hugging Face Space", | |
| operations: operations | |
| }) | |
| }); | |
| const text = await response.text(); | |
| if (response.ok) { | |
| console.log("✅ SUCCESS! Project successfully pushed to Hugging Face."); | |
| } else { | |
| console.error("❌ Push failed:", response.status, text); | |
| } | |
| } catch (err) { | |
| console.error("❌ Network or API error:", err); | |
| } | |
| } | |
| doPush(); | |