Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- 1.deploy.sh +76 -0
- Dockerfile +3 -1
- public/scripts/LiveSync.js +20 -0
1.deploy.sh
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
|
| 3 |
+
# --- CONFIGURATION ---
|
| 4 |
+
WORKFLOW_ID="221629785" # ID for 'Build Android (Bundled HuggingFace)'
|
| 5 |
+
ARTIFACT_NAME="tldraw-bundled-hf-debug.apk"
|
| 6 |
+
TARGET_DIR="/storage/emulated/0/Download/MY-T-APP"
|
| 7 |
+
COUNTER_FILE=".build_counter"
|
| 8 |
+
|
| 9 |
+
# 1. RUN HUGGING FACE UPLOAD
|
| 10 |
+
echo "🚀 Starting Hugging Face Upload..."
|
| 11 |
+
~/.hf-cli/venv/bin/hf upload Jaimodiji/my-multiplayer-app . . \
|
| 12 |
+
--repo-type space \
|
| 13 |
+
--exclude "node_modules/*" \
|
| 14 |
+
--exclude "dist/*" \
|
| 15 |
+
--exclude ".wrangler/*" \
|
| 16 |
+
--exclude ".git/*" \
|
| 17 |
+
--exclude ".env" \
|
| 18 |
+
--exclude ".dev.vars" \
|
| 19 |
+
--exclude "temp/*" \
|
| 20 |
+
--exclude "restored_files/*" \
|
| 21 |
+
--exclude "*.sqlite" \
|
| 22 |
+
--exclude "*.log"
|
| 23 |
+
|
| 24 |
+
# 2. GIT INCREMENTAL COMMIT
|
| 25 |
+
# Check/Create counter file
|
| 26 |
+
if [ ! -f "$COUNTER_FILE" ]; then echo 0 > "$COUNTER_FILE"; fi
|
| 27 |
+
# Read, Increment, Save
|
| 28 |
+
CURRENT_COUNT=$(cat "$COUNTER_FILE")
|
| 29 |
+
NEXT_COUNT=$((CURRENT_COUNT + 1))
|
| 30 |
+
echo "$NEXT_COUNT" > "$COUNTER_FILE"
|
| 31 |
+
|
| 32 |
+
COMMIT_MSG="test-dev-$NEXT_COUNT"
|
| 33 |
+
echo "📦 Committing to Git with message: '$COMMIT_MSG'..."
|
| 34 |
+
|
| 35 |
+
git add .
|
| 36 |
+
git commit -m "$COMMIT_MSG"
|
| 37 |
+
git push
|
| 38 |
+
|
| 39 |
+
# 3. TRIGGER GITHUB ACTION
|
| 40 |
+
echo "🎬 Triggering GitHub Action (ID: $WORKFLOW_ID)..."
|
| 41 |
+
gh workflow run "$WORKFLOW_ID"
|
| 42 |
+
|
| 43 |
+
# Give GitHub a moment to register the run
|
| 44 |
+
echo "⏳ Waiting for run to start..."
|
| 45 |
+
sleep 5
|
| 46 |
+
|
| 47 |
+
# Get the ID of the run we just triggered (the most recent one)
|
| 48 |
+
RUN_ID=$(gh run list --workflow "$WORKFLOW_ID" --limit 1 --json databaseId -q '.[0].databaseId')
|
| 49 |
+
echo "👀 Watching Run ID: $RUN_ID"
|
| 50 |
+
|
| 51 |
+
# Watch the run until it finishes. If it fails, exit script.
|
| 52 |
+
gh run watch "$RUN_ID" --exit-status
|
| 53 |
+
if [ $? -ne 0 ]; then
|
| 54 |
+
echo "❌ Build Failed on GitHub! Check logs."
|
| 55 |
+
exit 1
|
| 56 |
+
fi
|
| 57 |
+
|
| 58 |
+
# 4. DOWNLOAD AND MOVE ARTIFACT
|
| 59 |
+
echo "📥 Downloading artifact..."
|
| 60 |
+
# Create target directory if it doesn't exist
|
| 61 |
+
mkdir -p "$TARGET_DIR"
|
| 62 |
+
|
| 63 |
+
# Download to a temporary folder
|
| 64 |
+
mkdir -p temp_artifact
|
| 65 |
+
gh run download "$RUN_ID" -n "$ARTIFACT_NAME" --dir temp_artifact
|
| 66 |
+
|
| 67 |
+
# Unzip and Move
|
| 68 |
+
# GitHub wraps artifacts in a zip. We unzip it and move the .apk file.
|
| 69 |
+
echo "📂 Extracting and moving to Android storage..."
|
| 70 |
+
unzip -o temp_artifact/*.zip -d temp_artifact/
|
| 71 |
+
find temp_artifact -name "*.apk" -exec mv {} "$TARGET_DIR/" \;
|
| 72 |
+
|
| 73 |
+
# Cleanup
|
| 74 |
+
rm -rf temp_artifact
|
| 75 |
+
|
| 76 |
+
echo "✅ DONE! APK saved to: $TARGET_DIR"
|
Dockerfile
CHANGED
|
@@ -25,4 +25,6 @@ ENV NODE_ENV=development
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
# Run disk check, init, restore, then start dev server, backup worker, and PDF convert server concurrently
|
| 28 |
-
CMD ["sh", "-c", "df -h && node cmd/hf_init.mjs && node cmd/hf_restore.mjs && npx concurrently \"npm run dev\" \"node cmd/hf_backup.mjs\" \"node cmd/pdf_convert_server.mjs\""]
|
|
|
|
|
|
|
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
# Run disk check, init, restore, then start dev server, backup worker, and PDF convert server concurrently
|
| 28 |
+
#CMD ["sh", "-c", "df -h && node cmd/hf_init.mjs && node cmd/hf_restore.mjs && npx concurrently \"npm run dev\" \"node cmd/hf_backup.mjs\" \"node cmd/pdf_convert_server.mjs\""]
|
| 29 |
+
|
| 30 |
+
CMD ["sh", "-c", "df -h && \"npm run dev\" "]
|
public/scripts/LiveSync.js
CHANGED
|
@@ -1873,6 +1873,19 @@ export class LiveSyncClient {
|
|
| 1873 |
console.log(`[_renderPdfPagesFromBase] ArrayBuffer size: ${arrayBuffer.byteLength}, expected PDF size: ${blob.size}`);
|
| 1874 |
|
| 1875 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1876 |
console.log(`[_renderPdfPagesFromBase] Loading PDF with pdf.js...`);
|
| 1877 |
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
|
| 1878 |
console.log(`[_renderPdfPagesFromBase] PDF loaded successfully, numPages: ${pdf.numPages}`);
|
|
@@ -1881,6 +1894,13 @@ export class LiveSyncClient {
|
|
| 1881 |
console.error(`[_renderPdfPagesFromBase] ArrayBuffer byte check - first 100 bytes:`,
|
| 1882 |
Array.from(new Uint8Array(arrayBuffer.slice(0, 100))).map(b => b.toString(16).padStart(2, '0')).join(' '));
|
| 1883 |
console.error(`[_renderPdfPagesFromBase] Content type check:`, blob.type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1884 |
throw pdfError;
|
| 1885 |
}
|
| 1886 |
|
|
|
|
| 1873 |
console.log(`[_renderPdfPagesFromBase] ArrayBuffer size: ${arrayBuffer.byteLength}, expected PDF size: ${blob.size}`);
|
| 1874 |
|
| 1875 |
try {
|
| 1876 |
+
// Check the first few bytes to see if it's a valid PDF header
|
| 1877 |
+
const headerBytes = Array.from(new Uint8Array(arrayBuffer.slice(0, 8)));
|
| 1878 |
+
const headerHex = headerBytes.map(b => b.toString(16).padStart(2, '0')).join(' ');
|
| 1879 |
+
const headerAscii = String.fromCharCode(...headerBytes);
|
| 1880 |
+
|
| 1881 |
+
console.log(`[_renderPdfPagesFromBase] PDF header check: ${headerHex} ('${headerAscii}')`);
|
| 1882 |
+
|
| 1883 |
+
// Valid PDF header should start with %PDF-
|
| 1884 |
+
if (!headerAscii.startsWith('%PDF-')) {
|
| 1885 |
+
console.error(`[_renderPdfPagesFromBase] ERROR: Invalid PDF header! Expected '%PDF-', got '${headerAscii}'`);
|
| 1886 |
+
console.error(`[_renderPdfPagesFromBase] Full header bytes:`, headerHex);
|
| 1887 |
+
}
|
| 1888 |
+
|
| 1889 |
console.log(`[_renderPdfPagesFromBase] Loading PDF with pdf.js...`);
|
| 1890 |
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
|
| 1891 |
console.log(`[_renderPdfPagesFromBase] PDF loaded successfully, numPages: ${pdf.numPages}`);
|
|
|
|
| 1894 |
console.error(`[_renderPdfPagesFromBase] ArrayBuffer byte check - first 100 bytes:`,
|
| 1895 |
Array.from(new Uint8Array(arrayBuffer.slice(0, 100))).map(b => b.toString(16).padStart(2, '0')).join(' '));
|
| 1896 |
console.error(`[_renderPdfPagesFromBase] Content type check:`, blob.type);
|
| 1897 |
+
|
| 1898 |
+
// Additional debugging for PDF header
|
| 1899 |
+
const headerBytes = Array.from(new Uint8Array(arrayBuffer.slice(0, 8)));
|
| 1900 |
+
const headerHex = headerBytes.map(b => b.toString(16).padStart(2, '0')).join(' ');
|
| 1901 |
+
const headerAscii = String.fromCharCode(...headerBytes);
|
| 1902 |
+
console.error(`[_renderPdfPagesFromBase] Actual PDF header: ${headerHex} ('${headerAscii}')`);
|
| 1903 |
+
|
| 1904 |
throw pdfError;
|
| 1905 |
}
|
| 1906 |
|