Read the curated photo feeds from wss://nostr.kosmos.org, verify events, cache originals and thumbnails, and let users pick a wallpaper from the Photos section. Nature is the default feed; City Nights is opt-in. Adds the manual publishing scripts, real event fixtures, protocol documentation, and tests with stubbed network connections.
108 lines
3.6 KiB
Bash
Executable File
108 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Upload generated thumbnails to Kosmos Blossom. nak prompts for the key once.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/lib.sh"
|
|
|
|
require_nak
|
|
require_cmd jq
|
|
require_cmd curl
|
|
validate_manifest
|
|
ensure_workdirs
|
|
|
|
THUMB_STATE="$STATE_DIR/thumbs.json"
|
|
[[ -f "$THUMB_STATE" ]] || die "no thumbnail state; run ./scripts/nostr/run.sh thumbnails first"
|
|
|
|
parse_common_args "$@"
|
|
|
|
mapfile -t files < <(
|
|
jq -r --argjson force "$FORCE" \
|
|
'to_entries[] | select(($force == 1) or ((.value.url // "") == "")) | .key' \
|
|
"$THUMB_STATE"
|
|
)
|
|
|
|
if [[ "${#files[@]}" -eq 0 ]]; then
|
|
info "All thumbnails already have Blossom URLs."
|
|
exit 0
|
|
fi
|
|
|
|
thumbs=()
|
|
for file in "${files[@]}"; do
|
|
thumb="$(jq -r --arg f "$file" '.[$f].thumb // empty' "$THUMB_STATE")"
|
|
[[ -n "$thumb" && -f "$thumb" ]] || die "missing generated thumbnail for $file; run thumbnails again"
|
|
thumbs+=("$thumb")
|
|
done
|
|
|
|
info "Uploading ${#files[@]} thumbnail(s) to $BLOSSOM"
|
|
for i in "${!files[@]}"; do
|
|
info " ${files[$i]} -> ${thumbs[$i]}"
|
|
done
|
|
info ""
|
|
if [[ "${#NAK_PROMPT_ARGS[@]}" -gt 0 ]]; then
|
|
info "nak will ask for the key. Paste the Kosmos Blossom upload key (nsec/hex)."
|
|
info "The key is used only by nak and is never written to disk."
|
|
else
|
|
info "NOSTR_SECRET_KEY is set; nak will use it from the environment (no prompt)."
|
|
fi
|
|
|
|
if ! confirm "Upload these thumbnails now?"; then
|
|
info "Aborted."
|
|
exit 1
|
|
fi
|
|
|
|
upload_out="$LOG_DIR/upload-thumbs-$(date -u +%Y%m%dT%H%M%SZ).ndjson"
|
|
|
|
if [[ "$DRY_RUN" == "1" ]]; then
|
|
print_cmd nak "${NAK_PROMPT_ARGS[@]}" blossom --server "$BLOSSOM" upload "${thumbs[@]}"
|
|
exit 0
|
|
fi
|
|
|
|
nak "${NAK_PROMPT_ARGS[@]}" blossom --server "$BLOSSOM" upload "${thumbs[@]}" > "$upload_out"
|
|
|
|
upload_json="$upload_out.json"
|
|
jq -s 'map(select(type == "object"))' "$upload_out" > "$upload_json"
|
|
count="$(jq 'length' "$upload_json")"
|
|
[[ "$count" -eq "${#files[@]}" ]] || die "expected ${#files[@]} upload result(s), got $count; see $upload_out"
|
|
|
|
now="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
|
|
for i in "${!files[@]}"; do
|
|
file="${files[$i]}"
|
|
blob="$(jq -c ".[$i]" "$upload_json")"
|
|
sha="$(jq -r '.sha256 // empty' <<<"$blob")"
|
|
url="$(jq -r '.url // empty' <<<"$blob")"
|
|
remote_size="$(jq -r '.size // empty' <<<"$blob")"
|
|
remote_type="$(jq -r '.type // empty' <<<"$blob")"
|
|
|
|
expected_sha="$(jq -r --arg f "$file" '.[$f].sha256 // empty' "$THUMB_STATE")"
|
|
expected_size="$(jq -r --arg f "$file" '.[$f].size // empty' "$THUMB_STATE")"
|
|
|
|
[[ -n "$sha" && -n "$url" ]] || die "Blossom returned no sha256/url for $file: $blob"
|
|
[[ "$sha" == "$expected_sha" ]] || die "Blossom hash mismatch for $file (expected $expected_sha, got $sha)"
|
|
[[ -z "$remote_size" || "$remote_size" == "$expected_size" ]] || die "Blossom size mismatch for $file (expected $expected_size, got $remote_size)"
|
|
[[ -z "$remote_type" || "$remote_type" == image/* ]] || die "Blossom returned non-image type for $file: $remote_type"
|
|
is_https "$url" || die "Blossom returned a non-https URL for $file: $url"
|
|
url_contains_sha "$url" "$sha" || warn "Blossom URL does not contain the hash for $file: $url"
|
|
|
|
status="$(http_status "$url")"
|
|
[[ "$status" == "200" ]] || die "uploaded thumbnail is not reachable for $file: HTTP $status ($url)"
|
|
|
|
tmp="$THUMB_STATE.tmp"
|
|
jq --arg f "$file" \
|
|
--arg url "$url" \
|
|
--arg server "$BLOSSOM" \
|
|
--arg uploadedAt "$now" \
|
|
'.[$f] = ((.[$f] // {}) + {
|
|
url: $url,
|
|
server: $server,
|
|
uploadedAt: $uploadedAt
|
|
})' "$THUMB_STATE" > "$tmp"
|
|
mv "$tmp" "$THUMB_STATE"
|
|
|
|
info "ok: $file"
|
|
info " $url"
|
|
done
|
|
|
|
info ""
|
|
info "Thumbnails uploaded. Next: ./scripts/nostr/run.sh preflight" |