.
This commit is contained in:
1 parent
843e6435cc
commit
987ad74de0
3 files changed
+50
-15
No files matched your search
@@ -14,9 +14,12 @@ import { CLOCK_CALIBRATION_DEFAULTS } from '../type/reservation'
|
|||||||
|
|
||||||
const MAX_SALVO_ATTEMPTS = 8
|
const MAX_SALVO_ATTEMPTS = 8
|
||||||
|
|
||||||
// n개의 토큰을 목표 시각 0을 중심으로 stepMs 간격으로 대칭 배치한 오프셋 목록을 만든다.
|
// 토큰 수별 기본 오프셋: 1개는 +0, 그 이상은 -50 헤지 하나 뒤로 0부터 +50씩 증가.
|
||||||
function symmetricOffsets(count: number, stepMs: number) {
|
// 1→[0] · 2→[-50,0] · 3→[-50,0,50] · 4→[-50,0,50,100] · …
|
||||||
return Array.from({ length: count }, (_, index) => Math.round((index - (count - 1) / 2) * stepMs))
|
export function defaultSalvoOffsets(count: number) {
|
||||||
|
if (count <= 0) return []
|
||||||
|
if (count === 1) return [0]
|
||||||
|
return [-50, ...Array.from({ length: count - 1 }, (_, index) => index * 50)]
|
||||||
}
|
}
|
||||||
|
|
||||||
const KST_OFFSET_MS = 9 * 60 * 60 * 1_000
|
const KST_OFFSET_MS = 9 * 60 * 60 * 1_000
|
||||||
@@ -135,7 +138,7 @@ export default function AutomationPanel({
|
|||||||
const [settingsOpen, setSettingsOpen] = useState(false)
|
const [settingsOpen, setSettingsOpen] = useState(false)
|
||||||
const [clockSettings, setClockSettings] = useState<ClockCalibrationSettings>(loadClockSettings)
|
const [clockSettings, setClockSettings] = useState<ClockCalibrationSettings>(loadClockSettings)
|
||||||
const [tokens, setTokens] = useState<CaptchaResult[]>([])
|
const [tokens, setTokens] = useState<CaptchaResult[]>([])
|
||||||
const [salvoStepMs, setSalvoStepMs] = useState(300)
|
const [offsets, setOffsets] = useState<number[]>([])
|
||||||
const [stopOnSuccess, setStopOnSuccess] = useState(true)
|
const [stopOnSuccess, setStopOnSuccess] = useState(true)
|
||||||
const [salvoState, setSalvoState] = useState<AutoSalvoState>({ status: 'idle', stopOnSuccess: true, attempts: [] })
|
const [salvoState, setSalvoState] = useState<AutoSalvoState>({ status: 'idle', stopOnSuccess: true, attempts: [] })
|
||||||
const [salvoBusy, setSalvoBusy] = useState<'token' | 'arm' | null>(null)
|
const [salvoBusy, setSalvoBusy] = useState<'token' | 'arm' | null>(null)
|
||||||
@@ -157,13 +160,13 @@ export default function AutomationPanel({
|
|||||||
const armed = autoState.status === 'armed' || autoState.status === 'firing'
|
const armed = autoState.status === 'armed' || autoState.status === 'firing'
|
||||||
const salvoArmed = salvoState.status === 'armed' || salvoState.status === 'firing'
|
const salvoArmed = salvoState.status === 'armed' || salvoState.status === 'firing'
|
||||||
const attemptCount = Math.min(tokens.length, MAX_SALVO_ATTEMPTS)
|
const attemptCount = Math.min(tokens.length, MAX_SALVO_ATTEMPTS)
|
||||||
const salvoOffsets = useMemo(() => symmetricOffsets(attemptCount, salvoStepMs), [attemptCount, salvoStepMs])
|
|
||||||
const salvoTokenState = tokens.slice(0, attemptCount).map((token, index) => {
|
const salvoTokenState = tokens.slice(0, attemptCount).map((token, index) => {
|
||||||
const effectiveTargetServerMs = targetServerTimeMs + userOffsetMs + salvoOffsets[index]
|
const offsetMs = offsets[index] ?? 0
|
||||||
|
const effectiveTargetServerMs = targetServerTimeMs + userOffsetMs + offsetMs
|
||||||
const ageAtTargetMs = Number.isFinite(effectiveTargetServerMs)
|
const ageAtTargetMs = Number.isFinite(effectiveTargetServerMs)
|
||||||
? effectiveTargetServerMs - (token.solvedAtMs + (clock?.offsetMs ?? 0))
|
? effectiveTargetServerMs - (token.solvedAtMs + (clock?.offsetMs ?? 0))
|
||||||
: Number.POSITIVE_INFINITY
|
: Number.POSITIVE_INFINITY
|
||||||
return { token, offsetMs: salvoOffsets[index], ageAtTargetMs, ready: ageAtTargetMs >= 0 && ageAtTargetMs <= 90_000 }
|
return { token, offsetMs, ageAtTargetMs, ready: ageAtTargetMs >= 0 && ageAtTargetMs <= 90_000 }
|
||||||
})
|
})
|
||||||
const salvoReady = attemptCount > 0 && salvoBaseRequest !== null && Number.isFinite(targetServerTimeMs) && salvoTokenState.every((item) => item.ready)
|
const salvoReady = attemptCount > 0 && salvoBaseRequest !== null && Number.isFinite(targetServerTimeMs) && salvoTokenState.every((item) => item.ready)
|
||||||
|
|
||||||
@@ -219,6 +222,15 @@ export default function AutomationPanel({
|
|||||||
}
|
}
|
||||||
}, [autoState, onResult, onTokenConsumed])
|
}, [autoState, onResult, onTokenConsumed])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 토큰 수가 바뀌면 오프셋 배열 길이를 맞춘다. 기존 편집값은 유지하고, 새로 늘어난 칸만 기본 패턴으로 채운다.
|
||||||
|
setOffsets((current) => {
|
||||||
|
if (current.length === attemptCount) return current
|
||||||
|
const fallback = defaultSalvoOffsets(attemptCount)
|
||||||
|
return Array.from({ length: attemptCount }, (_, index) => current[index] ?? fallback[index])
|
||||||
|
})
|
||||||
|
}, [attemptCount])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (previousSalvoStatus.current !== salvoState.status) {
|
if (previousSalvoStatus.current !== salvoState.status) {
|
||||||
if (salvoState.status === 'succeeded' && salvoState.result) {
|
if (salvoState.status === 'succeeded' && salvoState.result) {
|
||||||
@@ -468,10 +480,15 @@ export default function AutomationPanel({
|
|||||||
<p className="mt-3 text-[10px] leading-4 text-ink-muted">토큰이 없습니다. ‘토큰 생성’을 눌러 인증 창에서 캡차를 풀면 토큰이 하나씩 쌓입니다.</p>
|
<p className="mt-3 text-[10px] leading-4 text-ink-muted">토큰이 없습니다. ‘토큰 생성’을 눌러 인증 창에서 캡차를 풀면 토큰이 하나씩 쌓입니다.</p>
|
||||||
) : (
|
) : (
|
||||||
<ul className="mt-3 space-y-1.5">
|
<ul className="mt-3 space-y-1.5">
|
||||||
{salvoTokenState.map((item) => (
|
{salvoTokenState.map((item, index) => (
|
||||||
<li key={item.token.solvedAtMs} className="flex items-center justify-between gap-3 rounded-lg border border-line-soft bg-surface px-3 py-2 text-[10px]">
|
<li key={item.token.solvedAtMs} className="flex items-center gap-3 rounded-lg border border-line-soft bg-surface px-3 py-2 text-[10px]">
|
||||||
<span className="font-mono text-ink-muted">{item.token.token.slice(0, 6)}••••{item.token.token.slice(-4)}</span>
|
<span className="font-mono text-ink-muted">{index + 1}. {item.token.token.slice(0, 6)}••••{item.token.token.slice(-4)}</span>
|
||||||
<span className={`font-semibold tabular-nums ${item.ready ? 'text-success' : 'text-warning'}`}>{item.offsetMs >= 0 ? '+' : ''}{item.offsetMs}ms · 목표시 잔여 {Number.isFinite(item.ageAtTargetMs) ? formatDuration(90_000 - item.ageAtTargetMs) : '—'}</span>
|
<label className="ml-auto flex items-center gap-1.5 text-ink-muted">
|
||||||
|
<span>오프셋</span>
|
||||||
|
<input type="number" min="-5000" max="10000" step="10" value={item.offsetMs} disabled={salvoArmed} onChange={(event) => { const value = Math.max(-5_000, Math.min(10_000, Number(event.target.value))); setOffsets((current) => current.map((offset, position) => position === index ? value : offset)) }} aria-label={`${index + 1}번 시도 오프셋 (ms)`} className="w-20 rounded-md border border-line bg-canvas px-2 py-1 text-right font-mono text-ink outline-none focus:border-accent disabled:opacity-50" />
|
||||||
|
<span>ms</span>
|
||||||
|
</label>
|
||||||
|
<span className={`w-24 text-right font-semibold tabular-nums ${item.ready ? 'text-success' : 'text-warning'}`}>{item.ready ? `잔여 ${formatDuration(90_000 - item.ageAtTargetMs)}` : '토큰 만료 임박'}</span>
|
||||||
{!salvoArmed && <button onClick={() => removeToken(item.token.solvedAtMs)} className="text-ink-muted hover:text-danger" aria-label="토큰 삭제">✕</button>}
|
{!salvoArmed && <button onClick={() => removeToken(item.token.solvedAtMs)} className="text-ink-muted hover:text-danger" aria-label="토큰 삭제">✕</button>}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
@@ -479,11 +496,11 @@ export default function AutomationPanel({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-3 grid gap-3 sm:grid-cols-[1fr_auto]">
|
<div className="mt-3 flex flex-wrap items-center justify-between gap-3">
|
||||||
<label className="space-y-2"><span className="text-[10px] font-semibold text-ink-muted">시도 간격 (ms, 목표 시각 중심 대칭)</span><input type="number" min="0" max="3000" step="10" value={salvoStepMs} onChange={(event) => setSalvoStepMs(Math.max(0, Math.min(3_000, Number(event.target.value))))} disabled={salvoArmed} className="w-full rounded-xl border border-line bg-surface px-3 py-3 font-mono text-xs text-ink outline-none focus:border-accent disabled:opacity-50" /></label>
|
<label className="flex items-center gap-2 text-[10px] font-semibold text-ink-muted"><input type="checkbox" checked={stopOnSuccess} onChange={(event) => setStopOnSuccess(event.target.checked)} disabled={salvoArmed} className="accent-coral" />첫 성공 시 이후 취소</label>
|
||||||
<label className="flex items-end gap-2 pb-3 text-[10px] font-semibold text-ink-muted"><input type="checkbox" checked={stopOnSuccess} onChange={(event) => setStopOnSuccess(event.target.checked)} disabled={salvoArmed} className="accent-coral" />첫 성공 시 이후 취소</label>
|
{attemptCount > 0 && !salvoArmed && <button onClick={() => setOffsets(defaultSalvoOffsets(attemptCount))} className="rounded-lg border border-line px-2.5 py-1.5 text-[10px] font-semibold text-ink-muted hover:text-ink">오프셋 기본값</button>}
|
||||||
</div>
|
</div>
|
||||||
{attemptCount > 0 && <p className="mt-2 text-[10px] leading-4 text-ink-muted">시도 <span className="font-semibold text-ink">{attemptCount}</span>개 · 오프셋 <span className="font-mono text-ink">{salvoOffsets.map((offset) => `${offset >= 0 ? '+' : ''}${offset}`).join(' / ')}</span> ms</p>}
|
{attemptCount > 0 && <p className="mt-2 text-[10px] leading-4 text-ink-muted">시도 <span className="font-semibold text-ink">{attemptCount}</span>개 · 오프셋 <span className="font-mono text-ink">{salvoTokenState.map((item) => `${item.offsetMs >= 0 ? '+' : ''}${item.offsetMs}`).join(' / ')}</span> ms · 목표 시각 대비 각 시도가 이 오프셋에서 발사됩니다.</p>}
|
||||||
|
|
||||||
{salvoState.attempts.length > 0 && (
|
{salvoState.attempts.length > 0 && (
|
||||||
<div className="mt-3 overflow-hidden rounded-xl border border-line-soft">
|
<div className="mt-3 overflow-hidden rounded-xl border border-line-soft">
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
import { defaultSalvoOffsets } from '../src/components/AutomationPanel'
|
||||||
|
|
||||||
|
describe('defaultSalvoOffsets', () => {
|
||||||
|
it('matches the requested per-token defaults', () => {
|
||||||
|
expect(defaultSalvoOffsets(1)).toEqual([0])
|
||||||
|
expect(defaultSalvoOffsets(2)).toEqual([-50, 0])
|
||||||
|
expect(defaultSalvoOffsets(3)).toEqual([-50, 0, 50])
|
||||||
|
expect(defaultSalvoOffsets(4)).toEqual([-50, 0, 50, 100])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps a stable prefix as tokens grow and handles the empty case', () => {
|
||||||
|
expect(defaultSalvoOffsets(0)).toEqual([])
|
||||||
|
expect(defaultSalvoOffsets(5)).toEqual([-50, 0, 50, 100, 150])
|
||||||
|
// 앞쪽 오프셋은 토큰 수가 늘어도 유지된다(사용자 편집 보존에 필요).
|
||||||
|
expect(defaultSalvoOffsets(5).slice(0, 4)).toEqual(defaultSalvoOffsets(4))
|
||||||
|
})
|
||||||
|
})
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 91 KiB |
Reference in new issue
Block a user