mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Git proxy origins are configured separately from git credentials
This commit is contained in:
15 files changed
+35
-47
No files matched your search
@@ -132,6 +132,7 @@ const defaultConfig: AppConfig = {
|
||||
],
|
||||
esmUrl: "https://esm.sh",
|
||||
corsProxy: "https://proxy.shakespeare.diy/?url={href}",
|
||||
gitProxyOrigins: ["https://github.com", "https://gitlab.com"],
|
||||
faviconUrl: "https://favicon.shakespeare.diy/?url={href}",
|
||||
ngitWebUrl: "https://nostrhub.io/{naddr}",
|
||||
previewDomain: "local-shakespeare.dev",
|
||||
|
||||
@@ -45,6 +45,7 @@ const AppConfigSchema = z.object({
|
||||
templates: z.array(ProjectTemplateSchema),
|
||||
esmUrl: z.string().url(),
|
||||
corsProxy: z.string().url(),
|
||||
gitProxyOrigins: z.array(z.string()),
|
||||
faviconUrl: z.string().url(),
|
||||
ngitWebUrl: z.string().url(),
|
||||
previewDomain: z.string().min(1),
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('SentryProvider', () => {
|
||||
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy: 'https://proxy.test/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://favicon.test/{href}',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
@@ -75,6 +76,7 @@ describe('SentryProvider', () => {
|
||||
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy: 'https://proxy.test/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://favicon.test/{href}',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
@@ -117,6 +119,7 @@ describe('SentryProvider', () => {
|
||||
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy: 'https://proxy.test/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://favicon.test/{href}',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
@@ -162,6 +165,7 @@ describe('SentryProvider', () => {
|
||||
templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }],
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy: 'https://proxy.test/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://favicon.test/{href}',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
|
||||
@@ -38,6 +38,8 @@ export interface AppConfig {
|
||||
esmUrl: string;
|
||||
/** HTTP proxy used to bypass CORS for AI and Git operations */
|
||||
corsProxy: string;
|
||||
/** Git origins that should use the CORS proxy (e.g., ["https://github.com", "https://gitlab.com"]) */
|
||||
gitProxyOrigins: string[];
|
||||
/** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */
|
||||
faviconUrl: string;
|
||||
/** Nostr Git web URL template (e.g., "https://nostrhub.io/{naddr}") */
|
||||
|
||||
@@ -6,7 +6,6 @@ export interface GitCredential {
|
||||
origin: string; // Full origin URL (e.g., "https://github.com")
|
||||
username: string;
|
||||
password: string;
|
||||
proxy?: boolean; // Whether to use a proxy for this credential
|
||||
}
|
||||
|
||||
export interface GitSettings {
|
||||
|
||||
@@ -63,6 +63,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
templates: defaultTemplates,
|
||||
esmUrl: 'https://esm.sh',
|
||||
corsProxy: 'https://proxy.example.com/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
@@ -224,6 +225,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
templates: [],
|
||||
esmUrl: 'https://esm.sh',
|
||||
corsProxy: 'https://proxy.example.com/{href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
|
||||
@@ -40,6 +40,7 @@ function createWrapper(corsProxy: string) {
|
||||
templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy,
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-test.dev',
|
||||
@@ -93,6 +94,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }],
|
||||
graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
|
||||
credentials: [],
|
||||
@@ -110,6 +112,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://custom-cors.example.com',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }],
|
||||
graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
|
||||
credentials: [],
|
||||
@@ -127,6 +130,7 @@ describe('useGit', () => {
|
||||
fs: mockFS,
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
relayList: [{ url: new URL('wss://relay.test/'), read: true, write: true }],
|
||||
graspList: [{ url: new URL('wss://git.shakespeare.diy/') }, { url: new URL('wss://relay.ngit.dev/') }],
|
||||
credentials: [],
|
||||
|
||||
+3
-2
@@ -16,7 +16,7 @@ export function useGit(): { git: Git } {
|
||||
const { nostr } = useNostr();
|
||||
const { config } = useAppContext();
|
||||
const { settings } = useGitSettings();
|
||||
const { corsProxy, relayMetadata, graspMetadata } = config;
|
||||
const { corsProxy, gitProxyOrigins, relayMetadata, graspMetadata } = config;
|
||||
|
||||
const relayList = useMemo(() => {
|
||||
// Extract hostnames from grasp relay URLs for backwards compatibility with Git class
|
||||
@@ -45,12 +45,13 @@ export function useGit(): { git: Git } {
|
||||
fs,
|
||||
nostr,
|
||||
corsProxy,
|
||||
gitProxyOrigins,
|
||||
relayList,
|
||||
graspList,
|
||||
credentials: settings.credentials,
|
||||
signer: user?.signer,
|
||||
});
|
||||
}, [fs, nostr, corsProxy, relayList, graspList, settings.credentials, user?.signer]);
|
||||
}, [fs, nostr, corsProxy, gitProxyOrigins, relayList, graspList, settings.credentials, user?.signer]);
|
||||
|
||||
return { git };
|
||||
}
|
||||
@@ -43,6 +43,7 @@ const testConfig: AppConfig = {
|
||||
templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
|
||||
@@ -162,7 +162,6 @@ describe('configUtils', () => {
|
||||
origin: 'https://github.com',
|
||||
username: 'user',
|
||||
password: 'token123',
|
||||
proxy: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -64,7 +64,6 @@ const gitCredentialSchema = z.object({
|
||||
origin: z.string(),
|
||||
username: z.string(),
|
||||
password: z.string(),
|
||||
proxy: z.boolean().optional(),
|
||||
});
|
||||
|
||||
// Old format (map of origins to credentials)
|
||||
@@ -284,13 +283,6 @@ export async function readGitSettings(fs: JSRuntimeFS, configPath = '/config'):
|
||||
credentials = convertCredentialsToNewFormat(parsed.credentials);
|
||||
}
|
||||
|
||||
// Set default proxy settings if missing
|
||||
for (const cred of credentials) {
|
||||
if (!('proxy' in cred)) {
|
||||
cred.proxy = ['https://github.com', 'https://gitlab.com'].includes(cred.origin);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...parsed,
|
||||
credentials,
|
||||
|
||||
+15
-5
@@ -16,12 +16,13 @@ export interface GitOptions {
|
||||
signer?: NostrSigner;
|
||||
credentials?: GitCredential[];
|
||||
corsProxy?: string;
|
||||
gitProxyOrigins?: string[];
|
||||
fetch?: typeof globalThis.fetch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Git class that wraps isomorphic-git and provides a cleaner interface.
|
||||
* Instantiate with an fs implementation, optional corsProxy string, and optional corsProxyRegex.
|
||||
* Instantiate with an fs implementation, optional corsProxy string, and optional gitProxyOrigins list.
|
||||
* All methods have the same names as isomorphic-git but don't require
|
||||
* passing fs, http, and corsProxy each time.
|
||||
*/
|
||||
@@ -33,6 +34,7 @@ export class Git {
|
||||
private systemAuthor: { name: string; email: string };
|
||||
private signer?: NostrSigner;
|
||||
private corsProxy?: string;
|
||||
private gitProxyOrigins: string[];
|
||||
private credentials?: GitCredential[];
|
||||
private customFetch?: typeof globalThis.fetch;
|
||||
|
||||
@@ -40,6 +42,7 @@ export class Git {
|
||||
this.fs = options.fs;
|
||||
this.nostr = options.nostr;
|
||||
this.corsProxy = options.corsProxy;
|
||||
this.gitProxyOrigins = options.gitProxyOrigins ?? [];
|
||||
this.relayList = options.relayList;
|
||||
this.graspList = options.graspList;
|
||||
this.systemAuthor = options.systemAuthor ?? {
|
||||
@@ -65,15 +68,22 @@ export class Git {
|
||||
|
||||
// Get HTTP adapter for the given URL
|
||||
private httpForUrl(url: string | null | undefined): HttpClient {
|
||||
if (url?.startsWith('nostr://')) {
|
||||
if (!url || url.startsWith('nostr://')) {
|
||||
return new GitHttp(undefined, this.customFetch);
|
||||
}
|
||||
if (this.credentials && url) {
|
||||
const cred = findCredentialsForRepo(url, this.credentials);
|
||||
if (cred && cred.proxy) {
|
||||
|
||||
// Check if the URL's origin is in the proxy origins list
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
const origin = urlObj.origin;
|
||||
|
||||
if (this.gitProxyOrigins.includes(origin)) {
|
||||
return new GitHttp(this.corsProxy, this.customFetch);
|
||||
}
|
||||
} catch {
|
||||
// Invalid URL, don't use proxy
|
||||
}
|
||||
|
||||
return new GitHttp(undefined, this.customFetch);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ const testConfig: AppConfig = {
|
||||
templates: [{ name: 'MKStack', description: 'Build Nostr clients with React.', url: 'https://gitlab.com/soapbox-pub/mkstack.git' }],
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
|
||||
@@ -24,7 +24,6 @@ import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
@@ -49,7 +48,6 @@ interface PresetProvider {
|
||||
origin: string;
|
||||
username: string;
|
||||
tokenURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
@@ -59,7 +57,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
origin: "https://github.com",
|
||||
username: "git",
|
||||
tokenURL: "https://github.com/settings/tokens",
|
||||
proxy: true,
|
||||
},
|
||||
{
|
||||
id: "gitlab",
|
||||
@@ -67,7 +64,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
origin: "https://gitlab.com",
|
||||
username: "git",
|
||||
tokenURL: "https://gitlab.com/-/user_settings/personal_access_tokens",
|
||||
proxy: true,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -177,18 +173,6 @@ function SortableCredentialItem({ credential, onUpdate, onRemove, showDragHandle
|
||||
onChange={(e) => updateCredential({ password: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={`credential-${credential.id}-proxy`}
|
||||
checked={credential.proxy || false}
|
||||
onCheckedChange={(checked) => updateCredential({
|
||||
proxy: checked === true || undefined
|
||||
})}
|
||||
/>
|
||||
<Label htmlFor={`credential-${credential.id}-proxy`} className="cursor-pointer">
|
||||
{t('useCorsProxy')}
|
||||
</Label>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
@@ -211,7 +195,6 @@ export function GitSettings() {
|
||||
const [customOrigin, setCustomOrigin] = useState('');
|
||||
const [customUsername, setCustomUsername] = useState('');
|
||||
const [customPassword, setCustomPassword] = useState('');
|
||||
const [customProxy, setCustomProxy] = useState(false);
|
||||
const [presetTokens, setPresetTokens] = useState<Record<string, string>>({});
|
||||
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
|
||||
|
||||
@@ -233,7 +216,6 @@ export function GitSettings() {
|
||||
origin: preset.origin,
|
||||
username: preset.username,
|
||||
password: token.trim(),
|
||||
proxy: preset.proxy,
|
||||
};
|
||||
|
||||
// Auto-save: Add credential immediately to persistent storage
|
||||
@@ -255,7 +237,6 @@ export function GitSettings() {
|
||||
origin: customOrigin.trim(),
|
||||
username: customUsername.trim(),
|
||||
password: customPassword.trim(),
|
||||
proxy: customProxy || undefined,
|
||||
};
|
||||
|
||||
// Auto-save: Add credential immediately to persistent storage
|
||||
@@ -265,7 +246,6 @@ export function GitSettings() {
|
||||
setCustomOrigin('');
|
||||
setCustomUsername('');
|
||||
setCustomPassword('');
|
||||
setCustomProxy(false);
|
||||
};
|
||||
|
||||
const handleRemoveCredential = (id: string) => {
|
||||
@@ -559,16 +539,6 @@ export function GitSettings() {
|
||||
onChange={(e) => setCustomPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="custom-proxy"
|
||||
checked={customProxy}
|
||||
onCheckedChange={(checked) => setCustomProxy(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="custom-proxy" className="cursor-pointer">
|
||||
{t('useCorsProxy')}
|
||||
</Label>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
|
||||
@@ -44,6 +44,7 @@ export function TestApp({ children }: TestAppProps) {
|
||||
],
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
|
||||
gitProxyOrigins: ['https://github.com', 'https://gitlab.com'],
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
|
||||
Reference in new issue
Block a user