feat: write nip34.json when publishing a repository
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s

This commit is contained in:
2026-11-29 19:43:22 +07:00
parent 7721ddd6a8
commit 7ead2df034
6 changed files with 153 additions and 9 deletions
+23 -5
View File
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -12,7 +12,7 @@ use nostr::nips::nip19::Nip19Coordinate;
use nostr_connect::prelude::*;
use nostr_sdk::prelude::*;
use signed_core::{Announcement, Deletions, Filters, RepoAddr};
use signed_git::{GitCache, Repo};
use signed_git::{GitCache, Nip34Metadata, Repo};
use signed_nostr::{SignedAuthUrlHandler, UniversalSigner, Update};
use crate::bootstrap::{
@@ -809,8 +809,6 @@ impl Backend {
.await;
}
// The ngit-compatible `nostr.repo` marker makes the next scan
// detect the repository instead of offering to publish it again.
let coordinate = RepoAddr::new(event.pubkey, repo_id.clone());
match Nip19Coordinate::new(coordinate.into(), servers.clone()).to_bech32() {
Ok(naddr) => {
@@ -825,7 +823,27 @@ impl Backend {
Err(error) => log::warn!("failed to encode the repository coordinate: {error}"),
}
Announcement::from_event(&event).ok_or_else(|| anyhow!("failed to parse announcement"))
let announcement = Announcement::from_event(&event)
.ok_or_else(|| anyhow!("failed to parse announcement"))?;
Self::write_nip34_json(&path, &announcement, cx).await;
Ok(announcement)
})
}
/// Records the announcement in `nak`'s `nip34.json`, which keeps itself out of the repository.
fn write_nip34_json(path: &Path, announcement: &Announcement, cx: &mut AsyncApp) -> Task<()> {
let metadata = Nip34Metadata::from_announcement(announcement);
let path = path.to_path_buf();
cx.background_spawn(async move {
let written =
metadata.and_then(|metadata| Repo::open(&path)?.write_nip34_json(&metadata));
if let Err(error) = written {
log::warn!("failed to write nip34.json: {error:#}");
}
})
}