mirror of
https://github.com/lone-cloud/gerbil
synced 2026-06-03 19:54:44 -07:00
allow port to be clearable, store cloudflared bin in gerbil installation directory
This commit is contained in:
parent
b6cf119ff5
commit
c35ecff633
3 changed files with 18 additions and 15 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -13,5 +13,5 @@
|
||||||
"editor.defaultFormatter": "prettier.prettier-vscode",
|
"editor.defaultFormatter": "prettier.prettier-vscode",
|
||||||
"[typescriptreact]": {
|
"[typescriptreact]": {
|
||||||
"editor.defaultFormatter": "prettier.prettier-vscode"
|
"editor.defaultFormatter": "prettier.prettier-vscode"
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import { Stack, Text, TextInput, Group } from '@mantine/core';
|
import { Stack, Text, TextInput, Group } from '@mantine/core';
|
||||||
import { useState } from 'react';
|
|
||||||
import { InfoTooltip } from '@/components/InfoTooltip';
|
import { InfoTooltip } from '@/components/InfoTooltip';
|
||||||
import { CheckboxWithTooltip } from '@/components/CheckboxWithTooltip';
|
import { CheckboxWithTooltip } from '@/components/CheckboxWithTooltip';
|
||||||
import { useLaunchConfigStore } from '@/stores/launchConfig';
|
import { useLaunchConfigStore } from '@/stores/launchConfig';
|
||||||
|
|
@ -21,7 +20,6 @@ export const NetworkTab = () => {
|
||||||
setNocertify,
|
setNocertify,
|
||||||
setWebsearch,
|
setWebsearch,
|
||||||
} = useLaunchConfigStore();
|
} = useLaunchConfigStore();
|
||||||
const [portInput, setPortInput] = useState('');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
|
|
@ -49,12 +47,12 @@ export const NetworkTab = () => {
|
||||||
</Group>
|
</Group>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder="5001"
|
placeholder="5001"
|
||||||
value={portInput || port?.toString() || ''}
|
value={port?.toString() ?? ''}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
const value = event.currentTarget.value;
|
const value = event.currentTarget.value;
|
||||||
setPortInput(value);
|
|
||||||
|
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
|
setPort(undefined);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,13 +61,6 @@ export const NetworkTab = () => {
|
||||||
setPort(numValue);
|
setPort(numValue);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={(event) => {
|
|
||||||
const value = event.currentTarget.value;
|
|
||||||
if (value === '') {
|
|
||||||
setPort(undefined);
|
|
||||||
setPortInput('');
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
max={65535}
|
max={65535}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { Tunnel, bin, install } from 'cloudflared';
|
import path from 'path';
|
||||||
|
import { Tunnel, install } from 'cloudflared';
|
||||||
|
import { platform } from 'process';
|
||||||
|
|
||||||
import { logError } from '@/utils/node/logging';
|
import { logError } from '@/utils/node/logging';
|
||||||
import { sendKoboldOutput, sendToRenderer } from '../window';
|
import { sendKoboldOutput, sendToRenderer } from '../window';
|
||||||
import { PROXY } from '@/constants/proxy';
|
import { PROXY } from '@/constants/proxy';
|
||||||
import { SILLYTAVERN, OPENWEBUI } from '@/constants';
|
import { SILLYTAVERN, OPENWEBUI } from '@/constants';
|
||||||
|
import { getInstallDir } from '@/main/modules/config';
|
||||||
import type { FrontendPreference } from '@/types';
|
import type { FrontendPreference } from '@/types';
|
||||||
|
|
||||||
let activeTunnel: Tunnel | null = null;
|
let activeTunnel: Tunnel | null = null;
|
||||||
let tunnelUrl: string | null = null;
|
let tunnelUrl: string | null = null;
|
||||||
|
|
||||||
|
const getCloudflaredBin = () => {
|
||||||
|
const binName = platform === 'win32' ? 'cloudflared.exe' : 'cloudflared';
|
||||||
|
return path.join(getInstallDir(), binName);
|
||||||
|
};
|
||||||
|
|
||||||
const getTunnelTarget = (frontendPreference: FrontendPreference) => {
|
const getTunnelTarget = (frontendPreference: FrontendPreference) => {
|
||||||
switch (frontendPreference) {
|
switch (frontendPreference) {
|
||||||
case 'sillytavern':
|
case 'sillytavern':
|
||||||
|
|
@ -31,14 +39,18 @@ export const startTunnel = async (
|
||||||
try {
|
try {
|
||||||
sendKoboldOutput('Starting Cloudflare tunnel...');
|
sendKoboldOutput('Starting Cloudflare tunnel...');
|
||||||
|
|
||||||
|
const bin = getCloudflaredBin();
|
||||||
|
|
||||||
if (!fs.existsSync(bin)) {
|
if (!fs.existsSync(bin)) {
|
||||||
sendKoboldOutput('Installing cloudflared binary...');
|
sendKoboldOutput('Installing cloudflared binary...');
|
||||||
await install(bin);
|
await install(bin);
|
||||||
sendKoboldOutput('cloudflared binary installed');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const tunnelTarget = getTunnelTarget(frontendPreference);
|
const tunnelTarget = getTunnelTarget(frontendPreference);
|
||||||
const tunnel = Tunnel.quick(tunnelTarget, { '--no-autoupdate': true });
|
const tunnel = Tunnel.quick(tunnelTarget, {
|
||||||
|
'--no-autoupdate': true,
|
||||||
|
bin,
|
||||||
|
});
|
||||||
activeTunnel = tunnel;
|
activeTunnel = tunnel;
|
||||||
|
|
||||||
let rateLimited = false;
|
let rateLimited = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue