Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- build-android.sh +58 -0
- public/scripts/ColorRmApp.js +4 -4
- public/scripts/config.js +36 -9
build-android.sh
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Android Build Script for Capacitor App
|
| 4 |
+
# Usage: ./build-android.sh [environment] [build-type]
|
| 5 |
+
#
|
| 6 |
+
# Environments: bundled-cf (default), bundled-hf, cloudflare, hf, local
|
| 7 |
+
# Build types: debug (default), release
|
| 8 |
+
|
| 9 |
+
set -e
|
| 10 |
+
|
| 11 |
+
ENV="${1:-bundled-cf}"
|
| 12 |
+
BUILD_TYPE="${2:-debug}"
|
| 13 |
+
|
| 14 |
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
| 15 |
+
echo " Building Android APK"
|
| 16 |
+
echo " Environment: $ENV"
|
| 17 |
+
echo " Build Type: $BUILD_TYPE"
|
| 18 |
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
| 19 |
+
|
| 20 |
+
# Step 1: Build web assets
|
| 21 |
+
echo ""
|
| 22 |
+
echo "→ Building web assets..."
|
| 23 |
+
export CAPACITOR_SERVER_IP_ENV="$ENV"
|
| 24 |
+
npm run build
|
| 25 |
+
|
| 26 |
+
# Step 2: Sync to Android
|
| 27 |
+
echo ""
|
| 28 |
+
echo "→ Syncing to Android..."
|
| 29 |
+
npx cap sync android
|
| 30 |
+
|
| 31 |
+
# Step 3: Build APK
|
| 32 |
+
echo ""
|
| 33 |
+
echo "→ Building APK..."
|
| 34 |
+
cd android
|
| 35 |
+
chmod +x gradlew
|
| 36 |
+
|
| 37 |
+
if [ "$BUILD_TYPE" = "release" ]; then
|
| 38 |
+
./gradlew assembleRelease
|
| 39 |
+
APK_PATH="app/build/outputs/apk/release/app-release-unsigned.apk"
|
| 40 |
+
else
|
| 41 |
+
./gradlew assembleDebug
|
| 42 |
+
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
|
| 43 |
+
fi
|
| 44 |
+
|
| 45 |
+
cd ..
|
| 46 |
+
|
| 47 |
+
# Done
|
| 48 |
+
echo ""
|
| 49 |
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
| 50 |
+
echo " ✓ Build Complete!"
|
| 51 |
+
echo " APK: android/$APK_PATH"
|
| 52 |
+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
| 53 |
+
|
| 54 |
+
# Optional: Copy to easy location
|
| 55 |
+
if [ -f "android/$APK_PATH" ]; then
|
| 56 |
+
cp "android/$APK_PATH" "./app-$ENV-$BUILD_TYPE.apk"
|
| 57 |
+
echo " Copied to: ./app-$ENV-$BUILD_TYPE.apk"
|
| 58 |
+
fi
|
public/scripts/ColorRmApp.js
CHANGED
|
@@ -137,7 +137,7 @@ export class ColorRmApp {
|
|
| 137 |
// 5. Sync Base File (only for collaborative mode)
|
| 138 |
if (this.config.collaborative) {
|
| 139 |
try {
|
| 140 |
-
const res = await fetch(`/api/color_rm/base_file/${projectId}`, { method: 'GET' });
|
| 141 |
if (res.ok) {
|
| 142 |
if (this.state.images.length === 0) {
|
| 143 |
console.log("Liveblocks: Downloading base file from server...");
|
|
@@ -1669,7 +1669,7 @@ export class ColorRmApp {
|
|
| 1669 |
if (this.isFetchingBase) return;
|
| 1670 |
this.isFetchingBase = true;
|
| 1671 |
try {
|
| 1672 |
-
const res = await fetch(`/api/color_rm/base_file/${this.state.sessionId}`);
|
| 1673 |
if (res.ok) {
|
| 1674 |
const blob = await res.blob();
|
| 1675 |
await this.importBaseFile(blob);
|
|
@@ -2657,7 +2657,7 @@ export class ColorRmApp {
|
|
| 2657 |
console.log('ColorRM Sync: Uploading base file to server for ID:', this.state.sessionId);
|
| 2658 |
this.ui.toggleLoader(true, "Uploading to server...");
|
| 2659 |
try {
|
| 2660 |
-
const uploadRes = await fetch(`/api/color_rm/upload/${this.state.sessionId}`, {
|
| 2661 |
method: 'POST',
|
| 2662 |
body: files[0],
|
| 2663 |
headers: {
|
|
@@ -2852,7 +2852,7 @@ export class ColorRmApp {
|
|
| 2852 |
if (this.state.images.length > 0 && this.state.images[0].blob) {
|
| 2853 |
this.ui.showToast("Re-uploading base...");
|
| 2854 |
try {
|
| 2855 |
-
await fetch(`/api/color_rm/upload/${this.state.sessionId}`, {
|
| 2856 |
method: 'POST',
|
| 2857 |
body: this.state.images[0].blob,
|
| 2858 |
headers: { 'Content-Type': this.state.images[0].blob.type }
|
|
|
|
| 137 |
// 5. Sync Base File (only for collaborative mode)
|
| 138 |
if (this.config.collaborative) {
|
| 139 |
try {
|
| 140 |
+
const res = await fetch(window.Config?.apiUrl(`/api/color_rm/base_file/${projectId}`) || `/api/color_rm/base_file/${projectId}`, { method: 'GET' });
|
| 141 |
if (res.ok) {
|
| 142 |
if (this.state.images.length === 0) {
|
| 143 |
console.log("Liveblocks: Downloading base file from server...");
|
|
|
|
| 1669 |
if (this.isFetchingBase) return;
|
| 1670 |
this.isFetchingBase = true;
|
| 1671 |
try {
|
| 1672 |
+
const res = await fetch(window.Config?.apiUrl(`/api/color_rm/base_file/${this.state.sessionId}`) || `/api/color_rm/base_file/${this.state.sessionId}`);
|
| 1673 |
if (res.ok) {
|
| 1674 |
const blob = await res.blob();
|
| 1675 |
await this.importBaseFile(blob);
|
|
|
|
| 2657 |
console.log('ColorRM Sync: Uploading base file to server for ID:', this.state.sessionId);
|
| 2658 |
this.ui.toggleLoader(true, "Uploading to server...");
|
| 2659 |
try {
|
| 2660 |
+
const uploadRes = await fetch(window.Config?.apiUrl(`/api/color_rm/upload/${this.state.sessionId}`) || `/api/color_rm/upload/${this.state.sessionId}`, {
|
| 2661 |
method: 'POST',
|
| 2662 |
body: files[0],
|
| 2663 |
headers: {
|
|
|
|
| 2852 |
if (this.state.images.length > 0 && this.state.images[0].blob) {
|
| 2853 |
this.ui.showToast("Re-uploading base...");
|
| 2854 |
try {
|
| 2855 |
+
await fetch(window.Config?.apiUrl(`/api/color_rm/upload/${this.state.sessionId}`) || `/api/color_rm/upload/${this.state.sessionId}`, {
|
| 2856 |
method: 'POST',
|
| 2857 |
body: this.state.images[0].blob,
|
| 2858 |
headers: { 'Content-Type': this.state.images[0].blob.type }
|
public/scripts/config.js
CHANGED
|
@@ -22,6 +22,18 @@ export const Config = {
|
|
| 22 |
if (window.location.protocol === 'file:' &&
|
| 23 |
window.location.href.includes('capacitor')) return true;
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return false;
|
| 26 |
},
|
| 27 |
|
|
@@ -29,11 +41,24 @@ export const Config = {
|
|
| 29 |
isRemoteMode() {
|
| 30 |
if (typeof window === 'undefined') return false;
|
| 31 |
const host = window.location.host || '';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
return host.includes('hf.space') ||
|
| 33 |
host.includes('workers.dev') ||
|
| 34 |
host.includes('duckdns.org') ||
|
| 35 |
-
host.includes('localhost') ||
|
| 36 |
host.includes('192.168.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
},
|
| 38 |
|
| 39 |
// Get the API base URL
|
|
@@ -45,16 +70,16 @@ export const Config = {
|
|
| 45 |
return '';
|
| 46 |
}
|
| 47 |
|
| 48 |
-
//
|
| 49 |
-
if (
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
-
//
|
| 54 |
-
|
| 55 |
-
const base = this.BACKENDS[preferredBackend] || this.BACKENDS.cloudflare;
|
| 56 |
-
console.log('[Config] Using backend:', base);
|
| 57 |
-
return base;
|
| 58 |
},
|
| 59 |
|
| 60 |
// Helper to make API URL
|
|
@@ -79,9 +104,11 @@ export const Config = {
|
|
| 79 |
getDebugInfo() {
|
| 80 |
return {
|
| 81 |
isCapacitor: this.isCapacitor(),
|
|
|
|
| 82 |
isRemoteMode: this.isRemoteMode(),
|
| 83 |
protocol: window.location.protocol,
|
| 84 |
host: window.location.host,
|
|
|
|
| 85 |
apiBase: this.getApiBase(),
|
| 86 |
preferredBackend: localStorage.getItem('color_rm_backend') || 'cloudflare'
|
| 87 |
};
|
|
|
|
| 22 |
if (window.location.protocol === 'file:' &&
|
| 23 |
window.location.href.includes('capacitor')) return true;
|
| 24 |
|
| 25 |
+
// Check for http:// on localhost with empty or file-like path (Android WebView bundled)
|
| 26 |
+
if (window.location.protocol === 'http:' &&
|
| 27 |
+
window.location.host === 'localhost' &&
|
| 28 |
+
window.location.pathname.startsWith('/')) {
|
| 29 |
+
// This could be bundled Capacitor or local dev - check for Capacitor later
|
| 30 |
+
return false;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
// Check for https:// on localhost (Android secure WebView)
|
| 34 |
+
if (window.location.protocol === 'https:' &&
|
| 35 |
+
window.location.host.includes('localhost')) return true;
|
| 36 |
+
|
| 37 |
return false;
|
| 38 |
},
|
| 39 |
|
|
|
|
| 41 |
isRemoteMode() {
|
| 42 |
if (typeof window === 'undefined') return false;
|
| 43 |
const host = window.location.host || '';
|
| 44 |
+
|
| 45 |
+
// If host is empty or file-based, not remote mode
|
| 46 |
+
if (!host || host === '') return false;
|
| 47 |
+
|
| 48 |
return host.includes('hf.space') ||
|
| 49 |
host.includes('workers.dev') ||
|
| 50 |
host.includes('duckdns.org') ||
|
|
|
|
| 51 |
host.includes('192.168.');
|
| 52 |
+
// Note: removed 'localhost' - it should trigger bundled mode detection
|
| 53 |
+
},
|
| 54 |
+
|
| 55 |
+
// Force bundled mode check - called after Capacitor is definitely loaded
|
| 56 |
+
isBundledMode() {
|
| 57 |
+
// If Capacitor is present and we're not pointing to a remote server, we're bundled
|
| 58 |
+
if (window.Capacitor && !this.isRemoteMode()) {
|
| 59 |
+
return true;
|
| 60 |
+
}
|
| 61 |
+
return false;
|
| 62 |
},
|
| 63 |
|
| 64 |
// Get the API base URL
|
|
|
|
| 70 |
return '';
|
| 71 |
}
|
| 72 |
|
| 73 |
+
// Bundled Capacitor mode: need absolute URL to backend
|
| 74 |
+
if (this.isBundledMode() || this.isCapacitor()) {
|
| 75 |
+
const preferredBackend = localStorage.getItem('color_rm_backend') || 'cloudflare';
|
| 76 |
+
const base = this.BACKENDS[preferredBackend] || this.BACKENDS.cloudflare;
|
| 77 |
+
console.log('[Config] Bundled mode - using backend:', base);
|
| 78 |
+
return base;
|
| 79 |
}
|
| 80 |
|
| 81 |
+
// Web browser: relative URLs work
|
| 82 |
+
return '';
|
|
|
|
|
|
|
|
|
|
| 83 |
},
|
| 84 |
|
| 85 |
// Helper to make API URL
|
|
|
|
| 104 |
getDebugInfo() {
|
| 105 |
return {
|
| 106 |
isCapacitor: this.isCapacitor(),
|
| 107 |
+
isBundledMode: this.isBundledMode(),
|
| 108 |
isRemoteMode: this.isRemoteMode(),
|
| 109 |
protocol: window.location.protocol,
|
| 110 |
host: window.location.host,
|
| 111 |
+
href: window.location.href,
|
| 112 |
apiBase: this.getApiBase(),
|
| 113 |
preferredBackend: localStorage.getItem('color_rm_backend') || 'cloudflare'
|
| 114 |
};
|