mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Deploy to the gateway that actually serves shakespeare.wtf now
Shakespeare Deploy uploaded a zip to a host that kept the files itself. That host has been replaced: those domains are served out of nsite manifests, so a deploy through the old API has been succeeding and changing nothing anyone can see. This replaces it. NpanelAdapter is NsiteAdapter plus a name. The site is an ordinary nsite under the user's own key — same event, readable by any nsite client, gateway or no gateway — and the second half of the deploy asks the gateway to point a hostname at it. Its predecessor claimed names implicitly, by watching relays and reserving whichever d tag it saw first; this one keeps an explicit row, which is what makes a name something its owner holds rather than something they won a race for. The hostname is asked about before it is claimed, because "nobody holds this", "I already hold this" and "somebody else holds this" are three different acts and creating-then-reading-the-409 cannot tell the last two apart. The name field checks availability as you type, against an endpoint that takes no credentials: somebody choosing a name has not decided to make an account yet. A name this project already deployed to is not reported as taken — it is theirs. An unreachable gateway reports available, because being wrong that way costs a clear error at deploy time, and being wrong the other way tells someone a free name is taken and they settle for worse. Also fixes readDeploySettings, which swallowed a missing file and an unreadable one alike and answered "no providers" to both. The default provider it was meant to hand new users had therefore never reached anybody: it was written, saved back as an empty list on the next render, and gone. The two cases are now distinct, because inventing defaults for a file that exists but will not parse would silently replace whatever the user had. Providers and per-project deploy records saved under the old type are migrated on load rather than dropped. The project file holds one record per provider a project ever deployed to, so rejecting one entry would take a Netlify site id and a Vercel project id with it. Verified end to end against the live gateway: a fresh key self-enrolled, uploaded a blob, published a manifest, claimed a name, and the site served publicly with the SPA fallback working on a deep path. The package-lock version bump is npm reconciling it with package.json, which had drifted before this work.
This commit is contained in:
19 files changed
+1083
-353
No files matched your search
@@ -23,7 +23,7 @@ import {
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import type {
|
||||
ShakespeareDeployProvider,
|
||||
NpanelProvider,
|
||||
NetlifyProvider,
|
||||
VercelProvider,
|
||||
NsiteProvider,
|
||||
@@ -34,7 +34,7 @@ import type {
|
||||
|
||||
// Type for provider without the 'id' field (will be generated)
|
||||
type DeployProviderInput =
|
||||
| Omit<ShakespeareDeployProvider, 'id'>
|
||||
| Omit<NpanelProvider, 'id'>
|
||||
| Omit<NetlifyProvider, 'id'>
|
||||
| Omit<VercelProvider, 'id'>
|
||||
| Omit<NsiteProvider, 'id'>
|
||||
@@ -54,14 +54,14 @@ export function AddCustomProviderDialog({
|
||||
onAdd,
|
||||
}: AddCustomProviderDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway' | ''>('');
|
||||
const [customProviderType, setCustomProviderType] = useState<'npanel' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway' | ''>('');
|
||||
const [customName, setCustomName] = useState('');
|
||||
const [customApiKey, setCustomApiKey] = useState('');
|
||||
const [customAccountId, setCustomAccountId] = useState('');
|
||||
const [customOrganizationId, setCustomOrganizationId] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
const [customBaseDomain, setCustomBaseDomain] = useState('');
|
||||
const [customHost, setCustomHost] = useState('');
|
||||
const [customDashboardHost, setCustomDashboardHost] = useState('');
|
||||
const [customProxy, setCustomProxy] = useState(false);
|
||||
const [customGateway, setCustomGateway] = useState('');
|
||||
const [customRelayUrls, setCustomRelayUrls] = useState<string[]>([]);
|
||||
@@ -73,12 +73,15 @@ export function AddCustomProviderDialog({
|
||||
// Build provider object based on type
|
||||
let provider: DeployProviderInput;
|
||||
|
||||
if (customProviderType === 'shakespeare') {
|
||||
if (customProviderType === 'npanel') {
|
||||
if (!customDashboardHost.trim() || !customGateway.trim()) return;
|
||||
provider = {
|
||||
type: 'shakespeare',
|
||||
type: 'npanel',
|
||||
name: customName.trim(),
|
||||
...(customHost?.trim() && { host: customHost.trim() }),
|
||||
...(customProxy && { proxy: true }),
|
||||
dashboardHost: customDashboardHost.trim(),
|
||||
domain: customGateway.trim(),
|
||||
relayUrls: customRelayUrls.length > 0 ? customRelayUrls : ['wss://relay.ditto.pub'],
|
||||
blossomServers: customBlossomServers.length > 0 ? customBlossomServers : ['https://blossom.ditto.pub/', 'https://blossom.dreamith.to/'],
|
||||
};
|
||||
} else if (customProviderType === 'nsite') {
|
||||
provider = {
|
||||
@@ -151,7 +154,7 @@ export function AddCustomProviderDialog({
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomBaseDomain('');
|
||||
setCustomHost('');
|
||||
setCustomDashboardHost('');
|
||||
setCustomProxy(false);
|
||||
setCustomGateway('');
|
||||
setCustomRelayUrls([]);
|
||||
@@ -160,12 +163,22 @@ export function AddCustomProviderDialog({
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const isValid = customProviderType && customName.trim() &&
|
||||
(customProviderType === 'shakespeare' || customProviderType === 'nsite' ||
|
||||
(customApiKey.trim() &&
|
||||
(customProviderType !== 'cloudflare' || customAccountId.trim()) &&
|
||||
(customProviderType !== 'deno' || customOrganizationId.trim()) &&
|
||||
(customProviderType !== 'railway' || true)));
|
||||
const hasRequiredFields = () => {
|
||||
// A gateway is named by two hosts and reached with a Nostr key, so there is
|
||||
// no API key to ask for — but it cannot be guessed at either.
|
||||
if (customProviderType === 'npanel') {
|
||||
return Boolean(customDashboardHost.trim() && customGateway.trim());
|
||||
}
|
||||
// Plain nsite needs nothing beyond a name: it has defaults for the rest.
|
||||
if (customProviderType === 'nsite') return true;
|
||||
|
||||
if (!customApiKey.trim()) return false;
|
||||
if (customProviderType === 'cloudflare') return Boolean(customAccountId.trim());
|
||||
if (customProviderType === 'deno') return Boolean(customOrganizationId.trim());
|
||||
return true;
|
||||
};
|
||||
|
||||
const isValid = Boolean(customProviderType && customName.trim() && hasRequiredFields());
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
@@ -184,7 +197,7 @@ export function AddCustomProviderDialog({
|
||||
</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway') => {
|
||||
onValueChange={(value: 'npanel' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno' | 'railway') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
@@ -192,7 +205,7 @@ export function AddCustomProviderDialog({
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomBaseDomain('');
|
||||
setCustomHost('');
|
||||
setCustomDashboardHost('');
|
||||
setCustomProxy(false);
|
||||
setCustomGateway('');
|
||||
setCustomRelayUrls([]);
|
||||
@@ -203,7 +216,7 @@ export function AddCustomProviderDialog({
|
||||
<SelectValue placeholder={t('selectProviderType')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="shakespeare">Shakespeare Deploy</SelectItem>
|
||||
<SelectItem value="npanel">nsite gateway</SelectItem>
|
||||
<SelectItem value="nsite">nsite</SelectItem>
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
@@ -228,20 +241,53 @@ export function AddCustomProviderDialog({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{customProviderType === 'shakespeare' ? (
|
||||
{customProviderType === 'npanel' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('shakespeareDeployNostrAuth')}
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-host">Host (Optional)</Label>
|
||||
<Label htmlFor="custom-domain">
|
||||
Domain <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-host"
|
||||
id="custom-domain"
|
||||
placeholder="shakespeare.wtf"
|
||||
value={customHost}
|
||||
onChange={(e) => setCustomHost(e.target.value)}
|
||||
value={customGateway}
|
||||
onChange={(e) => setCustomGateway(e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sites get a name under this domain.
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-dashboard-host">
|
||||
Gateway API <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-dashboard-host"
|
||||
placeholder="npanel.shakespeare.to"
|
||||
value={customDashboardHost}
|
||||
onChange={(e) => setCustomDashboardHost(e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Where names are claimed. Usually a different host from the one above.
|
||||
</p>
|
||||
</div>
|
||||
<UrlListEditor
|
||||
label="Relay URLs"
|
||||
items={customRelayUrls}
|
||||
onChange={setCustomRelayUrls}
|
||||
protocol="wss"
|
||||
placeholder="relay.ditto.pub"
|
||||
/>
|
||||
<UrlListEditor
|
||||
label="Blossom Servers"
|
||||
items={customBlossomServers}
|
||||
onChange={setCustomBlossomServers}
|
||||
protocol="https"
|
||||
placeholder="blossom.ditto.pub"
|
||||
/>
|
||||
</>
|
||||
) : customProviderType === 'nsite' ? (
|
||||
<>
|
||||
|
||||
@@ -3,10 +3,10 @@ import { DeploySettingsContext, type DeploySettings, type DeployProvider } from
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { readDeploySettings, writeDeploySettings } from '@/lib/configUtils';
|
||||
import { DEFAULT_NSITE_PROVIDER } from '@/lib/deployProviderPresets';
|
||||
import { DEFAULT_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets';
|
||||
|
||||
const DEFAULT_SETTINGS: DeploySettings = {
|
||||
providers: [DEFAULT_NSITE_PROVIDER],
|
||||
providers: [...DEFAULT_DEPLOY_PROVIDERS],
|
||||
};
|
||||
|
||||
export function DeploySettingsProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
@@ -74,10 +74,8 @@ export function ProviderConfigDialog({
|
||||
// Use baseURL from configured provider, falling back to preset baseURL
|
||||
const baseURL = ('baseURL' in localProvider && localProvider.baseURL) || preset?.baseURL;
|
||||
|
||||
// For Shakespeare, special handling for host field
|
||||
const shakespeareUrl = localProvider.type === 'shakespeare' && 'host' in localProvider && localProvider.host
|
||||
? normalizeUrl(localProvider.host)
|
||||
: undefined;
|
||||
// A gateway is recognised by the domain it serves, not by its API origin
|
||||
const gatewayUrl = localProvider.type === 'npanel' ? normalizeUrl(localProvider.domain) : undefined;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
@@ -85,7 +83,7 @@ export function ProviderConfigDialog({
|
||||
<DialogHeader>
|
||||
<div className="flex items-center gap-2">
|
||||
<ExternalFavicon
|
||||
url={shakespeareUrl || baseURL}
|
||||
url={gatewayUrl || baseURL}
|
||||
size={20}
|
||||
fallback={<Rocket size={20} />}
|
||||
/>
|
||||
@@ -109,22 +107,55 @@ export function ProviderConfigDialog({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{localProvider.type === 'shakespeare' ? (
|
||||
{localProvider.type === 'npanel' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('shakespeareDeployNostrAuth')}
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="provider-host">
|
||||
Host (Optional)
|
||||
<Label htmlFor="provider-domain">
|
||||
Domain <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="provider-host"
|
||||
id="provider-domain"
|
||||
placeholder="shakespeare.wtf"
|
||||
value={localProvider.host || ''}
|
||||
onChange={(e) => setLocalProvider({ ...localProvider, host: e.target.value })}
|
||||
value={localProvider.domain}
|
||||
onChange={(e) => setLocalProvider({ ...localProvider, domain: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Sites get a name under this domain.
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="provider-dashboard-host">
|
||||
Gateway API <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="provider-dashboard-host"
|
||||
placeholder="npanel.shakespeare.to"
|
||||
value={localProvider.dashboardHost}
|
||||
onChange={(e) => setLocalProvider({ ...localProvider, dashboardHost: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Where names are claimed. Usually a different host from the one above.
|
||||
</p>
|
||||
</div>
|
||||
<UrlListEditor
|
||||
label="Relay URLs"
|
||||
items={localProvider.relayUrls ?? []}
|
||||
onChange={(urls) => setLocalProvider({ ...localProvider, relayUrls: urls })}
|
||||
protocol="wss"
|
||||
placeholder="relay.ditto.pub"
|
||||
required
|
||||
/>
|
||||
<UrlListEditor
|
||||
label="Blossom Servers"
|
||||
items={localProvider.blossomServers ?? []}
|
||||
onChange={(servers) => setLocalProvider({ ...localProvider, blossomServers: servers })}
|
||||
protocol="https"
|
||||
placeholder="blossom.ditto.pub"
|
||||
required
|
||||
/>
|
||||
</>
|
||||
) : localProvider.type === 'nsite' ? (
|
||||
<>
|
||||
|
||||
@@ -20,7 +20,7 @@ import { Link } from 'react-router-dom';
|
||||
import type { DeployProvider } from '@/contexts/DeploySettingsContext';
|
||||
import type { PresetDeployProvider } from '@/lib/deploy/types';
|
||||
import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets';
|
||||
import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm';
|
||||
import { NpanelDeployForm } from '@/components/deploy/NpanelDeployForm';
|
||||
import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm';
|
||||
import { VercelDeployForm } from '@/components/deploy/VercelDeployForm';
|
||||
import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm';
|
||||
@@ -29,7 +29,7 @@ import { DenoDeployForm } from '@/components/deploy/DenoDeployForm';
|
||||
import { RailwayDeployForm } from '@/components/deploy/RailwayDeployForm';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { DeployAdapter } from '@/lib/deploy/types';
|
||||
import { ShakespeareAdapter } from '@/lib/deploy/ShakespeareAdapter';
|
||||
import { NpanelAdapter } from '@/lib/deploy/NpanelAdapter';
|
||||
import { NsiteAdapter } from '@/lib/deploy/NsiteAdapter';
|
||||
import { NetlifyAdapter } from '@/lib/deploy/NetlifyAdapter';
|
||||
import { VercelAdapter } from '@/lib/deploy/VercelAdapter';
|
||||
@@ -74,12 +74,11 @@ function renderProviderIcon(provider: DeployProvider, preset: PresetDeployProvid
|
||||
// Use baseURL from configured provider, falling back to preset baseURL
|
||||
const baseURL = ('baseURL' in provider && provider.baseURL) || preset?.baseURL;
|
||||
|
||||
// For Shakespeare, special handling for host field
|
||||
const shakespeareUrl = provider.type === 'shakespeare' && 'host' in provider && provider.host
|
||||
? normalizeUrl(provider.host)
|
||||
: undefined;
|
||||
// A gateway is recognised by the domain it serves, not by its API origin —
|
||||
// that is the name the user picked it for and the one with an icon.
|
||||
const gatewayUrl = provider.type === 'npanel' ? normalizeUrl(provider.domain) : undefined;
|
||||
|
||||
const url = shakespeareUrl || baseURL;
|
||||
const url = gatewayUrl || baseURL;
|
||||
|
||||
if (url) {
|
||||
return (
|
||||
@@ -100,8 +99,10 @@ interface DeployStepsProps {
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
interface ShakespeareFormData {
|
||||
interface NpanelFormData {
|
||||
subdomain: string;
|
||||
siteTitle: string;
|
||||
siteDescription: string;
|
||||
}
|
||||
|
||||
interface NsiteFormData {
|
||||
@@ -152,7 +153,7 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
const [isDeploying, setIsDeploying] = useState(false);
|
||||
const [deployResult, setDeployResult] = useState<{ url: string } | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isShakespeareFormValid, setIsShakespeareFormValid] = useState(true);
|
||||
const [isNpanelFormValid, setIsNpanelFormValid] = useState(true);
|
||||
|
||||
// .nsite/config.json state — loaded once on mount, used to skip config form on re-deploy
|
||||
const [nsiteVfsConfig, setNsiteVfsConfig] = useState<NsiteVfsConfig | null>(null);
|
||||
@@ -187,8 +188,10 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
}, [fs, projectsPath, projectId]);
|
||||
|
||||
// Provider-specific form data
|
||||
const [shakespeareForm, setShakespeareForm] = useState<ShakespeareFormData>({
|
||||
const [npanelForm, setNpanelForm] = useState<NpanelFormData>({
|
||||
subdomain: projectId,
|
||||
siteTitle: projectName || projectId,
|
||||
siteDescription: '',
|
||||
});
|
||||
const [nsiteForm, setNsiteForm] = useState<NsiteFormData>({
|
||||
siteTitle: '',
|
||||
@@ -245,18 +248,36 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
|
||||
let adapter: DeployAdapter;
|
||||
|
||||
if (selectedProvider.type === 'shakespeare') {
|
||||
if (selectedProvider.type === 'npanel') {
|
||||
if (!user) {
|
||||
throw new Error('You must be logged in with Nostr to use Shakespeare Deploy');
|
||||
throw new Error('You must be logged in with Nostr to deploy here.');
|
||||
}
|
||||
|
||||
const shakespeareProvider = selectedProvider;
|
||||
adapter = new ShakespeareAdapter({
|
||||
const npanelProvider = selectedProvider;
|
||||
const subdomain = npanelForm.subdomain.trim();
|
||||
if (!subdomain) {
|
||||
throw new Error('Choose an address for this site.');
|
||||
}
|
||||
|
||||
const sourceUrl = await resolveNsiteSourceUrl(
|
||||
await git.getRemoteURL(projectPath, 'origin')
|
||||
);
|
||||
|
||||
adapter = new NpanelAdapter({
|
||||
fs,
|
||||
nostr,
|
||||
signer: user.signer,
|
||||
host: shakespeareProvider.host,
|
||||
subdomain: shakespeareForm.subdomain || undefined,
|
||||
corsProxy: shakespeareProvider.proxy ? config.corsProxy : undefined,
|
||||
dashboardHost: npanelProvider.dashboardHost,
|
||||
domain: npanelProvider.domain,
|
||||
subdomain,
|
||||
// The gateway serves the site, so it is also the gateway whose URL the
|
||||
// underlying nsite deploy reports.
|
||||
gateway: npanelProvider.domain,
|
||||
relayUrls: npanelProvider.relayUrls,
|
||||
blossomServers: npanelProvider.blossomServers,
|
||||
siteTitle: npanelForm.siteTitle || undefined,
|
||||
siteDescription: npanelForm.siteDescription || undefined,
|
||||
sourceUrl,
|
||||
});
|
||||
} else if (selectedProvider.type === 'nsite') {
|
||||
const nsiteProvider = selectedProvider;
|
||||
@@ -375,12 +396,14 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
});
|
||||
|
||||
// Save project-specific settings (updateSettings now automatically sets currentProvider)
|
||||
if (selectedProvider.type === 'shakespeare') {
|
||||
if (selectedProvider.type === 'npanel') {
|
||||
await updateProjectSettings(selectedProviderId, {
|
||||
type: 'shakespeare',
|
||||
type: 'npanel',
|
||||
url: result.url,
|
||||
data: {
|
||||
subdomain: shakespeareForm.subdomain || undefined,
|
||||
subdomain: npanelForm.subdomain.trim() || undefined,
|
||||
siteTitle: npanelForm.siteTitle || undefined,
|
||||
siteDescription: npanelForm.siteDescription || undefined,
|
||||
},
|
||||
});
|
||||
} else if (selectedProvider.type === 'nsite') {
|
||||
@@ -516,7 +539,7 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
setDeployResult(null);
|
||||
setError(null);
|
||||
// Reset forms
|
||||
setShakespeareForm({ subdomain: projectId });
|
||||
setNpanelForm({ subdomain: projectId, siteTitle: projectName || projectId, siteDescription: '' });
|
||||
setNsiteForm({ siteTitle: '', siteDescription: '', dTag: '' });
|
||||
setNetlifyForm({ siteId: '', siteName: '' });
|
||||
setVercelForm({ projectName: projectName || projectId, teamId: '' });
|
||||
@@ -528,12 +551,20 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleShakespeareSubdomainChange = useCallback((subdomain: string) => {
|
||||
setShakespeareForm({ subdomain });
|
||||
const handleNpanelSubdomainChange = useCallback((subdomain: string) => {
|
||||
setNpanelForm(prev => ({ ...prev, subdomain }));
|
||||
}, []);
|
||||
|
||||
const handleShakespeareValidationChange = useCallback((isValid: boolean) => {
|
||||
setIsShakespeareFormValid(isValid);
|
||||
const handleNpanelSiteTitleChange = useCallback((siteTitle: string) => {
|
||||
setNpanelForm(prev => ({ ...prev, siteTitle }));
|
||||
}, []);
|
||||
|
||||
const handleNpanelSiteDescriptionChange = useCallback((siteDescription: string) => {
|
||||
setNpanelForm(prev => ({ ...prev, siteDescription }));
|
||||
}, []);
|
||||
|
||||
const handleNpanelValidationChange = useCallback((isValid: boolean) => {
|
||||
setIsNpanelFormValid(isValid);
|
||||
}, []);
|
||||
|
||||
const handleNsiteSiteTitleChange = useCallback((siteTitle: string) => {
|
||||
@@ -578,18 +609,24 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
const renderProviderFields = () => {
|
||||
if (!selectedProvider) return null;
|
||||
|
||||
if (selectedProvider.type === 'shakespeare') {
|
||||
const shakespeareProvider = selectedProvider;
|
||||
if (selectedProvider.type === 'npanel') {
|
||||
const npanelProvider = selectedProvider;
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedSubdomain = savedConfig?.type === 'shakespeare' ? savedConfig.data.subdomain : undefined;
|
||||
const saved = savedConfig?.type === 'npanel' ? savedConfig.data : undefined;
|
||||
|
||||
return (
|
||||
<ShakespeareDeployForm
|
||||
host={shakespeareProvider.host}
|
||||
<NpanelDeployForm
|
||||
dashboardHost={npanelProvider.dashboardHost}
|
||||
domain={npanelProvider.domain}
|
||||
projectId={projectId}
|
||||
savedSubdomain={savedSubdomain}
|
||||
onSubdomainChange={handleShakespeareSubdomainChange}
|
||||
onValidationChange={handleShakespeareValidationChange}
|
||||
projectName={projectName}
|
||||
savedSubdomain={saved?.subdomain}
|
||||
savedSiteTitle={saved?.siteTitle}
|
||||
savedSiteDescription={saved?.siteDescription}
|
||||
onSubdomainChange={handleNpanelSubdomainChange}
|
||||
onSiteTitleChange={handleNpanelSiteTitleChange}
|
||||
onSiteDescriptionChange={handleNpanelSiteDescriptionChange}
|
||||
onValidationChange={handleNpanelValidationChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -906,11 +943,11 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
|
||||
{selectedProvider && renderProviderFields()}
|
||||
|
||||
{selectedProvider?.type === 'shakespeare' && !user && (
|
||||
{selectedProvider?.type === 'npanel' && !user && (
|
||||
<Alert>
|
||||
<AlertCircle className="h-4 w-4" />
|
||||
<AlertDescription>
|
||||
You must be logged in with Nostr to use Shakespeare Deploy.{' '}
|
||||
You must be logged in with Nostr to publish a site.{' '}
|
||||
<Link
|
||||
to="/settings/nostr"
|
||||
className="underline hover:no-underline"
|
||||
@@ -950,8 +987,8 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
|
||||
onClick={handleDeploy}
|
||||
disabled={
|
||||
isDeploying ||
|
||||
(selectedProvider.type === 'shakespeare' && !user) ||
|
||||
(selectedProvider.type === 'shakespeare' && !isShakespeareFormValid) ||
|
||||
(selectedProvider.type === 'npanel' && !user) ||
|
||||
(selectedProvider.type === 'npanel' && !isNpanelFormValid) ||
|
||||
(selectedProvider.type === 'nsite' && !user) ||
|
||||
(selectedProvider.type === 'nsite' && !nsiteForm.dTag) ||
|
||||
(selectedProvider.type === 'netlify' && !netlifyForm.siteId && !netlifyForm.siteName) ||
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
import { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { AlertCircle, Check, Loader2 } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { checkNameAvailable, type NameAvailability } from '@/lib/deploy/NpanelAdapter';
|
||||
|
||||
/** How long typing has to stop before the gateway is asked about a name. */
|
||||
const AVAILABILITY_DEBOUNCE_MS = 400;
|
||||
|
||||
interface NpanelDeployFormProps {
|
||||
/** The gateway's API origin, e.g. `npanel.shakespeare.to`. */
|
||||
dashboardHost: string;
|
||||
/** The domain sites are served under, e.g. `shakespeare.wtf`. */
|
||||
domain: string;
|
||||
/** Falls back to the project id when nothing has been deployed yet. */
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
savedSubdomain?: string;
|
||||
savedSiteTitle?: string;
|
||||
savedSiteDescription?: string;
|
||||
onSubdomainChange: (subdomain: string) => void;
|
||||
onSiteTitleChange: (title: string) => void;
|
||||
onSiteDescriptionChange: (description: string) => void;
|
||||
onValidationChange?: (isValid: boolean) => void;
|
||||
}
|
||||
|
||||
/** What the field is currently saying about the name in it. */
|
||||
type NameState =
|
||||
| { kind: 'empty' }
|
||||
| { kind: 'mine' }
|
||||
| { kind: 'checking' }
|
||||
| { kind: 'free' }
|
||||
| { kind: 'unavailable'; message: string };
|
||||
|
||||
function describe(availability: NameAvailability, domain: string): NameState {
|
||||
if (availability.available) return { kind: 'free' };
|
||||
|
||||
if (availability.reason === 'taken') {
|
||||
return { kind: 'unavailable', message: `That name is taken on ${domain}. Try another.` };
|
||||
}
|
||||
|
||||
return { kind: 'unavailable', message: availability.error ?? 'That name cannot be used.' };
|
||||
}
|
||||
|
||||
export function NpanelDeployForm({
|
||||
dashboardHost,
|
||||
domain,
|
||||
projectId,
|
||||
projectName,
|
||||
savedSubdomain,
|
||||
savedSiteTitle,
|
||||
savedSiteDescription,
|
||||
onSubdomainChange,
|
||||
onSiteTitleChange,
|
||||
onSiteDescriptionChange,
|
||||
onValidationChange,
|
||||
}: NpanelDeployFormProps) {
|
||||
const [subdomain, setSubdomain] = useState(savedSubdomain || projectId);
|
||||
const [siteTitle, setSiteTitle] = useState(savedSiteTitle ?? projectName);
|
||||
const [siteDescription, setSiteDescription] = useState(savedSiteDescription ?? '');
|
||||
const [nameState, setNameState] = useState<NameState>({ kind: 'empty' });
|
||||
|
||||
// Keyed by provider id in DeploySteps, so this runs once with fresh props.
|
||||
const initializedRef = useRef(false);
|
||||
const syncToParent = useCallback(() => {
|
||||
if (initializedRef.current) return;
|
||||
initializedRef.current = true;
|
||||
|
||||
onSubdomainChange(savedSubdomain || projectId);
|
||||
onSiteTitleChange(savedSiteTitle ?? projectName);
|
||||
if (savedSiteDescription) onSiteDescriptionChange(savedSiteDescription);
|
||||
}, [
|
||||
savedSubdomain,
|
||||
savedSiteTitle,
|
||||
savedSiteDescription,
|
||||
projectId,
|
||||
projectName,
|
||||
onSubdomainChange,
|
||||
onSiteTitleChange,
|
||||
onSiteDescriptionChange,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
syncToParent();
|
||||
}, [syncToParent]);
|
||||
|
||||
// The name this project already deployed to is not "taken" — it is theirs,
|
||||
// and asking the gateway would truthfully say taken and alarm them about
|
||||
// their own site.
|
||||
const isOwnName = Boolean(savedSubdomain) && subdomain === savedSubdomain;
|
||||
|
||||
useEffect(() => {
|
||||
const trimmed = subdomain.trim();
|
||||
|
||||
if (!trimmed) {
|
||||
setNameState({ kind: 'empty' });
|
||||
return;
|
||||
}
|
||||
if (isOwnName) {
|
||||
setNameState({ kind: 'mine' });
|
||||
return;
|
||||
}
|
||||
|
||||
setNameState({ kind: 'checking' });
|
||||
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(async () => {
|
||||
const availability = await checkNameAvailable(
|
||||
dashboardHost,
|
||||
`${trimmed}.${domain}`,
|
||||
controller.signal,
|
||||
);
|
||||
if (!controller.signal.aborted) setNameState(describe(availability, domain));
|
||||
}, AVAILABILITY_DEBOUNCE_MS);
|
||||
|
||||
return () => {
|
||||
controller.abort();
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [subdomain, isOwnName, dashboardHost, domain]);
|
||||
|
||||
// A name still being checked stays deployable: the gateway decides for real
|
||||
// when the deploy runs, and blocking the button on an in-flight request would
|
||||
// make the form feel stuck on a slow connection.
|
||||
const isValid = subdomain.trim() !== '' && nameState.kind !== 'unavailable';
|
||||
|
||||
useEffect(() => {
|
||||
onValidationChange?.(isValid);
|
||||
}, [isValid, onValidationChange]);
|
||||
|
||||
const handleSubdomainChange = (value: string) => {
|
||||
setSubdomain(value);
|
||||
onSubdomainChange(value);
|
||||
};
|
||||
|
||||
const handleSiteTitleChange = (value: string) => {
|
||||
setSiteTitle(value);
|
||||
onSiteTitleChange(value);
|
||||
};
|
||||
|
||||
const handleSiteDescriptionChange = (value: string) => {
|
||||
setSiteDescription(value);
|
||||
onSiteDescriptionChange(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="npanel-subdomain">Address</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
id="npanel-subdomain"
|
||||
value={subdomain}
|
||||
onChange={(e) => handleSubdomainChange(e.target.value)}
|
||||
placeholder={projectId}
|
||||
className={nameState.kind === 'unavailable' ? 'border-destructive' : ''}
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground font-mono whitespace-nowrap">
|
||||
.{domain}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{nameState.kind === 'checking' && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
<span>Checking availability…</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{nameState.kind === 'free' && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<Check className="h-3 w-3" />
|
||||
<span>
|
||||
<span className="font-mono">{subdomain.trim()}.{domain}</span> is available.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{nameState.kind === 'mine' && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Updating <span className="font-mono">{subdomain.trim()}.{domain}</span>.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{nameState.kind === 'unavailable' && (
|
||||
<div className="flex items-start gap-2 text-sm text-destructive">
|
||||
<AlertCircle className="h-4 w-4 mt-0.5 flex-shrink-0" />
|
||||
<span>{nameState.message}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="npanel-title">Site Title</Label>
|
||||
<Input
|
||||
id="npanel-title"
|
||||
value={siteTitle}
|
||||
onChange={(e) => handleSiteTitleChange(e.target.value)}
|
||||
placeholder="My Nostr Site"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="npanel-description">
|
||||
Description <span className="text-muted-foreground font-normal">(optional)</span>
|
||||
</Label>
|
||||
<Textarea
|
||||
id="npanel-description"
|
||||
value={siteDescription}
|
||||
onChange={(e) => handleSiteDescriptionChange(e.target.value)}
|
||||
placeholder="A short description of this site…"
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { AlertCircle } from 'lucide-react';
|
||||
|
||||
interface ShakespeareDeployFormProps {
|
||||
host?: string;
|
||||
projectId: string;
|
||||
savedSubdomain?: string;
|
||||
onSubdomainChange: (subdomain: string) => void;
|
||||
onValidationChange?: (isValid: boolean) => void;
|
||||
}
|
||||
|
||||
export function ShakespeareDeployForm({
|
||||
host = 'shakespeare.wtf',
|
||||
projectId,
|
||||
savedSubdomain,
|
||||
onSubdomainChange,
|
||||
onValidationChange,
|
||||
}: ShakespeareDeployFormProps) {
|
||||
const [subdomain, setSubdomain] = useState(savedSubdomain || projectId);
|
||||
|
||||
// Update subdomain when savedSubdomain changes (e.g., when switching providers)
|
||||
useEffect(() => {
|
||||
setSubdomain(savedSubdomain || projectId);
|
||||
}, [savedSubdomain, projectId]);
|
||||
|
||||
// Validate subdomain: no periods allowed (only single-level subdomains)
|
||||
const hasPeriod = subdomain.includes('.');
|
||||
const isValid = subdomain.trim() !== '' && !hasPeriod;
|
||||
|
||||
useEffect(() => {
|
||||
onSubdomainChange(subdomain);
|
||||
}, [subdomain, onSubdomainChange]);
|
||||
|
||||
useEffect(() => {
|
||||
onValidationChange?.(isValid);
|
||||
}, [isValid, onValidationChange]);
|
||||
|
||||
const fullDomain = subdomain ? `${subdomain}.${host}` : `${projectId}.${host}`;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="shakespeare-subdomain">Subdomain</Label>
|
||||
<Input
|
||||
id="shakespeare-subdomain"
|
||||
value={subdomain}
|
||||
onChange={(e) => setSubdomain(e.target.value)}
|
||||
placeholder={projectId}
|
||||
className={hasPeriod ? 'border-destructive' : ''}
|
||||
/>
|
||||
{hasPeriod && (
|
||||
<div className="flex items-start gap-2 text-sm text-destructive">
|
||||
<AlertCircle className="h-4 w-4 mt-0.5 flex-shrink-0" />
|
||||
<span>Subdomain cannot contain periods. Use hyphens instead (e.g., "nostr-radar").</span>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Will deploy to: <span className="font-mono">{fullDomain}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user