react-native-bspatch 1.0.6 → 1.0.7

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 +25 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bspatch",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
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",
@@ -105,7 +105,7 @@ if [ "$ACTION" != "reset" ]; then
105
105
  GH_BRANCH=$(echo "$CLEAN_URL" | cut -d'/' -f3)
106
106
  if [[ -z "$GH_BRANCH" ]]; then GH_BRANCH="main"; fi
107
107
 
108
- # Prefer GitHub CLI token for authenticated requests (higher rate limit, no cache)
108
+ # Prefer GitHub CLI token for authenticated requests (higher rate limit, no CDN cache)
109
109
  GH_CLI_TOKEN=$(gh auth token 2>/dev/null || true)
110
110
  GH_API_TOKEN="${GH_CLI_TOKEN:-${GH_TOKEN:-${GITHUB_TOKEN:-}}}"
111
111
 
@@ -113,30 +113,39 @@ if [ "$ACTION" != "reset" ]; then
113
113
  # The API always returns the latest committed content.
114
114
  REGISTRY_API_URL="https://api.github.com/repos/${GH_OWNER}/${GH_REPO}/contents/${BASE_FOLDER}/ota_registry.json?ref=${GH_BRANCH}"
115
115
 
116
+ API_HTTP_FILE=$(mktemp)
117
+ API_BODY_FILE=$(mktemp)
118
+
116
119
  if [[ -n "$GH_API_TOKEN" ]]; then
117
- API_RES=$(curl -s -w "\n---HTTP:%{http_code}" \
120
+ curl -s -o "$API_BODY_FILE" -w "%{http_code}" \
118
121
  -H "Authorization: Bearer $GH_API_TOKEN" \
119
122
  -H "Accept: application/vnd.github.v3+json" \
120
- "$REGISTRY_API_URL" 2>/dev/null || true)
123
+ "$REGISTRY_API_URL" > "$API_HTTP_FILE" 2>/dev/null || true
121
124
  else
122
- API_RES=$(curl -s -w "\n---HTTP:%{http_code}" \
125
+ curl -s -o "$API_BODY_FILE" -w "%{http_code}" \
123
126
  -H "Accept: application/vnd.github.v3+json" \
124
- "$REGISTRY_API_URL" 2>/dev/null || true)
127
+ "$REGISTRY_API_URL" > "$API_HTTP_FILE" 2>/dev/null || true
125
128
  fi
126
129
 
127
- API_HTTP=$(echo "$API_RES" | grep -o '---HTTP:[0-9]*' | cut -d: -f2)
128
- API_BODY=$(echo "$API_RES" | sed 's/---HTTP:.*//')
130
+ API_HTTP=$(cat "$API_HTTP_FILE" 2>/dev/null || echo "0")
131
+ rm -f "$API_HTTP_FILE"
129
132
 
130
133
  if [[ "$API_HTTP" = "200" ]]; then
131
- # Decode base64 content returned by the API
132
- echo "$API_BODY" | python3 -c "
134
+ # Decode base64 content returned by the GitHub Contents API in one python3 pass
135
+ python3 - "$API_BODY_FILE" "$REGISTRY_SHARED.tmp" << 'PYEOF'
133
136
  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
137
+ body_file, out_file = sys.argv[1], sys.argv[2]
138
+ try:
139
+ with open(body_file, 'r') as f:
140
+ d = json.load(f)
141
+ content = d.get('content', '')
142
+ decoded = base64.b64decode(content.replace('\n', ''))
143
+ with open(out_file, 'wb') as f:
144
+ f.write(decoded)
145
+ except Exception as e:
146
+ sys.exit(1)
147
+ PYEOF
148
+ rm -f "$API_BODY_FILE"
140
149
 
141
150
  if [ -s "$REGISTRY_SHARED.tmp" ]; then
142
151
  mv "$REGISTRY_SHARED.tmp" "$REGISTRY_SHARED"
@@ -146,7 +155,7 @@ sys.stdout.buffer.write(decoded)
146
155
  echo " Notice: Remote registry empty or decode failed (starting fresh with local state)."
147
156
  fi
148
157
  else
149
- rm -f "$REGISTRY_SHARED.tmp"
158
+ rm -f "$API_BODY_FILE" "$REGISTRY_SHARED.tmp"
150
159
  echo " Notice: Remote registry not found on GitHub API (HTTP $API_HTTP — starting fresh with local state)."
151
160
  fi
152
161