Files
raucao 6750c61d87 Add Nostr photo feeds and wallpaper selection
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.
2026-11-08 21:51:23 +04:00

161 lines
4.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build unsigned kind-20 photo events and kind-30006 feed events.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib.sh"
require_cmd jq
validate_manifest
ensure_workdirs
mkdir -p "$EVENTS_DIR/photos" "$EVENTS_DIR/feeds"
THUMB_STATE="$STATE_DIR/thumbs.json"
PHOTO_STATE="$STATE_DIR/photos.json"
[[ -f "$THUMB_STATE" ]] || die "no thumbnail state; run ./scripts/nostr/run.sh thumbnails first"
state_init "$PHOTO_STATE"
now="$(date +%s)"
info "Building photo event drafts."
while IFS= read -r file; do
sha="$(photo_field "$file" sha256)"
size="$(photo_field "$file" size)"
dim="$(photo_field "$file" dim)"
mime="$(photo_field "$file" mime)"
url="$(photo_field "$file" url)"
title="$(photo_field "$file" title)"
alt="$(photo_field "$file" alt)"
content="$(photo_field "$file" content)"
creator="$(photo_field "$file" creator)"
profile="$(photo_field "$file" profile)"
source="$(photo_field "$file" source)"
license="$(photo_field "$file" license)"
license_url="$(photo_field "$file" licenseUrl)"
portfolio="$(photo_field "$file" portfolio)"
origin_id="$(photo_field "$file" originId)"
thumb_url="$(jq -r --arg f "$file" '.[$f].url // empty' "$THUMB_STATE")"
[[ -n "$thumb_url" ]] || die "thumbnail not uploaded for $file; run ./scripts/nostr/run.sh upload-thumbnails first"
origin_json="$(jq -cn \
--arg creator "$creator" \
--arg profile "$profile" \
--arg license "$license" \
--arg licenseUrl "$license_url" \
--arg portfolio "$portfolio" \
'{creator: $creator, profile: $profile, license: $license, licenseUrl: $licenseUrl}
+ (if $portfolio != "" then {portfolio: $portfolio} else {} end)')"
tags_json="$(jq -c --arg f "$file" '.photos[] | select(.file == $f) | .tags | map(ascii_downcase) | unique' "$MANIFEST")"
out="$EVENTS_DIR/photos/$sha.json"
jq -n \
--argjson created_at "$now" \
--arg content "$content" \
--arg title "$title" \
--arg url "$url" \
--arg mime "$mime" \
--arg x "$sha" \
--argjson size "$size" \
--arg dim "$dim" \
--arg thumb "$thumb_url" \
--arg alt "$alt" \
--arg origin_id "$origin_id" \
--arg source "$source" \
--arg origin_json "$origin_json" \
--arg profile "$profile" \
--argjson tags "$tags_json" \
'{
kind: 20,
created_at: $created_at,
content: $content,
tags: (
[
["title", $title],
["imeta",
("url " + $url),
("m " + $mime),
("x " + $x),
("size " + ($size | tostring)),
("dim " + $dim),
("thumb " + $thumb),
("alt " + $alt)
],
["m", $mime],
["x", $x]
]
+ ($tags | map(["t", .]))
+ [
["origin", "unsplash", $origin_id, $source, $origin_json],
["r", $profile]
]
)
}' > "$out"
info " $out"
done < <(photo_files)
info ""
info "Building feed event drafts."
while IFS= read -r feed; do
ids=()
missing=()
while IFS= read -r order_file; do
id="$(jq -r --arg f "$order_file" '.[$f].id // empty' "$PHOTO_STATE")"
if [[ -n "$id" ]]; then
ids+=("$id")
else
missing+=("$order_file")
fi
done < <(jq -r --arg f "$feed" '.feeds[] | select(.id == $f) | .order[]' "$MANIFEST")
if [[ "${#missing[@]}" -gt 0 ]]; then
warn "skipping feed $feed: unpublished photo(s):"
for file in "${missing[@]}"; do
warn " $file"
done
continue
fi
title="$(feed_field "$feed" title)"
description="$(feed_field "$feed" description)"
cover="$(feed_field "$feed" cover)"
cover_url="$(jq -r --arg f "$cover" '.[$f].url // empty' "$THUMB_STATE")"
if [[ -z "$cover_url" ]]; then
cover_url="$(photo_field "$cover" url)"
fi
e_tags="$(for id in "${ids[@]}"; do jq -cn --arg id "$id" --arg relay "$RELAY" '["e", $id, $relay]'; done | jq -s '.')"
feed_tags="$(jq -c --arg f "$feed" '.feeds[] | select(.id == $f) | .tags | map(ascii_downcase) | unique' "$MANIFEST")"
out="$EVENTS_DIR/feeds/$(feed_slug "$feed").json"
jq -n \
--argjson created_at "$now" \
--arg d "$feed" \
--arg title "$title" \
--arg description "$description" \
--arg image "$cover_url" \
--argjson e_tags "$e_tags" \
--argjson feed_tags "$feed_tags" \
'{
kind: 30006,
created_at: $created_at,
content: "",
tags: (
[
["d", $d],
["title", $title],
["description", $description],
["image", $image]
]
+ $e_tags
+ [["t", "dashtab-photo-feed"]]
+ ($feed_tags | map(["t", .]))
)
}' > "$out"
info " $out"
done < <(feed_ids)
info ""
info "Drafts built. Next: ./scripts/nostr/run.sh publish-photos"