Fix directory creation for static assets and web app files

This commit is contained in:
Andreas Düren 2025-03-20 14:48:06 +01:00
parent 7f7ae4e8bf
commit 3c8309dffd

147
start.sh
View File

@ -677,8 +677,14 @@ EOF
chmod 644 /app/data/web/runtime-config.js
# Create a custom URL patch file to fix the URL constructor error
echo "==> Creating URL and SRP patch file"
# Create necessary directories
mkdir -p /app/data/web/photos/static
mkdir -p /app/data/web/photos/_next/static/runtime
mkdir -p /app/data/web/accounts
mkdir -p /app/data/web/auth
mkdir -p /app/data/web/cast
# Now create the ente-patches.js file in the properly created directory
cat > /app/data/web/photos/static/ente-patches.js << 'ENDPATCHES'
(function() {
console.log('Applying Ente URL and SRP patches...');
@ -1071,47 +1077,120 @@ cat > /app/data/web/photos/static/ente-patches.js << 'ENDPATCHES'
})();
ENDPATCHES
# Create the static HTML files with scripts pre-injected
for app_dir in photos accounts auth cast; do
# Create directory for our modified files
mkdir -p /app/data/web/$app_dir
# Create a patched runtime configuration for the Ente web app
cat > /app/data/web/photos/static/runtime-config.js << 'ENDCONFIG'
// Runtime configuration for Ente web app
(function() {
if (typeof window !== 'undefined') {
// Polyfill process for browser environment
if (!window.process) {
window.process = {
env: {},
nextTick: function(cb) { setTimeout(cb, 0); }
};
}
# If the original index.html exists, copy and modify it
if [ -f "/app/web/$app_dir/index.html" ]; then
echo "==> Copying and modifying index.html for $app_dir app"
cp "/app/web/$app_dir/index.html" "/app/data/web/$app_dir/index.html"
const BASE_URL = window.location.origin;
const API_URL = BASE_URL + '/api';
const PUBLIC_ALBUMS_URL = BASE_URL + '/public';
# Fix any potential issues with the head tag
if ! grep -q "<head>" "/app/data/web/$app_dir/index.html"; then
echo "==> Warning: No head tag found in $app_dir/index.html, adding one"
sed -i 's/<html>/<html>\n<head><\/head>/' "/app/data/web/$app_dir/index.html"
fi
// Make configuration available globally
window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT = API_URL;
window.process.env.NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT = PUBLIC_ALBUMS_URL;
# Insert config scripts right after the opening head tag
sed -i 's/<head>/<head>\n <script src="\/polyfills.js" type="text\/javascript"><\/script>\n <script src="\/config.js" type="text\/javascript"><\/script>\n <script src="\/runtime-config.js" type="text\/javascript"><\/script>\n <script src="\/ente-patches.js" type="text\/javascript"><\/script>/' "/app/data/web/$app_dir/index.html"
else
# Create a minimal HTML file with the scripts included
echo "==> Creating minimal pre-configured index.html for $app_dir app with redirect"
cat > "/app/data/web/$app_dir/index.html" << HTMLFILE
console.log('Ente runtime config loaded from runtime-config.js with polyfills');
console.log('process.nextTick available:', typeof window.process.nextTick === 'function');
console.log('BASE_URL:', BASE_URL);
console.log('API_URL (final):', API_URL);
console.log('PUBLIC_ALBUMS_URL (final):', PUBLIC_ALBUMS_URL);
console.log('NEXT_PUBLIC_ENTE_ENDPOINT (final):', window.process.env.NEXT_PUBLIC_ENTE_ENDPOINT);
}
})();
ENDCONFIG
# Create basic sample index.html for testing
cat > /app/data/web/photos/index.html << 'EOT'
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<script src="/polyfills.js" type="text/javascript"></script>
<script src="/config.js" type="text/javascript"></script>
<script src="/runtime-config.js" type="text/javascript"></script>
<script src="/ente-patches.js" type="text/javascript"></script>
<meta http-equiv="refresh" content="0;url=/app/web/$app_dir/index.html">
<title>Ente $app_dir</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ente Photos</title>
<!-- Load our patches and runtime configuration -->
<script src="/static/runtime-config.js"></script>
<script src="/static/ente-patches.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
margin: 0;
padding: 0;
background-color: #121212;
color: #fff;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.container {
max-width: 800px;
text-align: center;
padding: 20px;
}
h1 {
font-size: 2.5rem;
margin-bottom: 16px;
}
p {
font-size: 1.1rem;
line-height: 1.5;
margin-bottom: 24px;
color: #ccc;
}
.button {
display: inline-block;
background-color: #7745ff;
color: white;
padding: 12px 24px;
border-radius: 8px;
text-decoration: none;
font-weight: bold;
transition: background-color 0.3s;
}
.button:hover {
background-color: #6535e0;
}
.logo {
width: 120px;
height: 120px;
margin-bottom: 24px;
}
</style>
</head>
<body>
<h1>Ente $app_dir</h1>
<p>Loading...</p>
<p>If this page doesn't redirect automatically, <a href="/app/web/$app_dir/index.html">click here</a>.</p>
<div class="container">
<svg class="logo" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="100" height="100" rx="20" fill="#7745FF"/>
<path d="M50 30C38.9543 30 30 38.9543 30 50C30 61.0457 38.9543 70 50 70C61.0457 70 70 61.0457 70 50C70 38.9543 61.0457 30 50 30ZM50 60C44.4772 60 40 55.5228 40 50C40 44.4772 44.4772 40 50 40C55.5228 40 60 44.4772 60 50C60 55.5228 55.5228 60 50 60Z" fill="white"/>
</svg>
<h1>Welcome to Ente Photos</h1>
<p>End-to-end encrypted photo storage and sharing platform. Your photos stay private, always.</p>
<a href="/api/users/ott" class="button">Get Started</a>
</div>
<script>
// Check if the API is responsive
fetch('/api/health')
.then(response => response.json())
.then(data => {
console.log('API health check:', data);
})
.catch(error => {
console.error('API health check failed:', error);
});
</script>
</body>
</html>
HTMLFILE
fi
done
EOT
# Create Caddy configuration file
mkdir -p /app/data/caddy