react-native-bspatch 1.0.5 → 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.
- package/package.json +1 -1
- package/tools/build_ota.sh +61 -10
package/package.json
CHANGED
package/tools/build_ota.sh
CHANGED
|
@@ -95,19 +95,70 @@ 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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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 CDN 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
|
+
API_HTTP_FILE=$(mktemp)
|
|
117
|
+
API_BODY_FILE=$(mktemp)
|
|
118
|
+
|
|
119
|
+
if [[ -n "$GH_API_TOKEN" ]]; then
|
|
120
|
+
curl -s -o "$API_BODY_FILE" -w "%{http_code}" \
|
|
121
|
+
-H "Authorization: Bearer $GH_API_TOKEN" \
|
|
122
|
+
-H "Accept: application/vnd.github.v3+json" \
|
|
123
|
+
"$REGISTRY_API_URL" > "$API_HTTP_FILE" 2>/dev/null || true
|
|
124
|
+
else
|
|
125
|
+
curl -s -o "$API_BODY_FILE" -w "%{http_code}" \
|
|
126
|
+
-H "Accept: application/vnd.github.v3+json" \
|
|
127
|
+
"$REGISTRY_API_URL" > "$API_HTTP_FILE" 2>/dev/null || true
|
|
103
128
|
fi
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
|
|
130
|
+
API_HTTP=$(cat "$API_HTTP_FILE" 2>/dev/null || echo "0")
|
|
131
|
+
rm -f "$API_HTTP_FILE"
|
|
132
|
+
|
|
133
|
+
if [[ "$API_HTTP" = "200" ]]; then
|
|
134
|
+
# Decode base64 content returned by the GitHub Contents API in one python3 pass
|
|
135
|
+
python3 - "$API_BODY_FILE" "$REGISTRY_SHARED.tmp" << 'PYEOF'
|
|
136
|
+
import sys, json, base64
|
|
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"
|
|
149
|
+
|
|
150
|
+
if [ -s "$REGISTRY_SHARED.tmp" ]; then
|
|
151
|
+
mv "$REGISTRY_SHARED.tmp" "$REGISTRY_SHARED"
|
|
152
|
+
echo " ✓ Remote registry synced (via GitHub API)"
|
|
153
|
+
else
|
|
154
|
+
rm -f "$REGISTRY_SHARED.tmp"
|
|
155
|
+
echo " Notice: Remote registry empty or decode failed (starting fresh with local state)."
|
|
156
|
+
fi
|
|
107
157
|
else
|
|
108
|
-
rm -f "$REGISTRY_SHARED.tmp"
|
|
109
|
-
echo " Notice: Remote registry not found on GitHub (starting fresh with local state)."
|
|
158
|
+
rm -f "$API_BODY_FILE" "$REGISTRY_SHARED.tmp"
|
|
159
|
+
echo " Notice: Remote registry not found on GitHub API (HTTP $API_HTTP — starting fresh with local state)."
|
|
110
160
|
fi
|
|
161
|
+
|
|
111
162
|
else
|
|
112
163
|
if [[ -n "$UPCODE_USER" ]] && [[ -n "$UPCODE_PASS" ]]; then
|
|
113
164
|
LOGIN_RES=$(curl -s -X "POST" "$BASE_URL/public/authen/login" \
|