mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
Add Blossom server list to app config (kind 10063)
Blossom servers now live in AppConfig alongside the NIP-65 relay list: - blossomServerMetadata (BUD-03 server list) and useAppBlossomServers flag - src/lib/appBlossom.ts provides APP_BLOSSOM_SERVERS defaults (blossom.ditto.pub, blossom.dreamith.to, blossom.primal.net), parseBlossomServerList, and getEffectiveBlossomServers - NostrSync hydrates the user's kind 10063 event on login - useUploadFile reads effective servers from config
This commit is contained in:
7 files changed
+171
-7
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import { z } from 'zod';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
import { AppContext, type AppConfig, type AppContextType, type Theme, type RelayMetadata } from '@/contexts/AppContext';
|
||||
import { AppContext, type AppConfig, type AppContextType, type Theme, type RelayMetadata, type BlossomServerMetadata } from '@/contexts/AppContext';
|
||||
|
||||
interface AppProviderProps {
|
||||
children: ReactNode;
|
||||
@@ -21,10 +21,18 @@ const RelayMetadataSchema = z.object({
|
||||
updatedAt: z.number(),
|
||||
}) satisfies z.ZodType<RelayMetadata>;
|
||||
|
||||
// Zod schema for BlossomServerMetadata validation
|
||||
const BlossomServerMetadataSchema = z.object({
|
||||
servers: z.array(z.url()),
|
||||
updatedAt: z.number(),
|
||||
}) satisfies z.ZodType<BlossomServerMetadata>;
|
||||
|
||||
// Zod schema for AppConfig validation
|
||||
const AppConfigSchema = z.object({
|
||||
theme: z.enum(['dark', 'light', 'system']),
|
||||
relayMetadata: RelayMetadataSchema,
|
||||
blossomServerMetadata: BlossomServerMetadataSchema,
|
||||
useAppBlossomServers: z.boolean(),
|
||||
}) satisfies z.ZodType<AppConfig>;
|
||||
|
||||
export function AppProvider(props: AppProviderProps) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { parseBlossomServerList } from '@/lib/appBlossom';
|
||||
|
||||
/**
|
||||
* NostrSync - Syncs user's Nostr data
|
||||
@@ -9,6 +10,7 @@ import { useAppContext } from '@/hooks/useAppContext';
|
||||
* This component runs globally to sync various Nostr data when the user logs in.
|
||||
* Currently syncs:
|
||||
* - NIP-65 relay list (kind 10002)
|
||||
* - BUD-03 Blossom server list (kind 10063)
|
||||
*/
|
||||
export function NostrSync() {
|
||||
const { nostr } = useNostr();
|
||||
@@ -58,5 +60,42 @@ export function NostrSync() {
|
||||
syncRelaysFromNostr();
|
||||
}, [user, config.relayMetadata.updatedAt, nostr, updateConfig]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) return;
|
||||
|
||||
const syncBlossomServersFromNostr = async () => {
|
||||
try {
|
||||
const events = await nostr.query(
|
||||
[{ kinds: [10063], authors: [user.pubkey], limit: 1 }],
|
||||
{ signal: AbortSignal.timeout(5000) }
|
||||
);
|
||||
|
||||
if (events.length > 0) {
|
||||
const event = events[0];
|
||||
|
||||
// Only update if the event is newer than our stored data
|
||||
if (event.created_at > config.blossomServerMetadata.updatedAt) {
|
||||
const fetchedServers = parseBlossomServerList(event);
|
||||
|
||||
if (fetchedServers.length > 0) {
|
||||
console.log('Syncing Blossom server list from Nostr:', fetchedServers);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
blossomServerMetadata: {
|
||||
servers: fetchedServers,
|
||||
updatedAt: event.created_at,
|
||||
},
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to sync Blossom servers from Nostr:', error);
|
||||
}
|
||||
};
|
||||
|
||||
syncBlossomServersFromNostr();
|
||||
}, [user, config.blossomServerMetadata.updatedAt, nostr, updateConfig]);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user