Improve URL replacement strategy for frontend assets

- Enhanced rewrite_frontend_reference function to handle multiple URL encoding formats
- Now replaces plain URLs, backslash-escaped URLs, and double-backslash-escaped URLs
- Added https://ente.io -> BASE_URL replacement
- Version bump to 0.3.0

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Your Name
2025-10-21 19:58:39 -06:00
parent 37cd205a07
commit 1738af7f61
2 changed files with 31 additions and 5 deletions

View File

@@ -7,7 +7,7 @@
"contactEmail": "contact@ente.io",
"website": "https://ente.io",
"tagline": "Open source, end-to-end encrypted photo backup",
"version": "0.2.2",
"version": "0.3.0",
"upstreamVersion": "git-main",
"healthCheckPath": "/health",
"httpPort": 3080,

View File

@@ -356,11 +356,36 @@ rewrite_frontend_reference() {
return
fi
# Create escaped versions for different contexts
local search_escaped_slash="${search//\//\\/}"
local replace_escaped_slash="${replace//\//\\/}"
local search_json="${search//\//\\/}"
local replace_json="${replace//\//\\/}"
while IFS= read -r -d '' file; do
if LC_ALL=C grep -F -q "$search" "$file"; then
sed -i "s|$search|$replace|g" "$file"
chown cloudron:cloudron "$file"
count=$((count + 1))
local file_changed=false
# Check if file contains any variant of the search string
if LC_ALL=C grep -q -e "$search" -e "$search_escaped_slash" "$file" 2>/dev/null; then
# Replace plain URL
if sed -i "s|$search|$replace|g" "$file" 2>/dev/null; then
file_changed=true
fi
# Replace backslash-escaped URL (common in JavaScript strings)
if sed -i "s|$search_escaped_slash|$replace_escaped_slash|g" "$file" 2>/dev/null; then
file_changed=true
fi
# Replace double-backslash-escaped URL (common in JSON)
if sed -i "s|${search//\//\\\\/}|${replace//\//\\\\/}|g" "$file" 2>/dev/null; then
file_changed=true
fi
if [ "$file_changed" = true ]; then
chown cloudron:cloudron "$file"
count=$((count + 1))
fi
fi
done < <(find "$WEB_RUNTIME_DIR" -type f \( -name "*.js" -o -name "*.json" -o -name "*.html" -o -name "*.css" -o -name "*.txt" \) -print0)
@@ -381,6 +406,7 @@ if [ -d "$WEB_RUNTIME_DIR" ]; then
"https://web.ente.io|$BASE_URL/photos"
"https://albums.ente.io|$BASE_URL/albums"
"https://family.ente.io|$BASE_URL/family"
"https://ente.io|$BASE_URL"
)
OLD_IFS="$IFS"
for entry in "${FRONTEND_REPLACEMENTS[@]}"; do