mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
nsite deployment works!
This commit is contained in:
7 files changed
+71
-44
No files matched your search
@@ -270,13 +270,12 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'nsite') {
|
||||
const nsiteProvider = selectedProvider as import('@/contexts/DeploySettingsContext').NsiteProvider;
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedNsec = savedConfig?.type === 'nsite' ? savedConfig.data.nsec : undefined;
|
||||
|
||||
return (
|
||||
<NsiteDeployForm
|
||||
gateway={nsiteProvider.gateway}
|
||||
gateway={selectedProvider.gateway}
|
||||
savedNsec={savedNsec}
|
||||
onNsecChange={handleNsiteNsecChange}
|
||||
/>
|
||||
@@ -284,19 +283,18 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'netlify') {
|
||||
const netlifyProvider = selectedProvider as NetlifyProvider;
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedSiteId = savedConfig?.type === 'netlify' ? savedConfig.data.siteId : undefined;
|
||||
|
||||
return (
|
||||
<NetlifyDeployForm
|
||||
apiKey={netlifyProvider.apiKey}
|
||||
baseURL={netlifyProvider.baseURL}
|
||||
apiKey={selectedProvider.apiKey}
|
||||
baseURL={selectedProvider.baseURL}
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
savedSiteId={savedSiteId}
|
||||
onSiteChange={handleNetlifySiteChange}
|
||||
corsProxy={netlifyProvider.proxy ? config.corsProxy : undefined}
|
||||
corsProxy={selectedProvider.proxy ? config.corsProxy : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { Label } from '@/components/ui/label';
|
||||
@@ -19,16 +19,24 @@ export function NsiteDeployForm({
|
||||
}: NsiteDeployFormProps) {
|
||||
const [nsec, setNsec] = useState(savedNsec || '');
|
||||
const [npub, setNpub] = useState('');
|
||||
const initialized = useRef(false);
|
||||
|
||||
// Generate a new nsec if none exists
|
||||
// Initialize nsec on mount
|
||||
useEffect(() => {
|
||||
if (!nsec) {
|
||||
const sk = generateSecretKey();
|
||||
const newNsec = nip19.nsecEncode(sk);
|
||||
setNsec(newNsec);
|
||||
onNsecChange(newNsec);
|
||||
if (!initialized.current) {
|
||||
initialized.current = true;
|
||||
if (savedNsec) {
|
||||
// If we have a saved nsec, notify parent immediately
|
||||
onNsecChange(savedNsec);
|
||||
} else if (!nsec) {
|
||||
// Generate a new nsec if none exists
|
||||
const sk = generateSecretKey();
|
||||
const newNsec = nip19.nsecEncode(sk);
|
||||
setNsec(newNsec);
|
||||
onNsecChange(newNsec);
|
||||
}
|
||||
}
|
||||
}, [nsec, onNsecChange]);
|
||||
}, [savedNsec, nsec, onNsecChange]);
|
||||
|
||||
// Update npub when nsec changes
|
||||
useEffect(() => {
|
||||
|
||||
@@ -71,10 +71,18 @@ const vercelProviderSchema = baseDeployProviderSchema.extend({
|
||||
baseURL: z.string().optional(),
|
||||
});
|
||||
|
||||
const nsiteProviderSchema = baseDeployProviderSchema.extend({
|
||||
type: z.literal('nsite'),
|
||||
gateway: z.string(),
|
||||
relayUrls: z.array(z.string()),
|
||||
blossomServers: z.array(z.string()),
|
||||
});
|
||||
|
||||
const deployProviderSchema: z.ZodType<DeployProvider> = z.discriminatedUnion('type', [
|
||||
shakespeareDeployProviderSchema,
|
||||
netlifyProviderSchema,
|
||||
vercelProviderSchema,
|
||||
nsiteProviderSchema,
|
||||
]);
|
||||
|
||||
const deploySettingsSchema = z.object({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BlossomUploader } from '@nostrify/nostrify/uploaders';
|
||||
import { NSecSigner, NPool } from '@nostrify/nostrify';
|
||||
import type { NostrEvent } from '@nostrify/nostrify';
|
||||
import mime from 'mime';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, NsiteDeployConfig } from './types';
|
||||
@@ -58,16 +59,15 @@ export class NsiteAdapter implements DeployAdapter {
|
||||
const fileEvents: NostrEvent[] = [];
|
||||
await this.uploadDirectory(distPath, '', uploader, signer, fileEvents);
|
||||
|
||||
// Publish all file events to the relays
|
||||
for (const event of fileEvents) {
|
||||
await relayClient.event(event, { signal: AbortSignal.timeout(5000) });
|
||||
}
|
||||
|
||||
// Publish kind 10063 server list if not already published
|
||||
await this.publishServerList(pubkey, signer, relayClient);
|
||||
// Publish file events and other metadata to the relays
|
||||
await Promise.all([
|
||||
this.publishRelayList(signer, relayClient),
|
||||
this.publishServerList(signer, relayClient),
|
||||
...fileEvents.map(event => relayClient.event(event, { signal: AbortSignal.timeout(5000) })),
|
||||
]);
|
||||
|
||||
// Generate npub subdomain
|
||||
const npub = this.pubkeyToNpub(pubkey);
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
const siteUrl = `https://${npub}.${this.gateway}`;
|
||||
|
||||
return {
|
||||
@@ -114,7 +114,9 @@ export class NsiteAdapter implements DeployAdapter {
|
||||
const content = await this.fs.readFile(filePath);
|
||||
|
||||
// Convert to File object for upload
|
||||
const file = new File([content], relativePath.split('/').pop() || 'file');
|
||||
const file = new File([content], relativePath.split('/').pop() || 'file', {
|
||||
type: mime.getType(filePath) || undefined,
|
||||
});
|
||||
|
||||
// Upload to Blossom and get tags
|
||||
const tags = await uploader.upload(file);
|
||||
@@ -148,20 +150,18 @@ export class NsiteAdapter implements DeployAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private async publishServerList(pubkey: string, signer: NSecSigner, relayClient: NPool): Promise<void> {
|
||||
// Check if server list already exists
|
||||
const events = await relayClient.query([{
|
||||
kinds: [10063],
|
||||
authors: [pubkey],
|
||||
limit: 1,
|
||||
}], { signal: AbortSignal.timeout(5000) });
|
||||
private async publishRelayList(signer: NSecSigner, relayClient: NPool): Promise<void> {
|
||||
const relayListEvent = await signer.signEvent({
|
||||
kind: 10002,
|
||||
content: '',
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: this.relayUrls.map(url => ['r', url]),
|
||||
});
|
||||
|
||||
// If server list exists, don't publish a new one
|
||||
if (events.length > 0) {
|
||||
return;
|
||||
}
|
||||
await relayClient.event(relayListEvent, { signal: AbortSignal.timeout(5000) });
|
||||
}
|
||||
|
||||
// Create kind 10063 server list event
|
||||
private async publishServerList(signer: NSecSigner, relayClient: NPool): Promise<void> {
|
||||
const serverListEvent = await signer.signEvent({
|
||||
kind: 10063,
|
||||
content: '',
|
||||
@@ -171,8 +171,4 @@ export class NsiteAdapter implements DeployAdapter {
|
||||
|
||||
await relayClient.event(serverListEvent, { signal: AbortSignal.timeout(5000) });
|
||||
}
|
||||
|
||||
private pubkeyToNpub(pubkey: string): string {
|
||||
return nip19.npubEncode(pubkey);
|
||||
}
|
||||
}
|
||||
@@ -349,18 +349,18 @@ export function DeploySettings() {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
name: preset.name,
|
||||
type: 'nsite',
|
||||
gateway: 'nsite.lol',
|
||||
gateway: 'nosto.re',
|
||||
relayUrls: [
|
||||
'wss://relay.nsite.lol',
|
||||
'wss://relay.nosto.re',
|
||||
'wss://purplerelay.com',
|
||||
'wss://relay.nostr.band',
|
||||
'wss://relay.primal.net',
|
||||
'wss://relay.damus.io',
|
||||
'wss://purplerelay.com',
|
||||
],
|
||||
blossomServers: [
|
||||
'https://blossom.primal.net/',
|
||||
'https://blossom.band/',
|
||||
'https://cdn.sovbit.host/',
|
||||
'https://blossom.primal.net',
|
||||
'https://cdn.sovbit.host',
|
||||
],
|
||||
};
|
||||
} else if (preset.type === 'netlify') {
|
||||
|
||||
Reference in new issue
Block a user