diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-17 22:56:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-17 22:56:43 +0300 |
| commit | abe75a4209f86b562ac3e711804713c9a4325443 (patch) | |
| tree | 767318599e55b03d5f03d5b60d30b6793eafe4d9 /scripts | |
| parent | 03ea6253b3ccd9f0a4582969841c09b96cae59fb (diff) | |
immich-upload: auto-detect LAN vs public ingress
Probe the LAN /api/server/ping endpoint with a short timeout and use it
when reachable, otherwise fall back to the public HTTPS URL. Fixes the
indefinite hang when running off the home LAN.
Amp-Thread-ID: https://ampcode.com/threads/T-019ed713-5af1-72a2-8a4e-27ee32c1d6d5
Co-authored-by: Amp <amp@ampcode.com>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/immich-upload | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/scripts/immich-upload b/scripts/immich-upload index 9cc616f..a780730 100755 --- a/scripts/immich-upload +++ b/scripts/immich-upload @@ -8,8 +8,9 @@ set -euo pipefail -IMMICH_URL="http://immich.f3s.lan.buetow.org" -# IMMICH_URL="http://immich.f3s.buetow.org" +IMMICH_LAN_URL="http://immich.f3s.lan.buetow.org" # LAN-only, fast when on home network +IMMICH_PUBLIC_URL="https://immich.f3s.buetow.org" # public, works from anywhere +IMMICH_URL="" # auto-detected in main() API_KEY_FILE="$HOME/.immich_paul_key" # Supported image extensions (case-insensitive) @@ -25,6 +26,29 @@ warn() { echo "WARN: $1" >&2; } info() { echo "==> $1"; } +# Probe the Immich /api/server/ping endpoint at the given base URL. +# Returns success only on HTTP 200 within a short timeout (follows redirects). +immich_reachable() { + local url="$1" + local code + code=$(curl -sL -m 5 -o /dev/null -w '%{http_code}' \ + "$url/api/server/ping" 2>/dev/null) || return 1 + [[ "$code" == "200" ]] +} + +# Pick the LAN URL if reachable, otherwise fall back to the public URL. +detect_immich_url() { + if immich_reachable "$IMMICH_LAN_URL"; then + IMMICH_URL="$IMMICH_LAN_URL" + info "Using LAN ingress: $IMMICH_URL" + elif immich_reachable "$IMMICH_PUBLIC_URL"; then + IMMICH_URL="$IMMICH_PUBLIC_URL" + info "LAN ingress unreachable, using public ingress: $IMMICH_URL" + else + die "Immich is not reachable via LAN ($IMMICH_LAN_URL) or public ($IMMICH_PUBLIC_URL)" + fi +} + # Compute SHA1 (hex, lowercase) for a file. file_sha1() { sha1sum "$1" | awk '{print $1}' @@ -233,6 +257,8 @@ main() { die "API key file is empty: $API_KEY_FILE" fi + detect_immich_url + if [[ -f "$src" ]]; then # Single file upload info "Uploading single file: $src" |
