.
This commit is contained in:
1 parent
d2c03d155d
commit
db60190e19
13 files changed
+505
-38
No files matched your search
@@ -122,6 +122,7 @@ export default function AutomationPanel({
|
||||
const [clockSettings, setClockSettings] = useState<ClockCalibrationSettings>(loadClockSettings)
|
||||
const previousFingerprint = useRef('')
|
||||
const previousAutoStatus = useRef(autoState.status)
|
||||
const previousCaptchaAt = useRef<number | null>(null)
|
||||
const targetServerTimeMs = parseKstInput(targetInput)
|
||||
const liveServerTimeMs = clock
|
||||
? clock.estimatedServerTimeMs + (nowMs - clock.observedAtMs)
|
||||
@@ -132,6 +133,7 @@ export default function AutomationPanel({
|
||||
? targetServerTimeMs - (captchaPastedAtMs + (clock?.offsetMs ?? 0))
|
||||
: Number.POSITIVE_INFINITY
|
||||
const tokenReady = captchaToken.trim().length >= 30 && tokenAgeAtTargetMs >= 0 && tokenAgeAtTargetMs <= 90_000
|
||||
const armed = autoState.status === 'armed' || autoState.status === 'firing'
|
||||
|
||||
const requestFingerprint = useMemo(() => request ? JSON.stringify({
|
||||
...request,
|
||||
@@ -163,6 +165,17 @@ export default function AutomationPanel({
|
||||
previousFingerprint.current = requestFingerprint
|
||||
}, [requestFingerprint, autoState.status])
|
||||
|
||||
useEffect(() => {
|
||||
if (!captchaPastedAtMs || captchaPastedAtMs === previousCaptchaAt.current || armed) return
|
||||
previousCaptchaAt.current = captchaPastedAtMs
|
||||
const estimatedServerNow = clock
|
||||
? clock.estimatedServerTimeMs + (Date.now() - clock.observedAtMs)
|
||||
: Date.now()
|
||||
if (!Number.isFinite(targetServerTimeMs) || targetServerTimeMs <= estimatedServerNow + 150) {
|
||||
setTargetInput(toKstInput(estimatedServerNow + 30_000))
|
||||
}
|
||||
}, [armed, captchaPastedAtMs, clock, targetServerTimeMs])
|
||||
|
||||
useEffect(() => {
|
||||
if (previousAutoStatus.current !== autoState.status) {
|
||||
if (autoState.status === 'firing') onTokenConsumed()
|
||||
@@ -252,7 +265,6 @@ export default function AutomationPanel({
|
||||
}
|
||||
|
||||
const qualityTone = clock?.quality === 'good' ? 'good' : clock?.quality === 'poor' || clock?.quality === 'unavailable' ? 'warn' : 'normal'
|
||||
const armed = autoState.status === 'armed' || autoState.status === 'firing'
|
||||
|
||||
return (
|
||||
<section className="panel-card overflow-hidden" aria-label="자동 예약 및 서버시간">
|
||||
@@ -279,6 +291,7 @@ export default function AutomationPanel({
|
||||
<Metric label="sample age" value={clock?.acceptedSamples ? formatDuration(clock.sampleAgeMs + (nowMs - clock.observedAtMs)) : '—'} />
|
||||
<Metric label="drift" value={`${(clock?.driftPpm ?? 0).toFixed(2)}ppm`} />
|
||||
<Metric label="remote" value={clock?.remoteIp || '—'} />
|
||||
<Metric label="transport" value={`${clock?.protocol ?? (clockSettings.transportMode === 'http2' ? 'h2' : 'http/1.1')} · ${clock?.connectionId ?? 'not connected'}`} tone={clock?.protocol === 'h2' ? 'good' : 'normal'} />
|
||||
<Metric label="boundaries" value={`${clock?.boundaryCount ?? 0} / ${clock?.calibrationSettings.requiredBoundaryCount ?? CLOCK_CALIBRATION_DEFAULTS.requiredBoundaryCount}`} tone={clock?.calibrationReady ? 'good' : 'warn'} />
|
||||
<Metric label="phase spread" value={clock?.boundarySpreadMs === undefined ? '—' : `${clock.boundarySpreadMs.toFixed(1)}ms`} tone={clock?.calibrationReady ? 'good' : 'warn'} />
|
||||
<Metric label="recommended" value={`${(clock?.recommendedCorrectionMs ?? 0) >= 0 ? '+' : ''}${(clock?.recommendedCorrectionMs ?? 0).toFixed(1)}ms`} />
|
||||
@@ -294,6 +307,7 @@ export default function AutomationPanel({
|
||||
{clock?.warning && <p className="mt-2 text-[10px] leading-4 text-warning">{clock.warning} 품질이 낮아도 마지막 유효 추정값으로 1회 실행합니다.</p>}
|
||||
<div className="mt-3 flex justify-end"><button onClick={() => setSettingsOpen((value) => !value)} disabled={armed} className="rounded-full border border-line px-3 py-2 text-[10px] font-semibold text-ink-muted hover:text-ink disabled:opacity-40">정밀 보정 설정</button></div>
|
||||
{settingsOpen && <div className="mt-3 rounded-xl border border-line-soft bg-canvas p-4">
|
||||
<label className="mb-4 block space-y-1"><span className="text-[9px] font-semibold text-ink-muted">전송 모드</span><select value={clockSettings.transportMode} onChange={(event) => setClockSettings((current) => ({ ...current, transportMode: event.target.value as ClockCalibrationSettings['transportMode'] }))} className="w-full rounded-lg border border-line bg-surface px-3 py-2 font-mono text-xs text-ink outline-none focus:border-accent"><option value="http1">HTTP/1.1 keep-alive (기존)</option><option value="http2">HTTP/2 단일 세션</option></select><span className="block text-[9px] leading-4 text-ink-muted">모드 전환 시 RTT 특성이 달라 기존 시간 보정을 초기화하고 다시 수집합니다.</span></label>
|
||||
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{([
|
||||
['scanWindowMs', '경계 탐색 범위 (ms)', 100, 450],
|
||||
@@ -317,7 +331,7 @@ export default function AutomationPanel({
|
||||
<div><h3 className="text-sm font-semibold text-ink">시간 테스트</h3><p className="mt-1 text-[10px] text-ink-muted">3초 뒤 HEAD 요청으로 스케줄러와 도착 오차를 측정합니다.</p></div>
|
||||
<button onClick={runTimingTest} disabled={busy === 'test' || armed} className="rounded-full border border-line px-3 py-2 text-[11px] font-semibold text-ink-muted hover:border-ink hover:text-ink disabled:opacity-40">{busy === 'test' ? '테스트 중…' : '3초 테스트'}</button>
|
||||
</div>
|
||||
{timingTest && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="arrival error" value={`${timingTest.arrivalErrorMs >= 0 ? '+' : ''}${timingTest.arrivalErrorMs.toFixed(1)}ms`} tone={Math.abs(timingTest.arrivalErrorMs) <= timingTest.uncertaintyMs ? 'good' : 'warn'} /><Metric label="timer jitter" value={`${timingTest.schedulerJitterMs >= 0 ? '+' : ''}${timingTest.schedulerJitterMs.toFixed(1)}ms`} /><Metric label="RTT" value={`${timingTest.rttMs.toFixed(1)}ms`} /><Metric label="socket" value={timingTest.reusedSocket ? 'reused' : 'new'} /></div>}
|
||||
{timingTest && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="arrival error" value={`${timingTest.arrivalErrorMs >= 0 ? '+' : ''}${timingTest.arrivalErrorMs.toFixed(1)}ms`} tone={Math.abs(timingTest.arrivalErrorMs) <= timingTest.uncertaintyMs ? 'good' : 'warn'} /><Metric label="timer jitter" value={`${timingTest.schedulerJitterMs >= 0 ? '+' : ''}${timingTest.schedulerJitterMs.toFixed(1)}ms`} /><Metric label="RTT" value={`${timingTest.rttMs.toFixed(1)}ms`} /><Metric label="connection" value={`${timingTest.protocol ?? '—'} ${timingTest.connectionId ?? ''} · ${timingTest.reusedSocket ? 'reused' : 'new'}`} /></div>}
|
||||
</div>
|
||||
|
||||
<div className="p-5 sm:p-6">
|
||||
@@ -328,9 +342,10 @@ export default function AutomationPanel({
|
||||
</div>
|
||||
<div className="mt-3 grid grid-cols-2 gap-2"><Metric label="countdown" value={formatDuration(countdownMs)} tone={countdownMs > 0 ? 'good' : 'warn'} /><Metric label="token at target" value={Number.isFinite(tokenAgeAtTargetMs) ? formatDuration(tokenAgeAtTargetMs) : '토큰 없음'} tone={tokenReady ? 'good' : 'warn'} /></div>
|
||||
<div className="mt-3 rounded-xl border border-line-soft bg-canvas p-3 text-[10px] leading-5 text-ink-muted"><div className="flex justify-between gap-3"><span>토큰</span><span className={tokenReady ? 'font-semibold text-success' : 'font-semibold text-warning'}>{captchaToken ? `${captchaToken.slice(0, 6)}••••${captchaToken.slice(-4)} · ${formatDuration(tokenAgeMs)}` : '입력되지 않음'}</span></div>{autoState.snapshot && <><div className="flex justify-between gap-3"><span>고정 스냅샷</span><span className="text-right text-ink">{autoState.snapshot.themeName} · {autoState.snapshot.date} {autoState.snapshot.timeLabel} · {autoState.snapshot.person}명</span></div><div className="flex justify-between gap-3"><span>예정 발송</span><span className="font-mono text-ink">{autoState.timeline?.plannedSendAtMs ? formatClock(autoState.timeline.plannedSendAtMs) : '계산 중'}</span></div></>}</div>
|
||||
{autoState.timeline?.actualSendAtMs && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="actual send" value={formatClock(autoState.timeline.actualSendAtMs).split(' ').at(-1) ?? '—'} /><Metric label="arrival error" value={autoState.timeline.arrivalErrorMs === undefined ? '—' : `${autoState.timeline.arrivalErrorMs >= 0 ? '+' : ''}${autoState.timeline.arrivalErrorMs.toFixed(1)}ms`} /><Metric label="response RTT" value={autoState.timeline.rttMs === undefined ? '—' : `${autoState.timeline.rttMs.toFixed(1)}ms`} /><Metric label="HTTP / socket" value={`${autoState.timeline.httpStatus ?? '—'} / ${autoState.timeline.reusedSocket ? 'reused' : 'new'}`} /></div>}
|
||||
{autoState.timeline?.actualSendAtMs && <div className="mt-3 grid grid-cols-2 gap-2 sm:grid-cols-4"><Metric label="actual send" value={formatClock(autoState.timeline.actualSendAtMs).split(' ').at(-1) ?? '—'} /><Metric label="arrival error" value={autoState.timeline.arrivalErrorMs === undefined ? '—' : `${autoState.timeline.arrivalErrorMs >= 0 ? '+' : ''}${autoState.timeline.arrivalErrorMs.toFixed(1)}ms`} /><Metric label="response RTT" value={autoState.timeline.rttMs === undefined ? '—' : `${autoState.timeline.rttMs.toFixed(1)}ms`} /><Metric label="HTTP / connection" value={`${autoState.timeline.httpStatus ?? '—'} · ${autoState.timeline.protocol ?? '—'} ${autoState.timeline.connectionId ?? ''} · ${autoState.timeline.reusedSocket ? 'reused' : 'new'}`} /></div>}
|
||||
{(error || autoState.message) && <p role="alert" className={`mt-3 rounded-xl border px-3 py-2 text-[10px] leading-4 ${error || autoState.status === 'failed' ? 'border-danger/25 bg-danger/8 text-danger' : 'border-success/25 bg-success/8 text-success'}`}>{error || autoState.message}</p>}
|
||||
<div className="mt-4 grid grid-cols-2 gap-2">{armed ? <button onClick={disarm} disabled={autoState.status === 'firing'} className="col-span-2 rounded-xl border border-danger/30 py-3 text-xs font-semibold text-danger hover:bg-danger/8 disabled:opacity-40">자동 예약 해제</button> : <button onClick={arm} disabled={busy === 'arm' || !request || !tokenReady} className="col-span-2 rounded-xl bg-coral py-3 text-xs font-bold text-coral-ink hover:bg-coral-strong disabled:cursor-not-allowed disabled:bg-chrome disabled:text-ink-muted">{busy === 'arm' ? '시작 중…' : '자동 예약 시작'}</button>}</div>
|
||||
{!armed && (!request || !tokenReady) && <p className="mt-3 text-[10px] leading-4 text-warning">{!request ? '예약자 정보·인원·동의와 CAPTCHA 인증을 완료해주세요.' : tokenAgeAtTargetMs < 0 ? '실행 시각이 이미 지났습니다. 미래 시각으로 변경해주세요.' : 'CAPTCHA 인증 후 90초 이내의 실행 시각을 입력해주세요.'}</p>}
|
||||
<div className="mt-4 grid grid-cols-2 gap-2">{armed ? <button onClick={disarm} disabled={autoState.status === 'firing'} className="col-span-2 rounded-xl border border-danger/30 py-3 text-xs font-semibold text-danger hover:bg-danger/8 disabled:opacity-40">자동 예약 해제</button> : <button onClick={arm} disabled={busy === 'arm'} className="col-span-2 rounded-xl bg-coral py-3 text-xs font-bold text-coral-ink hover:bg-coral-strong disabled:cursor-not-allowed disabled:bg-chrome disabled:text-ink-muted">{busy === 'arm' ? '시작 중…' : '자동 예약 시작'}</button>}</div>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user