mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-04 08:13:34 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91ab79bb39 | ||
|
|
8f148e48c0 | ||
|
|
3e230d425f |
No files matched your search
Generated
+31
-11
@@ -195,6 +195,7 @@
|
||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
@@ -1830,6 +1831,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
@@ -1853,6 +1855,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
@@ -1874,6 +1877,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
|
||||
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@dnd-kit/accessibility": "^3.1.1",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
@@ -5404,8 +5408,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
||||
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/cacheable-request": {
|
||||
"version": "6.0.3",
|
||||
@@ -5647,6 +5650,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
|
||||
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/prop-types": "*",
|
||||
"csstype": "^3.0.2"
|
||||
@@ -5658,6 +5662,7 @@
|
||||
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.0.0"
|
||||
}
|
||||
@@ -5762,6 +5767,7 @@
|
||||
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.31.1",
|
||||
"@typescript-eslint/types": "8.31.1",
|
||||
@@ -6108,6 +6114,7 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -6552,6 +6559,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.8.19",
|
||||
"caniuse-lite": "^1.0.30001751",
|
||||
@@ -6811,6 +6819,7 @@
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.2",
|
||||
"braces": "~3.0.2",
|
||||
@@ -7549,8 +7558,7 @@
|
||||
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
|
||||
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/dom-helpers": {
|
||||
"version": "5.2.1",
|
||||
@@ -7628,7 +7636,8 @@
|
||||
"version": "8.6.0",
|
||||
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
|
||||
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/embla-carousel-react": {
|
||||
"version": "8.6.0",
|
||||
@@ -7927,6 +7936,7 @@
|
||||
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -9274,6 +9284,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.27.6"
|
||||
},
|
||||
@@ -10043,6 +10054,7 @@
|
||||
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"cssstyle": "^4.2.1",
|
||||
"data-urls": "^5.0.0",
|
||||
@@ -10439,7 +10451,6 @@
|
||||
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"lz-string": "bin/bin.js"
|
||||
}
|
||||
@@ -12143,6 +12154,7 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.8",
|
||||
"picocolors": "^1.1.1",
|
||||
@@ -12310,7 +12322,6 @@
|
||||
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.1",
|
||||
"ansi-styles": "^5.0.0",
|
||||
@@ -12326,7 +12337,6 @@
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
@@ -12337,7 +12347,6 @@
|
||||
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
@@ -12350,8 +12359,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/prismjs": {
|
||||
"version": "1.30.0",
|
||||
@@ -12491,6 +12499,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
||||
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0"
|
||||
},
|
||||
@@ -12517,6 +12526,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
||||
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"scheduler": "^0.23.2"
|
||||
@@ -12542,6 +12552,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
|
||||
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@@ -12590,6 +12601,7 @@
|
||||
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
|
||||
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0",
|
||||
"@types/mdast": "^4.0.0",
|
||||
@@ -13172,6 +13184,7 @@
|
||||
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/estree": "1.0.7"
|
||||
},
|
||||
@@ -14223,6 +14236,7 @@
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
|
||||
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"arg": "^5.0.2",
|
||||
@@ -14426,6 +14440,7 @@
|
||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -14698,6 +14713,7 @@
|
||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -15207,6 +15223,7 @@
|
||||
"integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.25.0",
|
||||
"fdir": "^6.4.4",
|
||||
@@ -15351,6 +15368,7 @@
|
||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -15821,6 +15839,7 @@
|
||||
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fast-uri": "^3.0.1",
|
||||
@@ -15897,6 +15916,7 @@
|
||||
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
|
||||
@@ -27,14 +27,13 @@ import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, CloudflareAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider, CloudflareProvider } from '@/contexts/DeploySettingsContext';
|
||||
import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider } from '@/contexts/DeploySettingsContext';
|
||||
import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm';
|
||||
import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm';
|
||||
import { VercelDeployForm } from '@/components/deploy/VercelDeployForm';
|
||||
import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm';
|
||||
import { CloudflareDeployForm } from '@/components/deploy/CloudflareDeployForm';
|
||||
|
||||
/**
|
||||
* Helper function to get provider URL for favicon
|
||||
@@ -59,12 +58,6 @@ function getProviderUrl(provider: DeployProvider): string | null {
|
||||
}
|
||||
return 'https://vercel.com';
|
||||
|
||||
case 'cloudflare':
|
||||
if (provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://cloudflare.com';
|
||||
|
||||
case 'nsite':
|
||||
return null;
|
||||
|
||||
@@ -117,11 +110,6 @@ interface VercelFormData {
|
||||
teamId: string;
|
||||
}
|
||||
|
||||
interface CloudflareFormData {
|
||||
projectName: string;
|
||||
branch: string;
|
||||
}
|
||||
|
||||
export function DeployDialog({ projectId, projectName, open, onOpenChange }: DeployDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const { settings } = useDeploySettings();
|
||||
@@ -153,10 +141,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
projectName: projectName || projectId,
|
||||
teamId: '',
|
||||
});
|
||||
const [cloudflareForm, setCloudflareForm] = useState<CloudflareFormData>({
|
||||
projectName: projectName || projectId,
|
||||
branch: 'main',
|
||||
});
|
||||
|
||||
// Load project settings when dialog opens
|
||||
useEffect(() => {
|
||||
@@ -246,24 +230,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
projectName: vercelForm.projectName || undefined,
|
||||
corsProxy: vercelProvider.proxy ? config.corsProxy : undefined,
|
||||
});
|
||||
} else if (selectedProvider.type === 'cloudflare') {
|
||||
const cloudflareProvider = selectedProvider as CloudflareProvider;
|
||||
if (!cloudflareProvider.apiToken) {
|
||||
throw new Error('Cloudflare API token is required');
|
||||
}
|
||||
if (!cloudflareProvider.accountId) {
|
||||
throw new Error('Cloudflare Account ID is required');
|
||||
}
|
||||
|
||||
adapter = new CloudflareAdapter({
|
||||
fs,
|
||||
apiToken: cloudflareProvider.apiToken,
|
||||
accountId: cloudflareProvider.accountId,
|
||||
baseURL: cloudflareProvider.baseURL,
|
||||
projectName: cloudflareForm.projectName || undefined,
|
||||
branch: cloudflareForm.branch || undefined,
|
||||
corsProxy: cloudflareProvider.proxy ? config.corsProxy : undefined,
|
||||
});
|
||||
} else {
|
||||
throw new Error('Unknown provider type');
|
||||
}
|
||||
@@ -303,15 +269,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
projectId: vercelForm.projectName || undefined,
|
||||
},
|
||||
});
|
||||
} else if (selectedProvider.type === 'cloudflare') {
|
||||
await updateProjectSettings(selectedProviderId, {
|
||||
type: 'cloudflare',
|
||||
data: {
|
||||
projectName: cloudflareForm.projectName || undefined,
|
||||
branch: cloudflareForm.branch || undefined,
|
||||
projectId: result.metadata?.projectId as string | undefined,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
setDeployResult(result);
|
||||
@@ -331,7 +288,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setNsiteForm({ nsec: '' });
|
||||
setNetlifyForm({ siteId: '', siteName: '' });
|
||||
setVercelForm({ projectName: projectName || projectId, teamId: '' });
|
||||
setCloudflareForm({ projectName: projectName || projectId, branch: 'main' });
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
@@ -355,10 +311,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setVercelForm({ projectName, teamId });
|
||||
}, []);
|
||||
|
||||
const handleCloudflareConfigChange = useCallback((projectName: string, branch: string) => {
|
||||
setCloudflareForm({ projectName, branch });
|
||||
}, []);
|
||||
|
||||
const renderProviderFields = () => {
|
||||
if (!selectedProvider) return null;
|
||||
|
||||
@@ -421,22 +373,6 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
);
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'cloudflare') {
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedProjectName = savedConfig?.type === 'cloudflare' ? savedConfig.data.projectName : undefined;
|
||||
const savedBranch = savedConfig?.type === 'cloudflare' ? savedConfig.data.branch : undefined;
|
||||
|
||||
return (
|
||||
<CloudflareDeployForm
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
savedProjectName={savedProjectName}
|
||||
savedBranch={savedBranch}
|
||||
onConfigChange={handleCloudflareConfigChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { encodeBase64 } from '@std/encoding/base64';
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useState, useEffect, useCallback, useRef, useMemo, memo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||
import { addConsoleMessage, getConsoleMessages, type ConsoleMessage } from '@/lib/consoleMessages';
|
||||
import { addConsoleMessage, getConsoleMessages, addConsoleMessageListener, removeConsoleMessageListener, type ConsoleMessage } from '@/lib/consoleMessages';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { Tabs, TabsContent } from '@/components/ui/tabs';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, X, Terminal } from 'lucide-react';
|
||||
import { FolderOpen, ArrowLeft, Bug, Copy, Check, Play, Loader2, MenuIcon, Code, Rocket, Terminal, Trash2, ChevronRight } from 'lucide-react';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
|
||||
import { BrowserAddressBar } from '@/components/ui/browser-address-bar';
|
||||
@@ -20,11 +20,6 @@ import {
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { FileTree } from './FileTree';
|
||||
import { FileEditor } from './FileEditor';
|
||||
@@ -88,6 +83,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
const [historyIndex, setHistoryIndex] = useState(0);
|
||||
|
||||
const [deployDialogOpen, setDeployDialogOpen] = useState(false);
|
||||
const [showConsoleView, setShowConsoleView] = useState(false);
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const { fs } = useFS();
|
||||
const { projectsPath } = useFSPaths();
|
||||
@@ -465,6 +461,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
setFileContent('');
|
||||
setMobileCodeView('explorer');
|
||||
setDesktopCodeView('files');
|
||||
setShowConsoleView(false);
|
||||
|
||||
// Reset navigation history and state
|
||||
setCurrentPath('/');
|
||||
@@ -521,102 +518,282 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
}
|
||||
};
|
||||
|
||||
const ConsoleDropdown = () => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [copiedMessageIndex, setCopiedMessageIndex] = useState<number | null>(null);
|
||||
// Constants
|
||||
const CONSOLE_SORT_ORDER_KEY = 'consoleSortOrder';
|
||||
const COPY_FEEDBACK_DURATION = 2000;
|
||||
const MAX_CONSOLE_MESSAGES = 500; // Limit displayed messages for performance
|
||||
|
||||
const messages = isOpen ? getConsoleMessages() : [];
|
||||
// Helper function to get message level color
|
||||
const getMessageLevelColor = (level: ConsoleMessage['level']): string => {
|
||||
switch (level) {
|
||||
case 'error': return 'text-destructive';
|
||||
case 'warn': return 'text-warning';
|
||||
case 'info': return 'text-primary';
|
||||
default: return 'text-muted-foreground';
|
||||
}
|
||||
};
|
||||
|
||||
const ConsoleToggleButton = () => {
|
||||
return (
|
||||
<Button
|
||||
variant={showConsoleView ? "secondary" : "ghost"}
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0 relative"
|
||||
onClick={() => setShowConsoleView(!showConsoleView)}
|
||||
title={showConsoleView ? "Show preview" : "Show console"}
|
||||
>
|
||||
<Bug className="h-4 w-4" />
|
||||
{hasConsoleErrors && (
|
||||
<span className="absolute -top-1 -right-1 h-3 w-3 rounded-full border-2 border-background bg-red-500" />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
// Individual console message component - memoized for performance
|
||||
const ConsoleMessage = memo(({ msg, index, copiedMessageIndex, onCopy }: {
|
||||
msg: ConsoleMessage;
|
||||
index: number;
|
||||
copiedMessageIndex: number | null;
|
||||
onCopy: (msg: ConsoleMessage, index: number) => void;
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onCopy(msg, index);
|
||||
}}
|
||||
>
|
||||
<div className={cn(
|
||||
"text-xs font-mono leading-tight whitespace-pre-wrap break-words",
|
||||
getMessageLevelColor(msg.level)
|
||||
)}>
|
||||
{msg.message}
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onCopy(msg, index);
|
||||
}}
|
||||
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
|
||||
>
|
||||
{copiedMessageIndex === index ? (
|
||||
<Check className="h-2 w-2 text-success" />
|
||||
) : (
|
||||
<Copy className="h-2 w-2" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
ConsoleMessage.displayName = 'ConsoleMessage';
|
||||
|
||||
const ConsoleView = () => {
|
||||
const [copiedMessageIndex, setCopiedMessageIndex] = useState<number | null>(null);
|
||||
const [isInitialLoad, setIsInitialLoad] = useState(true);
|
||||
const [rawMessages, setRawMessages] = useState<ConsoleMessage[]>([]);
|
||||
const [totalMessageCount, setTotalMessageCount] = useState(0);
|
||||
|
||||
// Load sort order from localStorage, default to 'newest-first'
|
||||
const [sortOrder, setSortOrder] = useState<'newest-first' | 'oldest-first'>(() => {
|
||||
const saved = localStorage.getItem(CONSOLE_SORT_ORDER_KEY);
|
||||
return (saved === 'oldest-first' || saved === 'newest-first') ? saved : 'newest-first';
|
||||
});
|
||||
|
||||
// Save sort order to localStorage whenever it changes
|
||||
useEffect(() => {
|
||||
localStorage.setItem(CONSOLE_SORT_ORDER_KEY, sortOrder);
|
||||
}, [sortOrder]);
|
||||
|
||||
// Track rapid message bursts for intelligent batching
|
||||
const lastMessageTimeRef = useRef<number>(0);
|
||||
const pendingUpdateRef = useRef<number>();
|
||||
const messageCountSinceUpdateRef = useRef<number>(0);
|
||||
|
||||
// Update messages from the global store - optimized for immediate updates
|
||||
const updateMessages = useCallback(() => {
|
||||
const allMessages = getConsoleMessages();
|
||||
setTotalMessageCount(allMessages.length);
|
||||
|
||||
// Limit messages for performance (keep most recent)
|
||||
const limitedMessages = allMessages.length > MAX_CONSOLE_MESSAGES
|
||||
? allMessages.slice(-MAX_CONSOLE_MESSAGES)
|
||||
: allMessages;
|
||||
|
||||
setRawMessages(limitedMessages);
|
||||
setIsInitialLoad(false);
|
||||
messageCountSinceUpdateRef.current = 0;
|
||||
}, []);
|
||||
|
||||
// Smart update handler: immediate for single messages, batched for rapid bursts
|
||||
const handleMessageUpdate = useCallback(() => {
|
||||
const now = Date.now();
|
||||
const timeSinceLastMessage = now - lastMessageTimeRef.current;
|
||||
lastMessageTimeRef.current = now;
|
||||
messageCountSinceUpdateRef.current += 1;
|
||||
|
||||
// Detect rapid bursts: if we get more than 3 messages within 50ms, batch them
|
||||
const isRapidBurst = messageCountSinceUpdateRef.current > 3 && timeSinceLastMessage < 50;
|
||||
|
||||
// Clear any pending update
|
||||
if (pendingUpdateRef.current) {
|
||||
cancelAnimationFrame(pendingUpdateRef.current);
|
||||
pendingUpdateRef.current = undefined;
|
||||
}
|
||||
|
||||
if (isRapidBurst) {
|
||||
// Batch rapid updates using requestAnimationFrame for smooth rendering
|
||||
// This prevents UI blocking during loops that log many messages
|
||||
pendingUpdateRef.current = requestAnimationFrame(() => {
|
||||
updateMessages();
|
||||
});
|
||||
} else {
|
||||
// Immediate update for normal console.log calls (like browser console)
|
||||
// Single messages appear instantly, just like native browser console
|
||||
updateMessages();
|
||||
}
|
||||
}, [updateMessages]);
|
||||
|
||||
// Initial load and listener setup
|
||||
useEffect(() => {
|
||||
// Initial load - check if we have many messages
|
||||
const allMessages = getConsoleMessages();
|
||||
if (allMessages.length > 500) {
|
||||
setIsInitialLoad(true);
|
||||
// Use requestIdleCallback for non-blocking initial render, fallback to setTimeout
|
||||
const scheduleUpdate = () => {
|
||||
if ('requestIdleCallback' in window) {
|
||||
requestIdleCallback(() => {
|
||||
updateMessages();
|
||||
}, { timeout: 100 });
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
updateMessages();
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
scheduleUpdate();
|
||||
} else {
|
||||
updateMessages();
|
||||
}
|
||||
|
||||
addConsoleMessageListener(handleMessageUpdate);
|
||||
return () => {
|
||||
removeConsoleMessageListener(handleMessageUpdate);
|
||||
if (pendingUpdateRef.current) {
|
||||
cancelAnimationFrame(pendingUpdateRef.current);
|
||||
}
|
||||
};
|
||||
}, [handleMessageUpdate, updateMessages]);
|
||||
|
||||
// Memoize sorted messages to avoid recalculation on every render
|
||||
const messages = useMemo(() => {
|
||||
if (sortOrder === 'newest-first') {
|
||||
// For newest-first, reverse the array (messages are stored oldest-first)
|
||||
return [...rawMessages].reverse();
|
||||
}
|
||||
return rawMessages;
|
||||
}, [rawMessages, sortOrder]);
|
||||
|
||||
const copyMessageToClipboard = async (msg: ConsoleMessage, index: number) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(msg.message);
|
||||
setCopiedMessageIndex(index);
|
||||
setTimeout(() => setCopiedMessageIndex(null), 2000);
|
||||
setTimeout(() => setCopiedMessageIndex(null), COPY_FEEDBACK_DURATION);
|
||||
} catch (error) {
|
||||
console.error('Failed to copy message to clipboard:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleClearMessages = () => {
|
||||
clearErrors();
|
||||
setCopiedMessageIndex(null);
|
||||
};
|
||||
|
||||
const messageCount = messages.length;
|
||||
const hasMoreMessages = rawMessages.length >= MAX_CONSOLE_MESSAGES;
|
||||
|
||||
return (
|
||||
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<div className="h-full w-full flex flex-col bg-background">
|
||||
{/* Header */}
|
||||
<div className="h-12 flex-shrink-0 flex items-center justify-between px-4 border-b">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0 relative"
|
||||
onClick={() => setShowConsoleView(false)}
|
||||
className="h-8 gap-2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Bug className="h-4 w-4" />
|
||||
{hasConsoleErrors && (
|
||||
<span className="absolute -top-1 -right-1 h-3 w-3 rounded-full border-2 border-background bg-red-500" />
|
||||
)}
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
Back
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
align="end"
|
||||
className="w-[calc(100vw-1rem)] max-w-[480px] max-h-[512px] overflow-hidden shadow-lg border rounded-lg bg-background p-0"
|
||||
sideOffset={4}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
{messageCount > 0 && (
|
||||
<>
|
||||
{hasMoreMessages && (
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Showing last {MAX_CONSOLE_MESSAGES.toLocaleString()} of {totalMessageCount.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setSortOrder(sortOrder === 'newest-first' ? 'oldest-first' : 'newest-first')}
|
||||
className="h-8 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{sortOrder === 'newest-first' ? t('latestFirst') : t('oldestFirst')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleClearMessages}
|
||||
className="h-8 w-8 p-0 text-destructive/80 hover:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Messages */}
|
||||
<div className="h-[60vh] max-h-[512px] w-full bg-background text-foreground font-mono text-xs relative overflow-y-auto overflow-x-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]">
|
||||
{/* Messages */}
|
||||
<div className="flex-1 min-h-0 overflow-y-auto overflow-x-hidden [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none] bg-background text-foreground font-mono text-xs relative">
|
||||
{isInitialLoad ? (
|
||||
<div className="absolute inset-0 flex items-center justify-center z-10 bg-background">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<Loader2 className="h-5 w-5 animate-spin text-primary" />
|
||||
<span className="text-sm text-muted-foreground">Loading console messages...</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="py-2 px-1 space-y-0">
|
||||
{messageCount === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center py-12 text-center">
|
||||
<p className="text-sm text-muted-foreground font-medium">No console messages</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">Messages from your project will appear here</p>
|
||||
{/* Console prompt indicator - at top for newest-first, bottom for oldest-first */}
|
||||
{sortOrder === 'newest-first' && (
|
||||
<div className="py-0.5 px-1 flex items-center">
|
||||
<ChevronRight className="h-3 w-3 text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
{messages.map((msg, index) => (
|
||||
<ConsoleMessage
|
||||
key={`${index}-${msg.message.slice(0, 20)}`}
|
||||
msg={msg}
|
||||
index={index}
|
||||
copiedMessageIndex={copiedMessageIndex}
|
||||
onCopy={copyMessageToClipboard}
|
||||
/>
|
||||
))}
|
||||
{sortOrder === 'oldest-first' && (
|
||||
<div className="py-0.5 px-1 flex items-center">
|
||||
<ChevronRight className="h-3 w-3 text-muted-foreground" />
|
||||
</div>
|
||||
) : (
|
||||
messages.map((msg, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="group relative py-0.5 px-1 hover:bg-muted/50 transition-colors duration-150 rounded cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
copyMessageToClipboard(msg, index);
|
||||
}}
|
||||
>
|
||||
<div className={cn(
|
||||
"text-xs font-mono leading-tight whitespace-pre-wrap break-words",
|
||||
msg.level === 'error' ? "text-destructive" :
|
||||
msg.level === 'warn' ? "text-warning" :
|
||||
msg.level === 'info' ? "text-primary" :
|
||||
"text-muted-foreground"
|
||||
)}>
|
||||
{msg.message}
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
copyMessageToClipboard(msg, index);
|
||||
}}
|
||||
className="h-3 w-3 p-0 opacity-0 group-hover:opacity-100 transition-all duration-200 absolute right-1 top-1 hover:bg-muted/70 text-muted-foreground hover:text-foreground bg-background/80 rounded border"
|
||||
>
|
||||
{copiedMessageIndex === index ? (
|
||||
<Check className="h-2 w-2 text-success" />
|
||||
) : (
|
||||
<Copy className="h-2 w-2" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Close button */}
|
||||
<button
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="absolute top-2 right-2 h-8 w-8 p-0 bg-muted/50 hover:bg-muted/70 rounded-md z-10 flex items-center justify-center border"
|
||||
>
|
||||
<X className="h-5 w-5 text-muted-foreground" />
|
||||
</button>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -689,7 +866,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
<Code className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<ConsoleDropdown />
|
||||
<ConsoleToggleButton />
|
||||
<Menu />
|
||||
</div>
|
||||
)}
|
||||
@@ -697,16 +874,25 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
|
||||
</div>
|
||||
|
||||
{/* Content area */}
|
||||
<div className="flex-1">
|
||||
{hasBuiltProject ? (
|
||||
<div className="flex-1 min-h-0 relative">
|
||||
{/* Console View */}
|
||||
<div className={cn("absolute inset-0", showConsoleView ? "block" : "hidden")}>
|
||||
<ConsoleView />
|
||||
</div>
|
||||
|
||||
{/* Preview iframe */}
|
||||
{hasBuiltProject && (
|
||||
<iframe
|
||||
ref={iframeRef}
|
||||
src={`https://${projectId}.${previewDomain}/`}
|
||||
className="w-full h-full border-0"
|
||||
className={cn("w-full h-full border-0", showConsoleView ? "hidden" : "block")}
|
||||
title="Project Preview"
|
||||
sandbox="allow-scripts allow-same-origin"
|
||||
/>
|
||||
) : (
|
||||
)}
|
||||
|
||||
{/* Build prompt */}
|
||||
{!hasBuiltProject && !showConsoleView && (
|
||||
<div className="h-full flex items-center justify-center bg-muted">
|
||||
<div className="text-center">
|
||||
<h3 className="text-lg font-semibold mb-2">{t('projectPreview')}</h3>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
|
||||
interface CloudflareDeployFormProps {
|
||||
projectId: string;
|
||||
projectName?: string;
|
||||
savedProjectName?: string;
|
||||
savedBranch?: string;
|
||||
onConfigChange: (projectName: string, branch: string) => void;
|
||||
}
|
||||
|
||||
export function CloudflareDeployForm({
|
||||
projectId,
|
||||
projectName: initialProjectName,
|
||||
savedProjectName,
|
||||
savedBranch,
|
||||
onConfigChange,
|
||||
}: CloudflareDeployFormProps) {
|
||||
const [projectName, setProjectName] = useState(savedProjectName || initialProjectName || projectId);
|
||||
const [branch, setBranch] = useState(savedBranch || 'main');
|
||||
|
||||
useEffect(() => {
|
||||
onConfigChange(projectName, branch);
|
||||
}, [projectName, branch, onConfigChange]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="cloudflare-project-name">Project Name</Label>
|
||||
<Input
|
||||
id="cloudflare-project-name"
|
||||
value={projectName}
|
||||
onChange={(e) => setProjectName(e.target.value)}
|
||||
placeholder={initialProjectName || projectId}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
URL: <span className="font-mono">{projectName || projectId}.pages.dev</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="cloudflare-branch">Branch Name</Label>
|
||||
<Input
|
||||
id="cloudflare-branch"
|
||||
value={branch}
|
||||
onChange={(e) => setBranch(e.target.value)}
|
||||
placeholder="main"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Production branch for your Cloudflare Pages project
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -32,15 +32,7 @@ export interface NsiteProvider extends BaseDeployProvider {
|
||||
blossomServers: string[];
|
||||
}
|
||||
|
||||
export interface CloudflareProvider extends BaseDeployProvider {
|
||||
type: 'cloudflare';
|
||||
apiToken: string;
|
||||
accountId: string;
|
||||
baseURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider | NsiteProvider | CloudflareProvider;
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider | NsiteProvider;
|
||||
|
||||
export interface DeploySettings {
|
||||
providers: DeployProvider[];
|
||||
|
||||
@@ -49,10 +49,7 @@ export function useOAuth(config: OAuthConfig) {
|
||||
const { corsProxy } = appConfig;
|
||||
|
||||
// Check if OAuth is configured
|
||||
// For PKCE flows (like Cloudflare), we only need clientId
|
||||
const isOAuthConfigured = config.usePKCE
|
||||
? !!config.clientId
|
||||
: !!(config.clientId && config.clientSecret);
|
||||
const isOAuthConfigured = !!(config.clientId && config.clientSecret);
|
||||
|
||||
// Generate a cryptographically secure random string for PKCE code verifier
|
||||
const generateCodeVerifier = (): string => {
|
||||
|
||||
@@ -31,16 +31,7 @@ export interface VercelProjectConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export interface CloudflareProjectConfig {
|
||||
type: 'cloudflare';
|
||||
data: {
|
||||
projectName?: string;
|
||||
branch?: string;
|
||||
projectId?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NsiteProjectConfig | NetlifyProjectConfig | VercelProjectConfig | CloudflareProjectConfig;
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NsiteProjectConfig | NetlifyProjectConfig | VercelProjectConfig;
|
||||
|
||||
export interface ProjectDeploySettings {
|
||||
providers: Record<string, ProjectProviderConfig>;
|
||||
|
||||
@@ -1,321 +0,0 @@
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, CloudflareDeployConfig } from './types';
|
||||
import { proxyUrl } from '../proxyUrl';
|
||||
|
||||
interface CloudflareFile {
|
||||
key: string;
|
||||
value: string;
|
||||
metadata: {
|
||||
contentType: string;
|
||||
};
|
||||
base64: boolean;
|
||||
}
|
||||
|
||||
interface CloudflareDeployment {
|
||||
id: string;
|
||||
url: string;
|
||||
environment: string;
|
||||
deployment_trigger: {
|
||||
type: string;
|
||||
};
|
||||
stages: Array<{
|
||||
name: string;
|
||||
status: string;
|
||||
}>;
|
||||
project_name: string;
|
||||
}
|
||||
|
||||
interface CloudflareProject {
|
||||
id: string;
|
||||
name: string;
|
||||
subdomain: string;
|
||||
domains: string[];
|
||||
created_on: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cloudflare Pages Deploy Adapter
|
||||
* Uses Cloudflare Pages Direct Upload API with API token
|
||||
*
|
||||
* Mimics the behavior of "wrangler pages deploy dist"
|
||||
*/
|
||||
export class CloudflareAdapter implements DeployAdapter {
|
||||
private fs: JSRuntimeFS;
|
||||
private apiToken: string;
|
||||
private accountId: string;
|
||||
private baseURL: string;
|
||||
private projectName?: string;
|
||||
private branch?: string;
|
||||
private corsProxy?: string;
|
||||
|
||||
constructor(config: CloudflareDeployConfig) {
|
||||
this.fs = config.fs;
|
||||
this.apiToken = config.apiToken;
|
||||
this.accountId = config.accountId;
|
||||
this.baseURL = config.baseURL || 'https://api.cloudflare.com/client/v4';
|
||||
this.projectName = config.projectName;
|
||||
this.branch = config.branch || 'main';
|
||||
this.corsProxy = config.corsProxy;
|
||||
}
|
||||
|
||||
async deploy(options: DeployOptions): Promise<DeployResult> {
|
||||
const { projectId, projectPath } = options;
|
||||
|
||||
// Check if dist directory exists and contains index.html
|
||||
const distPath = `${projectPath}/dist`;
|
||||
try {
|
||||
await this.fs.readFile(`${distPath}/index.html`, 'utf8');
|
||||
} catch {
|
||||
throw new Error('No index.html found in dist directory. Please build the project first.');
|
||||
}
|
||||
|
||||
// Determine project name
|
||||
const cfProjectName = this.projectName || projectId;
|
||||
|
||||
// Ensure project exists or create it
|
||||
let project: CloudflareProject;
|
||||
try {
|
||||
project = await this.getProject(cfProjectName);
|
||||
} catch {
|
||||
// Project doesn't exist, create it
|
||||
project = await this.createProject(cfProjectName);
|
||||
}
|
||||
|
||||
// Collect all files from dist directory
|
||||
const manifest: Record<string, string> = {};
|
||||
const files: CloudflareFile[] = [];
|
||||
await this.collectFiles(distPath, '', files, manifest);
|
||||
|
||||
// Create deployment using Direct Upload API
|
||||
const deployment = await this.createDeployment(cfProjectName, files, manifest);
|
||||
|
||||
// Construct the deployment URL
|
||||
const deploymentUrl = deployment.url || `https://${deployment.id}.${project.subdomain}.pages.dev`;
|
||||
|
||||
return {
|
||||
url: deploymentUrl,
|
||||
metadata: {
|
||||
deploymentId: deployment.id,
|
||||
projectId: project.id,
|
||||
projectName: project.name,
|
||||
provider: 'cloudflare',
|
||||
environment: deployment.environment,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async getProject(projectName: string): Promise<CloudflareProject> {
|
||||
const url = `${this.baseURL}/accounts/${this.accountId}/pages/projects/${projectName}`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Failed to get Cloudflare Pages project: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.result;
|
||||
}
|
||||
|
||||
private async createProject(projectName: string): Promise<CloudflareProject> {
|
||||
const url = `${this.baseURL}/accounts/${this.accountId}/pages/projects`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: projectName,
|
||||
production_branch: this.branch,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Failed to create Cloudflare Pages project: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.result;
|
||||
}
|
||||
|
||||
private async createDeployment(
|
||||
projectName: string,
|
||||
files: CloudflareFile[],
|
||||
manifest: Record<string, string>
|
||||
): Promise<CloudflareDeployment> {
|
||||
const url = `${this.baseURL}/accounts/${this.accountId}/pages/projects/${projectName}/deployments`;
|
||||
const targetUrl = this.corsProxy ? proxyUrl(this.corsProxy, url) : url;
|
||||
|
||||
// Create form data for multipart upload
|
||||
const formData = new FormData();
|
||||
|
||||
// Add manifest
|
||||
formData.append('manifest', JSON.stringify(manifest));
|
||||
|
||||
// Add each file
|
||||
for (const file of files) {
|
||||
const blob = new Blob([file.value], { type: file.metadata.contentType });
|
||||
formData.append(file.key, blob);
|
||||
}
|
||||
|
||||
const response = await fetch(targetUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.apiToken}`,
|
||||
// Don't set Content-Type - browser will set it with boundary for multipart/form-data
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text().catch(() => 'Unknown error');
|
||||
throw new Error(`Failed to create Cloudflare Pages deployment: ${response.status} ${response.statusText}. ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.result;
|
||||
}
|
||||
|
||||
private async collectFiles(
|
||||
dirPath: string,
|
||||
relativePath: string,
|
||||
files: CloudflareFile[],
|
||||
manifest: Record<string, string>
|
||||
): Promise<void> {
|
||||
try {
|
||||
const entries = await this.fs.readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = `${dirPath}/${entry.name}`;
|
||||
const entryRelativePath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
// Recursively collect files from subdirectories
|
||||
await this.collectFiles(fullPath, entryRelativePath, files, manifest);
|
||||
} else if (entry.isFile()) {
|
||||
try {
|
||||
// Read file content
|
||||
const fileContent = await this.fs.readFile(fullPath);
|
||||
|
||||
// Determine content type based on file extension
|
||||
const contentType = this.getContentType(entry.name);
|
||||
|
||||
// Convert to base64 for binary files, or keep as string for text files
|
||||
let base64Content: string;
|
||||
let isBase64 = false;
|
||||
|
||||
if (this.isBinaryFile(entry.name)) {
|
||||
// Handle binary files (images, fonts, etc.)
|
||||
if (typeof fileContent === 'string') {
|
||||
base64Content = btoa(fileContent);
|
||||
} else {
|
||||
// Handle Uint8Array
|
||||
const binary = Array.from(fileContent)
|
||||
.map(byte => String.fromCharCode(byte))
|
||||
.join('');
|
||||
base64Content = btoa(binary);
|
||||
}
|
||||
isBase64 = true;
|
||||
} else {
|
||||
// Handle text files (HTML, CSS, JS, etc.)
|
||||
if (typeof fileContent === 'string') {
|
||||
base64Content = fileContent;
|
||||
} else {
|
||||
// Decode Uint8Array to string
|
||||
const decoder = new TextDecoder();
|
||||
base64Content = decoder.decode(fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
// Add to files array
|
||||
files.push({
|
||||
key: entryRelativePath,
|
||||
value: base64Content,
|
||||
metadata: {
|
||||
contentType,
|
||||
},
|
||||
base64: isBase64,
|
||||
});
|
||||
|
||||
// Add to manifest (hash placeholder - Cloudflare will compute actual hash)
|
||||
manifest[entryRelativePath] = '';
|
||||
} catch (error) {
|
||||
console.warn(`Failed to read file ${fullPath}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`Failed to read directory ${dirPath}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MIME type based on file extension
|
||||
*/
|
||||
private getContentType(filename: string): string {
|
||||
const ext = filename.split('.').pop()?.toLowerCase();
|
||||
|
||||
const mimeTypes: Record<string, string> = {
|
||||
// Text
|
||||
'html': 'text/html',
|
||||
'htm': 'text/html',
|
||||
'css': 'text/css',
|
||||
'js': 'application/javascript',
|
||||
'mjs': 'application/javascript',
|
||||
'json': 'application/json',
|
||||
'xml': 'application/xml',
|
||||
'txt': 'text/plain',
|
||||
'md': 'text/markdown',
|
||||
|
||||
// Images
|
||||
'png': 'image/png',
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'gif': 'image/gif',
|
||||
'svg': 'image/svg+xml',
|
||||
'webp': 'image/webp',
|
||||
'ico': 'image/x-icon',
|
||||
|
||||
// Fonts
|
||||
'woff': 'font/woff',
|
||||
'woff2': 'font/woff2',
|
||||
'ttf': 'font/ttf',
|
||||
'otf': 'font/otf',
|
||||
'eot': 'application/vnd.ms-fontobject',
|
||||
|
||||
// Other
|
||||
'pdf': 'application/pdf',
|
||||
'zip': 'application/zip',
|
||||
'wasm': 'application/wasm',
|
||||
};
|
||||
|
||||
return mimeTypes[ext || ''] || 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a file should be treated as binary
|
||||
*/
|
||||
private isBinaryFile(filename: string): boolean {
|
||||
const ext = filename.split('.').pop()?.toLowerCase();
|
||||
|
||||
const binaryExtensions = [
|
||||
'png', 'jpg', 'jpeg', 'gif', 'webp', 'ico',
|
||||
'woff', 'woff2', 'ttf', 'otf', 'eot',
|
||||
'pdf', 'zip', 'wasm',
|
||||
];
|
||||
|
||||
return binaryExtensions.includes(ext || '');
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,3 @@ export * from './ShakespeareAdapter';
|
||||
export * from './NetlifyAdapter';
|
||||
export * from './VercelAdapter';
|
||||
export * from './NsiteAdapter';
|
||||
export * from './CloudflareAdapter';
|
||||
@@ -54,13 +54,3 @@ export interface NsiteDeployConfig {
|
||||
relayUrls: string[];
|
||||
blossomServers: string[];
|
||||
}
|
||||
|
||||
export interface CloudflareDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
apiToken: string;
|
||||
accountId: string;
|
||||
baseURL?: string;
|
||||
projectName?: string;
|
||||
branch?: string;
|
||||
corsProxy?: string;
|
||||
}
|
||||
@@ -87,6 +87,8 @@
|
||||
"add": "Add",
|
||||
"remove": "Remove",
|
||||
"retry": "Retry",
|
||||
"latestFirst": "Latest First",
|
||||
"oldestFirst": "Oldest First",
|
||||
"name": "Name",
|
||||
"email": "Email",
|
||||
"buildNostrApps": "Build apps with AI",
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
"add": "Ƙara",
|
||||
"remove": "Cire",
|
||||
"retry": "Sake gwadawa",
|
||||
"latestFirst": "Na Baya-bayan nan Da farko",
|
||||
"oldestFirst": "Na Dā Da farko",
|
||||
"name": "Suna",
|
||||
"email": "Imel",
|
||||
"buildNostrApps": "Gina aikace-aikace da AI",
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
"add": "Tinye",
|
||||
"remove": "Wepụ",
|
||||
"retry": "Nwaa ọzọ",
|
||||
"latestFirst": "Nke Ọhụrụ Mbụ",
|
||||
"oldestFirst": "Nke Ochie Mbụ",
|
||||
"name": "Aha",
|
||||
"email": "Ozi-eletrọniki",
|
||||
"buildNostrApps": "Wuo ngwa na AI",
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
"add": "Adicionar",
|
||||
"remove": "Remover",
|
||||
"retry": "Tentar novamente",
|
||||
"latestFirst": "Mais Recentes Primeiro",
|
||||
"oldestFirst": "Mais Antigos Primeiro",
|
||||
"name": "Nome",
|
||||
"email": "Email",
|
||||
"buildNostrApps": "Construa aplicativos com IA",
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
"add": "Fi kun",
|
||||
"remove": "Yọ kuro",
|
||||
"retry": "Tun gbiyanju",
|
||||
"latestFirst": "Tuntun Akọkọ",
|
||||
"oldestFirst": "Atijọ Akọkọ",
|
||||
"name": "Orukọ",
|
||||
"email": "Imeeli",
|
||||
"buildNostrApps": "Kọ awọn ohun elo pẹlu AI",
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
"add": "添加",
|
||||
"remove": "移除",
|
||||
"retry": "重试",
|
||||
"latestFirst": "最新优先",
|
||||
"oldestFirst": "最旧优先",
|
||||
"name": "名称",
|
||||
"email": "邮箱",
|
||||
"buildNostrApps": "使用AI构建应用",
|
||||
|
||||
+26
-161
@@ -45,14 +45,12 @@ import { normalizeUrl } from '@/lib/faviconUrl';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare';
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite';
|
||||
name: string;
|
||||
description: string;
|
||||
requiresNostr?: boolean;
|
||||
apiKeyLabel?: string;
|
||||
apiKeyURL?: string;
|
||||
accountIdLabel?: string;
|
||||
accountIdURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
@@ -188,54 +186,29 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
<PasswordInput
|
||||
id={`provider-${index}-apiKey`}
|
||||
placeholder={t('enterApiKey')}
|
||||
value={
|
||||
provider.type === 'cloudflare' ? provider.apiToken :
|
||||
provider.type === 'netlify' ? provider.apiKey :
|
||||
provider.type === 'vercel' ? provider.apiKey : ''
|
||||
}
|
||||
value={provider.apiKey}
|
||||
onChange={(e) => {
|
||||
if (provider.type === 'netlify') {
|
||||
onUpdate(index, { ...provider, apiKey: e.target.value });
|
||||
} else if (provider.type === 'vercel') {
|
||||
onUpdate(index, { ...provider, apiKey: e.target.value });
|
||||
} else if (provider.type === 'cloudflare') {
|
||||
onUpdate(index, { ...provider, apiToken: e.target.value });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{provider.type === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-accountId`}>
|
||||
Account ID
|
||||
</Label>
|
||||
<Input
|
||||
id={`provider-${index}-accountId`}
|
||||
placeholder="Enter your Cloudflare 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)
|
||||
</Label>
|
||||
<Input
|
||||
id={`provider-${index}-baseURL`}
|
||||
placeholder={
|
||||
provider.type === 'netlify' ? 'https://api.netlify.com/api/v1' :
|
||||
provider.type === 'cloudflare' ? 'https://api.cloudflare.com/client/v4' :
|
||||
'https://api.vercel.com'
|
||||
}
|
||||
placeholder={provider.type === 'netlify' ? 'https://api.netlify.com/api/v1' : 'https://api.vercel.com'}
|
||||
value={provider.baseURL || ''}
|
||||
onChange={(e) => {
|
||||
if (provider.type === 'netlify') {
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
} else if (provider.type === 'vercel') {
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
} else if (provider.type === 'cloudflare') {
|
||||
onUpdate(index, { ...provider, baseURL: e.target.value });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
@@ -283,17 +256,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
name: 'nsite',
|
||||
description: 'Deploy to Nostr as a static website',
|
||||
},
|
||||
{
|
||||
id: 'cloudflare',
|
||||
type: 'cloudflare',
|
||||
name: 'Cloudflare Pages',
|
||||
description: 'Deploy to Cloudflare Pages',
|
||||
apiKeyLabel: 'API Token',
|
||||
apiKeyURL: 'https://dash.cloudflare.com/profile/api-tokens',
|
||||
accountIdLabel: 'Account ID',
|
||||
accountIdURL: 'https://dash.cloudflare.com/',
|
||||
proxy: true,
|
||||
},
|
||||
{
|
||||
id: 'netlify',
|
||||
type: 'netlify',
|
||||
@@ -344,13 +306,6 @@ function getProviderUrl(provider: DeployProvider | PresetProvider): string | nul
|
||||
}
|
||||
return 'https://vercel.com';
|
||||
|
||||
case 'cloudflare':
|
||||
// For Cloudflare providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://cloudflare.com';
|
||||
|
||||
case 'nsite':
|
||||
// nsite uses Rocket icon fallback
|
||||
return null;
|
||||
@@ -372,14 +327,12 @@ export function DeploySettings() {
|
||||
const vercelOAuth = useVercelOAuth();
|
||||
|
||||
const [presetApiKeys, setPresetApiKeys] = useState<Record<string, string>>({});
|
||||
const [presetAccountIds, setPresetAccountIds] = useState<Record<string, string>>({});
|
||||
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
|
||||
|
||||
// Custom provider form state
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | ''>('');
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | ''>('');
|
||||
const [customName, setCustomName] = useState('');
|
||||
const [customApiKey, setCustomApiKey] = useState('');
|
||||
const [customAccountId, setCustomAccountId] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
const [customHost, setCustomHost] = useState('');
|
||||
const [customProxy, setCustomProxy] = useState(false);
|
||||
@@ -413,18 +366,12 @@ export function DeploySettings() {
|
||||
}
|
||||
|
||||
const apiKey = presetApiKeys[preset.id];
|
||||
const accountId = presetAccountIds[preset.id];
|
||||
|
||||
// For non-Shakespeare/non-nsite providers, require API key
|
||||
if (!preset.requiresNostr && preset.type !== 'nsite' && !apiKey?.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For Cloudflare, also require account ID
|
||||
if (preset.type === 'cloudflare' && !accountId?.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let newProvider: DeployProvider;
|
||||
|
||||
if (preset.type === 'shakespeare') {
|
||||
@@ -453,15 +400,6 @@ export function DeploySettings() {
|
||||
'https://cdn.sovbit.host',
|
||||
],
|
||||
};
|
||||
} else if (preset.type === 'cloudflare') {
|
||||
newProvider = {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
name: preset.name,
|
||||
type: 'cloudflare',
|
||||
apiToken: apiKey.trim(),
|
||||
accountId: accountId.trim(),
|
||||
...(preset.proxy && { proxy: true }),
|
||||
};
|
||||
} else if (preset.type === 'netlify') {
|
||||
newProvider = {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
@@ -484,7 +422,6 @@ export function DeploySettings() {
|
||||
|
||||
// Clear inputs
|
||||
setPresetApiKeys(prev => ({ ...prev, [preset.id]: '' }));
|
||||
setPresetAccountIds(prev => ({ ...prev, [preset.id]: '' }));
|
||||
};
|
||||
|
||||
const handleAddCustomProvider = () => {
|
||||
@@ -517,17 +454,6 @@ export function DeploySettings() {
|
||||
relayUrls,
|
||||
blossomServers,
|
||||
};
|
||||
} else if (customProviderType === 'cloudflare') {
|
||||
if (!customApiKey.trim() || !customAccountId.trim()) return;
|
||||
newProvider = {
|
||||
id: generateCustomProviderId(customProviderType), // Generate custom ID
|
||||
name: customName.trim(),
|
||||
type: 'cloudflare',
|
||||
apiToken: customApiKey.trim(),
|
||||
accountId: customAccountId.trim(),
|
||||
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
|
||||
...(customProxy && { proxy: true }),
|
||||
};
|
||||
} else if (customProviderType === 'netlify') {
|
||||
if (!customApiKey.trim()) return;
|
||||
newProvider = {
|
||||
@@ -556,7 +482,6 @@ export function DeploySettings() {
|
||||
setCustomProviderType('');
|
||||
setCustomName('');
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
@@ -769,77 +694,34 @@ export function DeploySettings() {
|
||||
) : (
|
||||
// Show manual token input
|
||||
<div className="space-y-2">
|
||||
{preset.type === 'cloudflare' ? (
|
||||
// Cloudflare needs both API token and Account ID
|
||||
<>
|
||||
<div className="flex gap-2">
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
className="flex-1"
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
/>
|
||||
<Input
|
||||
placeholder={preset.accountIdLabel || 'Account ID'}
|
||||
value={presetAccountIds[preset.id] || ''}
|
||||
onChange={(e) => setPresetAccountIds(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() && presetAccountIds[preset.id]?.trim()) {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{preset.accountIdURL && (
|
||||
<button
|
||||
type="button"
|
||||
className="text-xs text-muted-foreground underline hover:text-foreground"
|
||||
onClick={() => window.open(preset.accountIdURL, '_blank')}
|
||||
>
|
||||
Find your Account ID
|
||||
</button>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={!presetApiKeys[preset.id]?.trim() || !presetAccountIds[preset.id]?.trim()}
|
||||
className="w-full"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
className="flex-1"
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
(!preset.requiresNostr && preset.type !== 'nsite' && !presetApiKeys[preset.id]?.trim())
|
||||
}
|
||||
className={(preset.requiresNostr || preset.type === 'nsite') ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
(!preset.requiresNostr && preset.type !== 'nsite' && !presetApiKeys[preset.id]?.trim())
|
||||
}
|
||||
className={(preset.requiresNostr || preset.type === 'nsite') ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -862,11 +744,10 @@ export function DeploySettings() {
|
||||
<Label htmlFor="custom-provider-type">{t('providerType')}</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare') => {
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
@@ -881,7 +762,6 @@ export function DeploySettings() {
|
||||
<SelectContent>
|
||||
<SelectItem value="shakespeare">Shakespeare Deploy</SelectItem>
|
||||
<SelectItem value="nsite">nsite</SelectItem>
|
||||
<SelectItem value="cloudflare">Cloudflare Pages</SelectItem>
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
</SelectContent>
|
||||
@@ -952,8 +832,7 @@ export function DeploySettings() {
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'cloudflare' ? 'API Token' :
|
||||
customProviderType === 'netlify' ? 'Personal Access Token' : 'Access Token'}
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' : 'Access Token'}
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
@@ -962,27 +841,14 @@ export function DeploySettings() {
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{customProviderType === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-accountid">Account ID</Label>
|
||||
<Input
|
||||
id="custom-accountid"
|
||||
placeholder="Enter your Cloudflare Account ID"
|
||||
value={customAccountId}
|
||||
onChange={(e) => setCustomAccountId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
||||
<Input
|
||||
id="custom-baseurl"
|
||||
placeholder={
|
||||
customProviderType === 'cloudflare'
|
||||
? 'https://api.cloudflare.com/client/v4'
|
||||
: customProviderType === 'netlify'
|
||||
? 'https://api.netlify.com/api/v1'
|
||||
: 'https://api.vercel.com'
|
||||
customProviderType === 'netlify'
|
||||
? 'https://api.netlify.com/api/v1'
|
||||
: 'https://api.vercel.com'
|
||||
}
|
||||
value={customBaseURL}
|
||||
onChange={(e) => setCustomBaseURL(e.target.value)}
|
||||
@@ -1007,8 +873,7 @@ export function DeploySettings() {
|
||||
disabled={
|
||||
!customProviderType ||
|
||||
!customName.trim() ||
|
||||
(customProviderType === 'cloudflare' && (!customApiKey.trim() || !customAccountId.trim())) ||
|
||||
(customProviderType !== 'shakespeare' && customProviderType !== 'nsite' && customProviderType !== 'cloudflare' && !customApiKey.trim())
|
||||
(customProviderType !== 'shakespeare' && customProviderType !== 'nsite' && !customApiKey.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user