diff --git a/scripts/update.sh b/scripts/update.sh index 8cf9e4d..fee699e 100644 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -23,10 +23,19 @@ IMPORT_THREADS="${IMPORT_THREADS:-10}" # --- Remote Machine Settings --- REMOTE_BASE_DIR="/opt/paikka/data" +# --- Cloudflare Cache Invalidation Settings --- +CLOUDFLARE_API_BASE_URL="https://api.cloudflare.com/client/v4" +PURGE_CLOUDFLARE_CACHE="${PURGE_CLOUDFLARE_CACHE:-false}" +CLOUDFLARE_API_TOKEN="${CLOUDFLARE_API_TOKEN:-}" +CLOUDFLARE_ZONE_ID="${CLOUDFLARE_ZONE_ID:-}" +CLOUDFLARE_PURGE_PATTERN="${CLOUDFLARE_PURGE_PATTERN:-}" +PURGE_URLS=() # Populated from CLOUDFLARE_PURGE_PATTERN by validate_purge_pattern + # Global variables that will be set by parse_args_and_configure or environment -REMOTE_USER="" -REMOTE_HOST="" -GEOCODER_API_TOKEN="" +REMOTE_USER="${REMOTE_USER:-}" +REMOTE_HOST="${REMOTE_HOST:-}" +GEOCODER_API_TOKEN="${GEOCODER_API_TOKEN:-}" +PBF_INPUT_PATH="${PBF_INPUT_PATH:-}" # ============================================================================== # HELPER FUNCTIONS @@ -36,41 +45,207 @@ log() { echo -e "\n[$(date +'%Y-%m-%d %H:%M:%S')] --- $1 ---" } +### +# Prints usage information for this script. +### +print_usage() { + cat <&2 + fi + + PURGE_URLS=("${validated_urls[@]}") +} + +### +# Parses command-line arguments and applies configuration. +# Precedence: command-line arguments > environment variables > defaults. ### parse_args_and_configure() { + local arg + for arg in "$@"; do + if [ "$arg" = "-h" ] || [ "$arg" = "--help" ]; then + print_usage + exit 0 + fi + done + log "Step 0: Parsing arguments and setting configuration" - # Precedence: Command-line arguments > Environment variables - REMOTE_USER="${1:-$REMOTE_USER}" - REMOTE_HOST="${2:-$REMOTE_HOST}" - GEOCODER_API_TOKEN="${3:-$GEOCODER_API_TOKEN}" + while [ $# -gt 0 ]; do + case "$1" in + --remote-user) require_flag_value "$1" "${2:-}"; REMOTE_USER="$2"; shift 2 ;; + --remote-user=*) REMOTE_USER="${1#*=}"; shift ;; + --remote-host) require_flag_value "$1" "${2:-}"; REMOTE_HOST="$2"; shift 2 ;; + --remote-host=*) REMOTE_HOST="${1#*=}"; shift ;; + --api-token) require_flag_value "$1" "${2:-}"; GEOCODER_API_TOKEN="$2"; shift 2 ;; + --api-token=*) GEOCODER_API_TOKEN="${1#*=}"; shift ;; + --download-dir) require_flag_value "$1" "${2:-}"; DOWNLOAD_DIR="$2"; shift 2 ;; + --download-dir=*) DOWNLOAD_DIR="${1#*=}"; shift ;; + --import-data-dir) require_flag_value "$1" "${2:-}"; IMPORT_DATA_DIR="$2"; shift 2 ;; + --import-data-dir=*) IMPORT_DATA_DIR="${1#*=}"; shift ;; + --memory) require_flag_value "$1" "${2:-}"; IMPORT_MEMORY="$2"; shift 2 ;; + --memory=*) IMPORT_MEMORY="${1#*=}"; shift ;; + --threads) require_flag_value "$1" "${2:-}"; IMPORT_THREADS="$2"; shift 2 ;; + --threads=*) IMPORT_THREADS="${1#*=}"; shift ;; + --pbf-file) require_flag_value "$1" "${2:-}"; PBF_INPUT_PATH="$2"; shift 2 ;; + --pbf-file=*) PBF_INPUT_PATH="${1#*=}"; shift ;; + --purge-cache) PURGE_CLOUDFLARE_CACHE=true; shift ;; + --purge-cache=*) + case "${1#*=}" in + true) PURGE_CLOUDFLARE_CACHE=true ;; + false) PURGE_CLOUDFLARE_CACHE=false ;; + *) echo "Error: Invalid value for --purge-cache (expected true or false)"; print_usage; exit 1 ;; + esac + shift ;; + --cloudflare-token) require_flag_value "$1" "${2:-}"; CLOUDFLARE_API_TOKEN="$2"; shift 2 ;; + --cloudflare-token=*) CLOUDFLARE_API_TOKEN="${1#*=}"; shift ;; + --cloudflare-zone-id) require_flag_value "$1" "${2:-}"; CLOUDFLARE_ZONE_ID="$2"; shift 2 ;; + --cloudflare-zone-id=*) CLOUDFLARE_ZONE_ID="${1#*=}"; shift ;; + --purge-pattern) require_flag_value "$1" "${2:-}"; CLOUDFLARE_PURGE_PATTERN="$2"; shift 2 ;; + --purge-pattern=*) CLOUDFLARE_PURGE_PATTERN="${1#*=}"; shift ;; + *) echo "Error: Unknown option: $1"; print_usage; exit 1 ;; + esac + done - DOWNLOAD_DIR="${4:-$DOWNLOAD_DIR}" - IMPORT_DATA_DIR="${5:-$IMPORT_DATA_DIR}" - IMPORT_MEMORY="${6:-$IMPORT_MEMORY}" - IMPORT_THREADS="${7:-$IMPORT_THREADS}" - PBF_INPUT_PATH="${8:-}" if [ -z "$REMOTE_USER" ] || [ -z "$REMOTE_HOST" ] || [ -z "$GEOCODER_API_TOKEN" ]; then - echo "Usage: $0 [DOWNLOAD_DIR] [IMPORT_DATA_DIR] [MEMORY] [THREADS]" - echo " DOWNLOAD_DIR: Where to download PBF files (default: current directory)" - echo " IMPORT_DATA_DIR: Where to store import data (default: ./import)" - echo " MEMORY: Memory for import (default: 16G)" - echo " THREADS: Threads for import (default: 10)" - echo "Error: Missing required configuration." + echo "Error: Missing required configuration (--remote-user, --remote-host, --api-token)." + print_usage exit 1 fi - if [ -n "$PBF_INPUT_PATH" ] && [ ! -f "$PBF_INPUT_PATH" ]; then echo "Error: PBF file not found"; exit 1; fi + if [ -n "$PBF_INPUT_PATH" ] && [ ! -f "$PBF_INPUT_PATH" ]; then + echo "Error: PBF file not found: $PBF_INPUT_PATH" + exit 1 + fi + if [ "$PURGE_CLOUDFLARE_CACHE" = "true" ]; then + if [ -z "$CLOUDFLARE_API_TOKEN" ]; then + echo "Error: Cache purge is enabled but no Cloudflare API token was provided (--cloudflare-token)." + print_usage + exit 1 + fi + if [ -z "$CLOUDFLARE_ZONE_ID" ]; then + echo "Error: Cache purge is enabled but no Cloudflare zone ID was provided (--cloudflare-zone-id)." + print_usage + exit 1 + fi + if [ -n "$CLOUDFLARE_PURGE_PATTERN" ]; then + validate_purge_pattern + fi + elif [ -n "$CLOUDFLARE_PURGE_PATTERN" ]; then + echo "Warning: --purge-pattern given but cache purge is not enabled (--purge-cache). The pattern will be ignored." + fi + echo "Configuration loaded for ${REMOTE_USER}@${REMOTE_HOST}" echo " Download directory: $DOWNLOAD_DIR" echo " Import data directory: $IMPORT_DATA_DIR" echo " Import memory: $IMPORT_MEMORY" echo " Import threads: $IMPORT_THREADS" + if [ -n "$PBF_INPUT_PATH" ]; then + echo " PBF input file: $PBF_INPUT_PATH" + fi + if [ "$PURGE_CLOUDFLARE_CACHE" = "true" ]; then + echo " Cloudflare cache purge: enabled (zone ID: $CLOUDFLARE_ZONE_ID)" + if [ "${#PURGE_URLS[@]}" -gt 0 ]; then + echo " Purge pattern: ${PURGE_URLS[*]}" + else + echo " Purge pattern: entire zone cache" + fi + else + echo " Cloudflare cache purge: disabled" + fi } ### @@ -286,6 +461,53 @@ remote_cleanup_old_releases() { echo_remote "Cleanup complete" EOF } + +### +# LOCAL: Purges the Cloudflare cache for the configured zone after a successful +# update. Purges the entire zone when no pattern is configured, otherwise only +# the configured URLs. Fails soft: warns and continues if the purge fails, +# because the data deployment itself has already completed at this point. +### +purge_cloudflare_cache() { + if [ "$PURGE_CLOUDFLARE_CACHE" != "true" ]; then + return 0 + fi + + log "CLOUDFLARE: Purging cache for zone $CLOUDFLARE_ZONE_ID" + + local purge_body + if [ "${#PURGE_URLS[@]}" -gt 0 ]; then + log "CLOUDFLARE: Purging ${#PURGE_URLS[@]} URL(s) from the configured pattern" + local urls_json="" + local url + for url in "${PURGE_URLS[@]}"; do + urls_json+="\"${url//\"/\\\"}\"," + done + purge_body="{\"files\":[${urls_json%,}]}" + else + log "CLOUDFLARE: Purging the entire zone cache" + purge_body='{"purge_everything":true}' + fi + + local response_file + response_file="$(mktemp)" + local http_status + http_status="$(curl -s -o "$response_file" -w "%{http_code}" \ + --max-time 60 \ + -X POST \ + "${CLOUDFLARE_API_BASE_URL}/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" \ + -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data "$purge_body")" || http_status="curl_failed" + + if [ "$http_status" = "200" ] && grep -Eq '"success":[[:space:]]*true' "$response_file"; then + log "CLOUDFLARE: Cache purge successful" + else + echo "WARNING: Cloudflare cache purge failed (HTTP status: $http_status). Continuing anyway." >&2 + echo "WARNING: Cloudflare response: $(cat "$response_file")" >&2 + fi + rm -f "$response_file" +} # ============================================================================== # MAIN ORCHESTRATION FUNCTION # ============================================================================== @@ -305,6 +527,7 @@ main() { local_cleanup_pbf remote_sync_bundle remote_deploy_and_verify + purge_cloudflare_cache remote_cleanup_old_releases log "Update process finished." diff --git a/src/main/resources/static/css/dark-theme.css b/src/main/resources/static/css/dark-theme.css index 92d2331..ea24dc5 100644 --- a/src/main/resources/static/css/dark-theme.css +++ b/src/main/resources/static/css/dark-theme.css @@ -154,6 +154,27 @@ body { border-radius: 0 0 12px 12px; } +/* Full-viewport map page */ +body.map-page { + margin: 0; + overflow: hidden; +} + +body.map-page .container { + max-width: none; + margin: 0; + border-radius: 0; + box-shadow: none; + background: transparent; +} + +body.map-page #map { + width: 100vw; + height: 100vh; + min-height: 100vh; + border-radius: 0; +} + .map-info { position: absolute; left: 15px; @@ -206,30 +227,32 @@ body { .legend { position: absolute; - top: 15px; - right: 15px; - background: var(--bg-card); - padding: 15px; - border-radius: 8px; - box-shadow: 0 4px 15px var(--shadow); + top: 10px; + right: 10px; + background: rgba(37, 37, 37, 0.85); + backdrop-filter: blur(6px); + -webkit-backdrop-filter: blur(6px); + padding: 6px 10px; + border-radius: 6px; + box-shadow: 0 2px 8px var(--shadow); z-index: 1000; - font-size: 13px; + font-size: 11px; border: 1px solid var(--border-color); - min-width: 200px; } .legend h4 { - margin: 0 0 10px 0; + margin: 0 0 6px 0; color: var(--text-primary); - font-size: 14px; + font-size: 11px; font-weight: 600; } .legend-item { display: flex; align-items: center; - margin-bottom: 8px; + margin-bottom: 4px; color: var(--text-secondary); + white-space: nowrap; } .legend-item:last-child { @@ -237,17 +260,17 @@ body { } .legend-circle { - width: 14px; - height: 14px; + width: 10px; + height: 10px; border-radius: 50%; - margin-right: 10px; + margin-right: 6px; border: 1px solid rgba(255, 255, 255, 0.3); } .legend-square { - width: 12px; - height: 12px; - margin-right: 8px; + width: 9px; + height: 9px; + margin-right: 6px; flex-shrink: 0; border: 1px solid #daa520; } @@ -258,6 +281,11 @@ body { margin: 10px; border-radius: 8px; } + + body.map-page .container { + margin: 0; + border-radius: 0; + } .header { padding: 20px; @@ -300,13 +328,13 @@ body { bottom: 40px; padding: 6px 10px; } - - .legend { - position: relative; - top: auto; - right: auto; - margin: 15px; - width: calc(100% - 30px); + + body.map-page .legend { + position: absolute; + top: 8px; + right: 8px; + margin: 0; + width: auto; } } diff --git a/src/main/resources/templates/map.html b/src/main/resources/templates/map.html index 84d8dda..718675d 100644 --- a/src/main/resources/templates/map.html +++ b/src/main/resources/templates/map.html @@ -7,25 +7,24 @@ - +
Loading map and location data...
-

Query Activity

- High activity (100+ queries) - White fill, more transparent + High (100+)
- Medium activity (20-99 queries) - Light gray fill + Medium (20-99)
- Low activity (5-19 queries) - Dark gray fill, less transparent + Low (5-19)