proxied fetch support
This commit is contained in:
@@ -63,6 +63,7 @@ class CommonStore {
|
||||
monitorData: MonitorData | null = null;
|
||||
depComplete: boolean = false;
|
||||
platform: Platform = 'windows';
|
||||
proxyPort: number = 0;
|
||||
lastModelName: string = '';
|
||||
// presets manager
|
||||
editingPreset: Preset | null = null;
|
||||
@@ -323,6 +324,10 @@ class CommonStore {
|
||||
this.platform = value;
|
||||
}
|
||||
|
||||
setProxyPort(value: number) {
|
||||
this.proxyPort = value;
|
||||
}
|
||||
|
||||
setCurrentInput(value: string) {
|
||||
this.currentInput = value;
|
||||
}
|
||||
|
||||
@@ -310,6 +310,24 @@ export function bytesToReadable(size: number) {
|
||||
else return bytesToGb(size) + ' GB';
|
||||
}
|
||||
|
||||
export async function getReqUrl(port: number, path: string, isCore: boolean = false): Promise<{
|
||||
url: string,
|
||||
headers: { [key: string]: string }
|
||||
}> {
|
||||
const realUrl = getServerRoot(port, isCore) + path;
|
||||
if (commonStore.platform === 'web')
|
||||
return {
|
||||
url: realUrl,
|
||||
headers: {}
|
||||
};
|
||||
if (!commonStore.proxyPort)
|
||||
await GetProxyPort().then(p => commonStore.setProxyPort(p));
|
||||
return {
|
||||
url: `http://127.0.0.1:${commonStore.proxyPort}`,
|
||||
headers: { 'Real-Target': realUrl }
|
||||
};
|
||||
}
|
||||
|
||||
export function getServerRoot(defaultLocalPort: number, isCore: boolean = false) {
|
||||
const coreCustomApiUrl = commonStore.settings.coreApiUrl.trim().replace(/\/$/, '');
|
||||
if (isCore && coreCustomApiUrl)
|
||||
|
||||
@@ -115,6 +115,12 @@ if (!window.go) {
|
||||
defineApp('ListDirFiles', async () => {
|
||||
return []
|
||||
})
|
||||
defineApp('GetAbsPath', async (path) => {
|
||||
return path
|
||||
})
|
||||
defineApp('GetProxyPort', async () => {
|
||||
return 0
|
||||
})
|
||||
defineApp('OpenOpenFileDialog', webOpenOpenFileDialog)
|
||||
defineApp('OpenSaveFileDialog', async (filterPattern, defaultFileName, savedContent) => {
|
||||
const saver = await import('file-saver')
|
||||
|
||||
Reference in New Issue
Block a user