mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Make Nostr git servers configurable
This commit is contained in:
13 files changed
+145
-22
No files matched your search
@@ -49,6 +49,7 @@ const defaultConfig: AppConfig = {
|
||||
previewDomain: "local-shakespeare.dev",
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
|
||||
ngitServers: ["git.shakespeare.diy", "relay.ngit.dev"],
|
||||
};
|
||||
|
||||
const presetRelays = [
|
||||
|
||||
@@ -26,6 +26,7 @@ const AppConfigSchema = z.object({
|
||||
language: z.string(),
|
||||
showcaseEnabled: z.boolean(),
|
||||
showcaseModerator: z.string(),
|
||||
ngitServers: z.array(z.string()),
|
||||
}) satisfies z.ZodType<AppConfig>;
|
||||
|
||||
export function AppProvider(props: AppProviderProps) {
|
||||
|
||||
@@ -52,6 +52,7 @@ import { useToast } from '@/hooks/useToast';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { useNostrPublish } from '@/hooks/useNostrPublish';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { findCredentialsForRepo } from '@/lib/gitCredentials';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
@@ -59,8 +60,6 @@ import { GitManagementDialog } from '@/components/git/GitManagementDialog';
|
||||
import { MergeDialog } from '@/components/git/MergeDialog';
|
||||
import { PullRequestDialog } from '@/components/git/PullRequestDialog';
|
||||
|
||||
const GRASP_SERVERS = ["git.shakespeare.diy", "relay.ngit.dev"];
|
||||
|
||||
interface GitDialogProps {
|
||||
projectId: string;
|
||||
children?: React.ReactNode;
|
||||
@@ -92,6 +91,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
const { user } = useCurrentUser();
|
||||
const { nostr } = useNostr();
|
||||
const { mutateAsync: publishEvent } = useNostrPublish();
|
||||
const { config } = useAppContext();
|
||||
|
||||
const projectPath = `/projects/${projectId}`;
|
||||
|
||||
@@ -299,10 +299,10 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
}
|
||||
|
||||
// Create repo announcement event (NIP-34 kind 30617)
|
||||
const cloneUrls = GRASP_SERVERS.map(server =>
|
||||
const cloneUrls = config.ngitServers.map(server =>
|
||||
`https://${server}/${nip19.npubEncode(user.pubkey)}/${projectId}.git`
|
||||
);
|
||||
const relayUrls = GRASP_SERVERS.map(server => `wss://${server}`);
|
||||
const relayUrls = config.ngitServers.map(server => `wss://${server}`);
|
||||
|
||||
await publishEvent({
|
||||
kind: 30617,
|
||||
|
||||
@@ -15,15 +15,11 @@ const GIT_KINDS = [
|
||||
1621, // NIP-34 Issue
|
||||
];
|
||||
|
||||
const GIT_RELAYS = [
|
||||
'wss://git.shakespeare.diy/',
|
||||
'wss://relay.ngit.dev/',
|
||||
];
|
||||
|
||||
const NostrProvider: React.FC<NostrProviderProps> = (props) => {
|
||||
const { children } = props;
|
||||
const { config, presetRelays } = useAppContext();
|
||||
|
||||
const gitRelays = config.ngitServers.map(server => `wss://${server}/`);
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Create NPool instance only once
|
||||
@@ -50,7 +46,7 @@ const NostrProvider: React.FC<NostrProviderProps> = (props) => {
|
||||
|
||||
if (filters.every((f) => f.kinds?.every((k) => GIT_KINDS.includes(k)))) {
|
||||
// If all filters are git-related, route to all git relays
|
||||
for (const url of GIT_RELAYS) {
|
||||
for (const url of gitRelays) {
|
||||
routes.set(url, filters);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +58,7 @@ const NostrProvider: React.FC<NostrProviderProps> = (props) => {
|
||||
|
||||
// If it's a git-related event, also publish to the git relays
|
||||
if (GIT_KINDS.includes(event.kind)) {
|
||||
for (const url of GIT_RELAYS) {
|
||||
for (const url of gitRelays) {
|
||||
allRelays.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ export interface AppConfig {
|
||||
showcaseEnabled: boolean;
|
||||
/** Npub of the showcase moderator */
|
||||
showcaseModerator: string;
|
||||
/** Nostr Git Servers (hostnames) */
|
||||
ngitServers: string[];
|
||||
}
|
||||
|
||||
export interface AppContextType {
|
||||
|
||||
@@ -49,6 +49,7 @@ describe('useAIProjectId', () => {
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
},
|
||||
updateConfig: vi.fn(),
|
||||
});
|
||||
|
||||
@@ -41,6 +41,7 @@ function createWrapper(corsProxy: string) {
|
||||
previewDomain: 'local-test.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
};
|
||||
|
||||
return createElement(
|
||||
@@ -81,6 +82,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
});
|
||||
expect(result.current).toEqual({ git: expect.any(Object) });
|
||||
});
|
||||
@@ -94,6 +96,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://custom-cors.example.com',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
});
|
||||
expect(result.current).toEqual({ git: expect.any(Object) });
|
||||
});
|
||||
@@ -107,6 +110,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
});
|
||||
|
||||
// Rerender with a different wrapper (different CORS proxy)
|
||||
|
||||
+3
-3
@@ -12,11 +12,11 @@ export function useGit(): { git: Git } {
|
||||
const { fs } = useFS();
|
||||
const { nostr } = useNostr();
|
||||
const { config } = useAppContext();
|
||||
const { corsProxy } = config;
|
||||
const { corsProxy, ngitServers } = config;
|
||||
|
||||
const git = useMemo(() => {
|
||||
return new Git({ fs, nostr, corsProxy });
|
||||
}, [fs, nostr, corsProxy]);
|
||||
return new Git({ fs, nostr, corsProxy, ngitServers });
|
||||
}, [fs, nostr, corsProxy, ngitServers]);
|
||||
|
||||
return { git };
|
||||
}
|
||||
@@ -22,6 +22,7 @@ function Wrapper({ children }: { children: React.ReactNode }) {
|
||||
previewDomain: 'local-test.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
};
|
||||
|
||||
return createElement(
|
||||
|
||||
+5
-6
@@ -10,6 +10,7 @@ export interface GitOptions {
|
||||
fs: JSRuntimeFS;
|
||||
nostr: NPool;
|
||||
corsProxy?: string;
|
||||
ngitServers?: string[];
|
||||
}
|
||||
|
||||
interface NostrCloneURI {
|
||||
@@ -28,11 +29,13 @@ export class Git {
|
||||
private fs: JSRuntimeFS;
|
||||
private http: HttpClient;
|
||||
private nostr: NPool;
|
||||
private ngitServers: string[];
|
||||
|
||||
constructor(options: GitOptions) {
|
||||
this.fs = options.fs;
|
||||
this.http = new GitHttp(options.corsProxy);
|
||||
this.nostr = options.nostr;
|
||||
this.ngitServers = options.ngitServers ?? ['git.shakespeare.diy', 'relay.ngit.dev'];
|
||||
}
|
||||
|
||||
// Repository initialization and configuration
|
||||
@@ -938,11 +941,7 @@ export class Git {
|
||||
'#d': [nostrURI.d],
|
||||
};
|
||||
|
||||
const gitRelays = new Set<string>([
|
||||
'wss://git.shakespeare.diy/',
|
||||
'wss://relay.ngit.dev/',
|
||||
'wss://relay.nostr.band/', // General purpose relay as fallback
|
||||
]);
|
||||
const gitRelays = this.ngitServers.map(server => `wss://${server}/`);
|
||||
|
||||
let events: NostrEvent[] = [];
|
||||
|
||||
@@ -956,7 +955,7 @@ export class Git {
|
||||
}
|
||||
if (!events.length) {
|
||||
try {
|
||||
events = await this.nostr.group([...gitRelays]).query([filter], { signal: AbortSignal.timeout(5000) });
|
||||
events = await this.nostr.group(gitRelays).query([filter], { signal: AbortSignal.timeout(5000) });
|
||||
} catch (error) {
|
||||
console.error(`Error querying group relays: ${error}`);
|
||||
}
|
||||
|
||||
@@ -312,6 +312,10 @@ const resources = {
|
||||
addAccount: 'Add Account',
|
||||
relayConfiguration: 'Relay Configuration',
|
||||
selectedRelay: 'Selected Relay',
|
||||
nostrGitServers: 'Nostr Git Servers',
|
||||
addServer: 'Add Server',
|
||||
serverHostname: 'Server Hostname',
|
||||
enterHostname: 'Enter hostname (e.g., git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: 'Clone a Git repository into your Shakespeare workspace',
|
||||
@@ -638,6 +642,10 @@ const resources = {
|
||||
addAccount: 'Adicionar Conta',
|
||||
relayConfiguration: 'Configuração de Relay',
|
||||
selectedRelay: 'Relay Selecionado',
|
||||
nostrGitServers: 'Servidores Git Nostr',
|
||||
addServer: 'Adicionar Servidor',
|
||||
serverHostname: 'Nome do Servidor',
|
||||
enterHostname: 'Digite o nome do host (ex: git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: 'Clone um repositório Git para seu workspace Shakespeare',
|
||||
@@ -964,6 +972,10 @@ const resources = {
|
||||
addAccount: '添加账户',
|
||||
relayConfiguration: '中继配置',
|
||||
selectedRelay: '选定的中继',
|
||||
nostrGitServers: 'Nostr Git服务器',
|
||||
addServer: '添加服务器',
|
||||
serverHostname: '服务器主机名',
|
||||
enterHostname: '输入主机名(例如:git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: '将Git仓库克隆到您的Shakespeare工作空间',
|
||||
@@ -1290,6 +1302,10 @@ const resources = {
|
||||
addAccount: 'Ƙara Asusu',
|
||||
relayConfiguration: 'Saitunan Relay',
|
||||
selectedRelay: 'Relay da aka zaɓa',
|
||||
nostrGitServers: 'Sabar Git na Nostr',
|
||||
addServer: 'Ƙara Sabar',
|
||||
serverHostname: 'Sunan Sabar',
|
||||
enterHostname: 'Shigar da sunan mai masaukin baki (misali: git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: 'Clone repository na Git zuwa wurin aikin Shakespeare',
|
||||
@@ -1611,6 +1627,10 @@ const resources = {
|
||||
addAccount: 'Fi Akọọlẹ kun',
|
||||
relayConfiguration: 'Iṣeto Relay',
|
||||
selectedRelay: 'Relay Ti a Yan',
|
||||
nostrGitServers: 'Awọn olupin Git Nostr',
|
||||
addServer: 'Fi Olupin kun',
|
||||
serverHostname: 'Orukọ Olupin',
|
||||
enterHostname: 'Tẹ orukọ ile-ipamọ sii (fun apẹẹrẹ: git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: 'Clone repository Git si aaye iṣẹ Shakespeare rẹ',
|
||||
@@ -1932,6 +1952,10 @@ const resources = {
|
||||
addAccount: 'Tinye Akaụntụ',
|
||||
relayConfiguration: 'Nhazi Relay',
|
||||
selectedRelay: 'Relay Ahọrọ',
|
||||
nostrGitServers: 'Ndị sava Git Nostr',
|
||||
addServer: 'Tinye Sava',
|
||||
serverHostname: 'Aha Sava',
|
||||
enterHostname: 'Tinye aha ọbịa (ọmụmaatụ: git.shakespeare.diy)',
|
||||
|
||||
// Clone Page
|
||||
cloneGitRepository: 'Clone repository Git n\'ogige ọrụ Shakespeare gị',
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { ArrowLeft, Wifi, Users, UserPlus, LogOut, Trash2, User, Plus } from 'lucide-react';
|
||||
import { ArrowLeft, Wifi, Users, UserPlus, LogOut, Trash2, User, Plus, Server, X } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { RelaySelector } from '@/components/RelaySelector';
|
||||
@@ -13,6 +14,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts';
|
||||
import { genUserName } from '@/lib/genUserName';
|
||||
import { useState } from 'react';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
export function NostrSettings() {
|
||||
const { t } = useTranslation();
|
||||
@@ -21,6 +23,8 @@ export function NostrSettings() {
|
||||
const { authors, currentUser, setLogin, removeLogin, isLoading } = useLoggedInAccounts();
|
||||
const [showLoginDialog, setShowLoginDialog] = useState(false);
|
||||
const [showSignupDialog, setShowSignupDialog] = useState(false);
|
||||
const { config, updateConfig } = useAppContext();
|
||||
const [newServerHostname, setNewServerHostname] = useState('');
|
||||
|
||||
const handleSwitchAccount = (accountId: string) => {
|
||||
setLogin(accountId);
|
||||
@@ -42,6 +46,30 @@ export function NostrSettings() {
|
||||
return account.metadata?.name ?? genUserName(account.pubkey);
|
||||
};
|
||||
|
||||
const handleAddServer = () => {
|
||||
const hostname = newServerHostname.trim();
|
||||
if (!hostname) return;
|
||||
|
||||
// Basic validation - check if it's a valid hostname format
|
||||
if (!/^[a-zA-Z0-9][a-zA-Z0-9-_.]*[a-zA-Z0-9]$/.test(hostname)) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
ngitServers: [...(current.ngitServers ?? config.ngitServers), hostname],
|
||||
}));
|
||||
|
||||
setNewServerHostname('');
|
||||
};
|
||||
|
||||
const handleRemoveServer = (hostname: string) => {
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
ngitServers: (current.ngitServers ?? config.ngitServers).filter(s => s !== hostname),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
{isMobile && (
|
||||
@@ -202,6 +230,71 @@ export function NostrSettings() {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Nostr Git Servers */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Server className="h-5 w-5" />
|
||||
{t('nostrGitServers')}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
{/* Server List */}
|
||||
<div className="space-y-2">
|
||||
{config.ngitServers.map((hostname) => (
|
||||
<div
|
||||
key={hostname}
|
||||
className="flex items-center gap-2 p-2 rounded-md border bg-muted/20"
|
||||
>
|
||||
<Server className="h-4 w-4 text-muted-foreground shrink-0" />
|
||||
<span className="font-mono text-sm flex-1 truncate">
|
||||
{hostname}
|
||||
</span>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => handleRemoveServer(hostname)}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive hover:bg-transparent shrink-0"
|
||||
disabled={config.ngitServers.length <= 1}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Add Server Form */}
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1">
|
||||
<Label htmlFor="new-server-hostname" className="sr-only">
|
||||
{t('serverHostname')}
|
||||
</Label>
|
||||
<Input
|
||||
id="new-server-hostname"
|
||||
placeholder={t('enterHostname')}
|
||||
value={newServerHostname}
|
||||
onChange={(e) => setNewServerHostname(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleAddServer();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddServer}
|
||||
disabled={!newServerHostname.trim()}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-10 shrink-0"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
{t('addServer')}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Login Dialog */}
|
||||
|
||||
@@ -38,6 +38,7 @@ export function TestApp({ children }: TestAppProps) {
|
||||
language: 'en',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
};
|
||||
|
||||
// Initialize LightningFS for testing
|
||||
|
||||
Reference in new issue
Block a user