mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +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',
|
name: 'Shakespeare',
|
||||||
type: '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()),
|
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', [
|
const deployProviderSchema: z.ZodType<DeployProvider> = z.discriminatedUnion('type', [
|
||||||
shakespeareDeployProviderSchema,
|
shakespeareDeployProviderSchema,
|
||||||
netlifyProviderSchema,
|
netlifyProviderSchema,
|
||||||
vercelProviderSchema,
|
vercelProviderSchema,
|
||||||
nsiteProviderSchema,
|
nsiteProviderSchema,
|
||||||
|
cloudflareProviderSchema,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const deploySettingsSchema = z.object({
|
const deploySettingsSchema = z.object({
|
||||||
|
|||||||
@@ -77,14 +77,9 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
// Construct the production URL
|
// Construct the production URL
|
||||||
// The subdomain from the API response already includes the full domain
|
// The subdomain from the API response already includes the full domain
|
||||||
// e.g., "error-button.pages.dev" not just "error-button"
|
// e.g., "error-button.pages.dev" not just "error-button"
|
||||||
let productionUrl: string;
|
const productionUrl = project.subdomain.includes('.')
|
||||||
if (project.subdomain.includes('.')) {
|
? `https://${project.subdomain}`
|
||||||
// Subdomain already includes the domain
|
: `https://${project.subdomain}.pages.dev`;
|
||||||
productionUrl = `https://${project.subdomain}`;
|
|
||||||
} else {
|
|
||||||
// Subdomain is just the name, append .pages.dev
|
|
||||||
productionUrl = `https://${project.subdomain}.pages.dev`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: deployment.url,
|
url: deployment.url,
|
||||||
@@ -92,6 +87,7 @@ export class CloudflareAdapter implements DeployAdapter {
|
|||||||
deploymentId: deployment.id,
|
deploymentId: deployment.id,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
projectName: project.name,
|
projectName: project.name,
|
||||||
|
productionUrl,
|
||||||
provider: 'cloudflare',
|
provider: 'cloudflare',
|
||||||
environment: deployment.environment,
|
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">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor={`provider-${index}-apiKey`}>
|
<Label htmlFor={`provider-${index}-apiKey`}>
|
||||||
{preset?.apiKeyLabel || t('apiKey')} <span className="text-destructive">*</span>
|
{preset?.apiKeyLabel || t('apiKey')} <span className="text-destructive">*</span>
|
||||||
@@ -208,19 +221,6 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</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">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor={`provider-${index}-baseURL`}>
|
<Label htmlFor={`provider-${index}-baseURL`}>
|
||||||
Base URL (Optional)
|
Base URL (Optional)
|
||||||
@@ -766,32 +766,6 @@ export function DeploySettings() {
|
|||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
{!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' && (
|
{preset.type === 'cloudflare' && (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Input
|
<Input
|
||||||
@@ -820,6 +794,32 @@ export function DeploySettings() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</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
|
<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' && (
|
{customProviderType === 'cloudflare' && (
|
||||||
<div className="grid gap-2">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="custom-accountid">
|
<Label htmlFor="custom-accountid">
|
||||||
@@ -977,6 +964,19 @@ export function DeploySettings() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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">
|
<div className="grid gap-2">
|
||||||
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
Reference in new issue
Block a user