Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/src/__tests__/wdttLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,22 @@ describe('parseWdttUrl', () => {
it('qwdtt без query string → null', () => {
expect(parseWdttUrl('qwdtt://config')).toBeNull();
});

it('workers=abc → undefined', () => {
const link = parseWdttUrl('qwdtt://config?peer=1.2.3.4:5555&pass=secret&workers=abc');
expect(link).not.toBeNull();
expect(link!.workers).toBeUndefined();
});

it('workers=-5 → undefined', () => {
const link = parseWdttUrl('qwdtt://config?peer=1.2.3.4:5555&pass=secret&workers=-5');
expect(link).not.toBeNull();
expect(link!.workers).toBeUndefined();
});

it('workers=9999 → undefined', () => {
const link = parseWdttUrl('qwdtt://config?peer=1.2.3.4:5555&pass=secret&workers=9999');
expect(link).not.toBeNull();
expect(link!.workers).toBeUndefined();
});
});
14 changes: 13 additions & 1 deletion frontend/src/lib/utils/wdttLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,23 @@ function parseQwdttConfig(raw: string): WdttLink | null {
if (!peer || !pass) return null;

const hashes = hashesStr.split(',').map(h => h.trim()).filter(Boolean);
const workers = workersStr ? parseInt(workersStr, 10) : undefined;
const workers = parseWorkers(workersStr);

return { name, host: peer, password: pass, hashes, workers, port };
}

// workers валиден только как целое число в диапазоне 9–108 (4 хеша × 27).
// Любой мусор (NaN, вне диапазона, нечисловой) → undefined, без clamp.
function parseWorkers(workersStr: string): number | undefined {
if (!workersStr) return undefined;
const trimmed = workersStr.trim();
if (!/^-?\d+$/.test(trimmed)) return undefined;
const n = Number(trimmed);
if (!Number.isFinite(n) || !Number.isInteger(n)) return undefined;
if (n < 9 || n > 108) return undefined;
return n;
}

// Парсинг старого формата: wdtt://IP:DTLS:WG:PROXY:PASSWORD[:HASHES][#name]
function parseLegacyWdtt(raw: string): WdttLink | null {
const stripped = raw.replace(/^wdtt:\/\//, '');
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modals/Add-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function AddServer({ onClose, onAdd }: Props) {

<div className="as-slider-wrap">
<div className="as-slider-label">
<span>Мощность</span>
<span>Количество воркеров</span>
<span>{filledHashes === 0 ? 'нет хешей' : power}</span>
</div>
<input
Expand All @@ -148,7 +148,7 @@ export default function AddServer({ onClose, onAdd }: Props) {
disabled={filledHashes === 0}
style={{ '--v': filledHashes > 0 ? Math.round((Math.min(power, powerMax) - 9) / Math.max(powerMax - 9, 1) * 100) : 0 } as React.CSSProperties}
onChange={e => setPower(+e.target.value)}
aria-label="Мощность"
aria-label="Количество воркеров"
/>
</div>

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modals/Edit-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function EditServer({ server, onClose, onSave, onDelete }: Props)

<div className="es-slider-wrap">
<div className="es-slider-label">
<span>Мощность</span>
<span>Количество воркеров</span>
<span>{filledHashes === 0 ? 'нет хешей' : power}</span>
</div>
<input
Expand All @@ -137,7 +137,7 @@ export default function EditServer({ server, onClose, onSave, onDelete }: Props)
disabled={filledHashes === 0}
style={{ '--v': filledHashes > 0 ? Math.round((Math.min(power, powerMax) - 9) / Math.max(powerMax - 9, 1) * 100) : 0 } as React.CSSProperties}
onChange={e => setPower(+e.target.value)}
aria-label="Мощность"
aria-label="Количество воркеров"
/>
</div>

Expand Down