109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
// File path utilities
|
|
export function basenameNoExt(filePath: string): string {
|
|
const VALID_EXTENSIONS = [".tar.gz", ".zip"];
|
|
|
|
// handle VALID extensions first
|
|
for (const ext of VALID_EXTENSIONS) {
|
|
if (filePath.toLowerCase().endsWith(ext)) {
|
|
return filePath.slice(0, -ext.length);
|
|
}
|
|
}
|
|
|
|
// fallback: remove only the last extension
|
|
const lastDotIndex = filePath.lastIndexOf('.');
|
|
if (lastDotIndex > 0) {
|
|
return filePath.slice(0, lastDotIndex);
|
|
}
|
|
|
|
return filePath;
|
|
}
|
|
|
|
// Zustand proxy state structure
|
|
interface ProxyState {
|
|
proxyEnabled: boolean
|
|
proxyUrl: string
|
|
proxyUsername: string
|
|
proxyPassword: string
|
|
proxyIgnoreSSL: boolean
|
|
verifyProxySSL: boolean
|
|
verifyProxyHostSSL: boolean
|
|
verifyPeerSSL: boolean
|
|
verifyHostSSL: boolean
|
|
noProxy: string
|
|
}
|
|
|
|
export function getProxyConfig(): Record<
|
|
string,
|
|
string | string[] | boolean
|
|
> | null {
|
|
try {
|
|
// Retrieve proxy configuration from localStorage
|
|
const proxyConfigString = localStorage.getItem('setting-proxy-config')
|
|
if (!proxyConfigString) {
|
|
return null
|
|
}
|
|
|
|
const proxyConfigData = JSON.parse(proxyConfigString)
|
|
|
|
const proxyState: ProxyState = proxyConfigData?.state
|
|
|
|
// Only return proxy config if proxy is enabled
|
|
if (!proxyState || !proxyState.proxyEnabled || !proxyState.proxyUrl) {
|
|
return null
|
|
}
|
|
|
|
const proxyConfig: Record<string, string | string[] | boolean> = {
|
|
url: proxyState.proxyUrl,
|
|
}
|
|
|
|
// Add username/password if both are provided
|
|
if (proxyState.proxyUsername && proxyState.proxyPassword) {
|
|
proxyConfig.username = proxyState.proxyUsername
|
|
proxyConfig.password = proxyState.proxyPassword
|
|
}
|
|
|
|
// Parse no_proxy list if provided
|
|
if (proxyState.noProxy) {
|
|
const noProxyList = proxyState.noProxy
|
|
.split(',')
|
|
.map((s: string) => s.trim())
|
|
.filter((s: string) => s.length > 0)
|
|
|
|
if (noProxyList.length > 0) {
|
|
proxyConfig.no_proxy = noProxyList
|
|
}
|
|
}
|
|
|
|
// Add SSL verification settings
|
|
proxyConfig.ignore_ssl = proxyState.proxyIgnoreSSL
|
|
proxyConfig.verify_proxy_ssl = proxyState.verifyProxySSL
|
|
proxyConfig.verify_proxy_host_ssl = proxyState.verifyProxyHostSSL
|
|
proxyConfig.verify_peer_ssl = proxyState.verifyPeerSSL
|
|
proxyConfig.verify_host_ssl = proxyState.verifyHostSSL
|
|
|
|
// Log proxy configuration for debugging
|
|
console.log('Using proxy configuration:', {
|
|
url: proxyState.proxyUrl,
|
|
hasAuth: !!(proxyState.proxyUsername && proxyState.proxyPassword),
|
|
noProxyCount: proxyConfig.no_proxy
|
|
? (proxyConfig.no_proxy as string[]).length
|
|
: 0,
|
|
ignoreSSL: proxyState.proxyIgnoreSSL,
|
|
verifyProxySSL: proxyState.verifyProxySSL,
|
|
verifyProxyHostSSL: proxyState.verifyProxyHostSSL,
|
|
verifyPeerSSL: proxyState.verifyPeerSSL,
|
|
verifyHostSSL: proxyState.verifyHostSSL,
|
|
})
|
|
|
|
return proxyConfig
|
|
} catch (error) {
|
|
console.error('Failed to parse proxy configuration:', error)
|
|
if (error instanceof SyntaxError) {
|
|
// JSON parsing error - return null
|
|
return null
|
|
}
|
|
// Other errors (like missing state) - throw
|
|
throw error
|
|
}
|
|
}
|