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.
84 lines
2.6 KiB
Bash
Executable File
84 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Generate the Settings-grid thumbnails from the verified originals.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/lib.sh"
|
|
|
|
require_cmd magick
|
|
require_cmd jq
|
|
validate_manifest
|
|
ensure_workdirs
|
|
|
|
THUMB_STATE="$STATE_DIR/thumbs.json"
|
|
state_init "$THUMB_STATE"
|
|
|
|
parse_common_args "$@"
|
|
|
|
info "Generating 480x270 JPEG thumbnails from $(photo_count) photos."
|
|
info "Output: $THUMBS_DIR"
|
|
info ""
|
|
|
|
while IFS= read -r file; do
|
|
src="$ROOT/$file"
|
|
[[ -f "$src" ]] || die "missing local file: $src"
|
|
|
|
expected_sha="$(photo_field "$file" sha256)"
|
|
expected_size="$(photo_field "$file" size)"
|
|
expected_dim="$(photo_field "$file" dim)"
|
|
expected_mime="$(photo_field "$file" mime)"
|
|
|
|
actual_sha="$(sha256_file "$src")"
|
|
actual_size="$(file_size "$src")"
|
|
actual_dim="$(image_dim "$src")"
|
|
actual_mime="$(file_mime "$src")"
|
|
|
|
[[ "$actual_sha" == "$expected_sha" ]] || die "sha256 mismatch for $file (expected $expected_sha, got $actual_sha)"
|
|
[[ "$actual_size" == "$expected_size" ]] || die "size mismatch for $file (expected $expected_size, got $actual_size)"
|
|
[[ "$actual_dim" == "$expected_dim" ]] || die "dimension mismatch for $file (expected $expected_dim, got $actual_dim)"
|
|
[[ "$actual_mime" == "$expected_mime" ]] || die "MIME mismatch for $file (expected $expected_mime, got $actual_mime)"
|
|
|
|
base="$(basename "$file")"
|
|
thumb="$THUMBS_DIR/$base"
|
|
|
|
if [[ "$FORCE" != "1" && -f "$thumb" && "$thumb" -nt "$src" ]]; then
|
|
info "keep: $thumb"
|
|
else
|
|
magick "$src" -auto-orient -resize 480x270 -strip -quality 82 "$thumb"
|
|
info "made: $thumb"
|
|
fi
|
|
|
|
thumb_sha="$(sha256_file "$thumb")"
|
|
thumb_size="$(file_size "$thumb")"
|
|
thumb_dim="$(image_dim "$thumb")"
|
|
thumb_mime="$(file_mime "$thumb")"
|
|
|
|
old_sha="$(jq -r --arg f "$file" '.[$f].sha256 // empty' "$THUMB_STATE")"
|
|
if [[ "$old_sha" != "$thumb_sha" ]]; then
|
|
tmp="$THUMB_STATE.tmp"
|
|
jq --arg f "$file" '.[$f] |= del(.url, .uploadedAt, .server)' "$THUMB_STATE" > "$tmp"
|
|
mv "$tmp" "$THUMB_STATE"
|
|
fi
|
|
|
|
tmp="$THUMB_STATE.tmp"
|
|
jq --arg f "$file" \
|
|
--arg thumb "$thumb" \
|
|
--arg sha "$thumb_sha" \
|
|
--arg dim "$thumb_dim" \
|
|
--arg mime "$thumb_mime" \
|
|
--argjson size "$thumb_size" \
|
|
'.[$f] = ((.[$f] // {}) + {
|
|
thumb: $thumb,
|
|
sha256: $sha,
|
|
size: $size,
|
|
dim: $dim,
|
|
mime: $mime
|
|
})' "$THUMB_STATE" > "$tmp"
|
|
mv "$tmp" "$THUMB_STATE"
|
|
|
|
info " $thumb_dim, $thumb_size bytes, sha256=$thumb_sha"
|
|
done < <(photo_files)
|
|
|
|
info ""
|
|
info "Thumbnails ready. Next: ./scripts/nostr/run.sh upload-thumbnails"
|
|
info "Publishing is blocked until every thumbnail is uploaded and preflight passes." |