react-native-bspatch 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tools/build_ota.sh +51 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bspatch",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Premium OTA Update Solution for React Native using TurboModules and bsdiff",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",
@@ -95,19 +95,61 @@ if [ "$ACTION" != "reset" ]; then
95
95
 
96
96
  if [[ "$BASE_URL" == *"github"* ]] || [[ "$BASE_URL" == *"raw.githubusercontent"* ]]; then
97
97
  echo " Downloading remote registry from GitHub..."
98
- # Add cache-busting params + Cache-Control header to bypass GitHub CDN 5-min cache
99
- CACHE_BUST="?cb=$(date +%s)"
100
- HTTP_CODE=$(curl -s -w "%{http_code}" -H "Cache-Control: no-cache" -o "$REGISTRY_SHARED.tmp" "$BASE_URL/$BASE_FOLDER/ota_registry.json${CACHE_BUST}" 2>/dev/null || true)
101
- if [ "$HTTP_CODE" != "200" ]; then
102
- HTTP_CODE=$(curl -s -w "%{http_code}" -H "Cache-Control: no-cache" -o "$REGISTRY_SHARED.tmp" "$BASE_URL/ota_registry.json${CACHE_BUST}" 2>/dev/null || true)
98
+
99
+ # Parse OWNER/REPO/BRANCH from the raw.githubusercontent URL or github.com URL
100
+ # e.g. https://raw.githubusercontent.com/owner/repo/branch OR
101
+ # https://github.com/owner/repo/tree/branch
102
+ CLEAN_URL=$(echo "$BASE_URL" | sed 's#https://raw.githubusercontent.com/##' | sed 's#https://github.com/##' | sed 's#/tree/##')
103
+ GH_OWNER=$(echo "$CLEAN_URL" | cut -d'/' -f1)
104
+ GH_REPO=$(echo "$CLEAN_URL" | cut -d'/' -f2)
105
+ GH_BRANCH=$(echo "$CLEAN_URL" | cut -d'/' -f3)
106
+ if [[ -z "$GH_BRANCH" ]]; then GH_BRANCH="main"; fi
107
+
108
+ # Prefer GitHub CLI token for authenticated requests (higher rate limit, no cache)
109
+ GH_CLI_TOKEN=$(gh auth token 2>/dev/null || true)
110
+ GH_API_TOKEN="${GH_CLI_TOKEN:-${GH_TOKEN:-${GITHUB_TOKEN:-}}}"
111
+
112
+ # Use GitHub Contents API — NOT raw CDN — to bypass the 5-min CDN cache.
113
+ # The API always returns the latest committed content.
114
+ REGISTRY_API_URL="https://api.github.com/repos/${GH_OWNER}/${GH_REPO}/contents/${BASE_FOLDER}/ota_registry.json?ref=${GH_BRANCH}"
115
+
116
+ if [[ -n "$GH_API_TOKEN" ]]; then
117
+ API_RES=$(curl -s -w "\n---HTTP:%{http_code}" \
118
+ -H "Authorization: Bearer $GH_API_TOKEN" \
119
+ -H "Accept: application/vnd.github.v3+json" \
120
+ "$REGISTRY_API_URL" 2>/dev/null || true)
121
+ else
122
+ API_RES=$(curl -s -w "\n---HTTP:%{http_code}" \
123
+ -H "Accept: application/vnd.github.v3+json" \
124
+ "$REGISTRY_API_URL" 2>/dev/null || true)
103
125
  fi
104
- if [ "$HTTP_CODE" = "200" ] && [ -s "$REGISTRY_SHARED.tmp" ]; then
105
- mv "$REGISTRY_SHARED.tmp" "$REGISTRY_SHARED"
106
- echo " ✓ Remote registry synced"
126
+
127
+ API_HTTP=$(echo "$API_RES" | grep -o '---HTTP:[0-9]*' | cut -d: -f2)
128
+ API_BODY=$(echo "$API_RES" | sed 's/---HTTP:.*//')
129
+
130
+ if [[ "$API_HTTP" = "200" ]]; then
131
+ # Decode base64 content returned by the API
132
+ echo "$API_BODY" | python3 -c "
133
+ import sys, json, base64
134
+ d = json.load(sys.stdin)
135
+ content = d.get('content', '')
136
+ # GitHub API returns base64 with newlines; strip them before decoding
137
+ decoded = base64.b64decode(content.replace('\n', ''))
138
+ sys.stdout.buffer.write(decoded)
139
+ " > "$REGISTRY_SHARED.tmp" 2>/dev/null || true
140
+
141
+ if [ -s "$REGISTRY_SHARED.tmp" ]; then
142
+ mv "$REGISTRY_SHARED.tmp" "$REGISTRY_SHARED"
143
+ echo " ✓ Remote registry synced (via GitHub API)"
144
+ else
145
+ rm -f "$REGISTRY_SHARED.tmp"
146
+ echo " Notice: Remote registry empty or decode failed (starting fresh with local state)."
147
+ fi
107
148
  else
108
149
  rm -f "$REGISTRY_SHARED.tmp"
109
- echo " Notice: Remote registry not found on GitHub (starting fresh with local state)."
150
+ echo " Notice: Remote registry not found on GitHub API (HTTP $API_HTTP — starting fresh with local state)."
110
151
  fi
152
+
111
153
  else
112
154
  if [[ -n "$UPCODE_USER" ]] && [[ -n "$UPCODE_PASS" ]]; then
113
155
  LOGIN_RES=$(curl -s -X "POST" "$BASE_URL/public/authen/login" \