mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Fix Cloudflare config persistence
This commit is contained in:
4 files changed
+71
-60
No files matched your search
@@ -228,6 +228,13 @@ describe('configUtils', () => {
|
||||
name: 'Shakespeare',
|
||||
type: 'shakespeare',
|
||||
},
|
||||
{
|
||||
id: 'provider-4',
|
||||
name: 'My Cloudflare',
|
||||
type: 'cloudflare',
|
||||
apiKey: 'cloudflare-token-789',
|
||||
accountId: 'account-123',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -106,11 +106,19 @@ const nsiteProviderSchema = baseDeployProviderSchema.extend({
|
||||
blossomServers: z.array(z.string()),
|
||||
});
|
||||
|
||||
const cloudflareProviderSchema = baseDeployProviderSchema.extend({
|
||||
type: z.literal('cloudflare'),
|
||||
apiKey: z.string(),
|
||||
accountId: z.string(),
|
||||
baseURL: z.string().optional(),
|
||||
});
|
||||
|
||||
const deployProviderSchema: z.ZodType<DeployProvider> = z.discriminatedUnion('type', [
|
||||
shakespeareDeployProviderSchema,
|
||||
netlifyProviderSchema,
|
||||
vercelProviderSchema,
|
||||
nsiteProviderSchema,
|
||||
cloudflareProviderSchema,
|
||||
]);
|
||||
|
||||
const deploySettingsSchema = z.object({
|
||||
|
||||
@@ -77,14 +77,9 @@ export class CloudflareAdapter implements DeployAdapter {
|
||||
// Construct the production URL
|
||||
// The subdomain from the API response already includes the full domain
|
||||
// e.g., "error-button.pages.dev" not just "error-button"
|
||||
let productionUrl: string;
|
||||
if (project.subdomain.includes('.')) {
|
||||
// Subdomain already includes the domain
|
||||
productionUrl = `https://${project.subdomain}`;
|
||||
} else {
|
||||
// Subdomain is just the name, append .pages.dev
|
||||
productionUrl = `https://${project.subdomain}.pages.dev`;
|
||||
}
|
||||
const productionUrl = project.subdomain.includes('.')
|
||||
? `https://${project.subdomain}`
|
||||
: `https://${project.subdomain}.pages.dev`;
|
||||
|
||||
return {
|
||||
url: deployment.url,
|
||||
@@ -92,6 +87,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
||||
deploymentId: deployment.id,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
productionUrl,
|
||||
provider: 'cloudflare',
|
||||
environment: deployment.environment,
|
||||
},
|
||||
|
||||
@@ -189,6 +189,19 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{provider.type === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-accountId`}>
|
||||
{preset?.accountIdLabel || 'Account ID'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`provider-${index}-accountId`}
|
||||
placeholder="Enter Account ID"
|
||||
value={provider.accountId}
|
||||
onChange={(e) => onUpdate(index, { ...provider, accountId: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-apiKey`}>
|
||||
{preset?.apiKeyLabel || t('apiKey')} <span className="text-destructive">*</span>
|
||||
@@ -208,19 +221,6 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{provider.type === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-accountId`}>
|
||||
{preset?.accountIdLabel || 'Account ID'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`provider-${index}-accountId`}
|
||||
placeholder="Enter Account ID"
|
||||
value={provider.accountId}
|
||||
onChange={(e) => onUpdate(index, { ...provider, accountId: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-baseURL`}>
|
||||
Base URL (Optional)
|
||||
@@ -766,32 +766,6 @@ export function DeploySettings() {
|
||||
<div className="space-y-2">
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<>
|
||||
<div className="relative">
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
(preset.type !== 'cloudflare' || presetApiKeys[`${preset.id}-accountId`]?.trim())) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{preset.apiKeyURL && !presetApiKeys[preset.id] && (
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-11 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors rounded-md hover:bg-muted"
|
||||
onClick={() => window.open(preset.apiKeyURL, '_blank')}
|
||||
>
|
||||
Get Key
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{preset.type === 'cloudflare' && (
|
||||
<div className="relative">
|
||||
<Input
|
||||
@@ -820,6 +794,32 @@ export function DeploySettings() {
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="relative">
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
(preset.type !== 'cloudflare' || presetApiKeys[`${preset.id}-accountId`]?.trim())) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{preset.apiKeyURL && !presetApiKeys[preset.id] && (
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-11 top-1/2 -translate-y-1/2 inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors rounded-md hover:bg-muted"
|
||||
onClick={() => window.open(preset.apiKeyURL, '_blank')}
|
||||
>
|
||||
Get Key
|
||||
<ExternalLink className="h-3 w-3" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
@@ -951,19 +951,6 @@ export function DeploySettings() {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' :
|
||||
customProviderType === 'cloudflare' ? 'API Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey')}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{customProviderType === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-accountid">
|
||||
@@ -977,6 +964,19 @@ export function DeploySettings() {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' :
|
||||
customProviderType === 'cloudflare' ? 'API Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey')}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
||||
<Input
|
||||
|
||||
Reference in new issue
Block a user