dongsik22 commited on
Commit
18751a7
·
1 Parent(s): e9dfe14

fix: 재생 중 NAS push 폭주 차단 (timeupdate throttle + 서버 최소 간격)

Browse files

추가 분석 (1차 패치 후 발견):
- index.html timeupdate가 5초마다 fav.progress.time을 저장 → saveFavs()
- progress.time 값이 매번 다르니 서버 콘텐츠 해시 디듀프는 못 막음
- 재생 중 5~6초마다 ssh push가 강제로 발생해 autossh tunnel을 polluting

수정:
- index.html: timeupdate progress 저장 throttle 5초 → 30초 상향
(이어보기 정확도 vs NAS 부하 균형)
- server.js: schedulePushToNas에 MIN_PUSH_INTERVAL_MS=15s 강제
(마지막 push 후 15초 이내 호출은 남은 시간만큼 지연)

부가 변경:
- index.html: 풀스크린 zoom 복원 + 재연결 시 zoom 상태 보존
- OPER.md: 파일 위치 표에 OPER/STACK/FLOW 추가

Files changed (3) hide show
  1. OPER.md +3 -0
  2. index.html +29 -4
  3. server.js +10 -1
OPER.md CHANGED
@@ -241,4 +241,7 @@ curl.exe -sS -u $auth "$base/api/ranking?period=daily" | Select-String -Pattern
241
  | 캐시 | `D:\ai\tvchak\.cache\` |
242
  | 변경 이력 | `D:\ai\tvchak\WORKLOG.md` |
243
  | 기능 사양 | `D:\ai\tvchak\SPEC.md` |
 
 
 
244
  | 호스팅 후보 분석 | `D:\ai\tvchak\HOSTING.md` |
 
241
  | 캐시 | `D:\ai\tvchak\.cache\` |
242
  | 변경 이력 | `D:\ai\tvchak\WORKLOG.md` |
243
  | 기능 사양 | `D:\ai\tvchak\SPEC.md` |
244
+ | 운영 매뉴얼 (이 문서) | `D:\ai\tvchak\OPER.md` |
245
+ | 기술 스택 & 버전 | `D:\ai\tvchak\STACK.md` |
246
+ | 동작 흐름도 (시퀀스) | `D:\ai\tvchak\FLOW.md` |
247
  | 호스팅 후보 분석 | `D:\ai\tvchak\HOSTING.md` |
index.html CHANGED
@@ -2564,9 +2564,16 @@ function closeAddModal() { $('#addModal').classList.remove('show'); }
2564
  return Math.sqrt(dx * dx + dy * dy);
2565
  }
2566
 
2567
- // src 바뀌면 리셋
2568
- const obs = new MutationObserver(() => { zoom = 1; tx = 0; ty = 0; apply(); });
 
 
 
2569
  obs.observe(v, { attributes: true, attributeFilter: ['src'] });
 
 
 
 
2570
 
2571
  // 단축키 핸들러에서 사용 가능하도록 전역 노출
2572
  window._videoZoom = {
@@ -2658,9 +2665,10 @@ $('#player').addEventListener('timeupdate', () => {
2658
  }
2659
  }
2660
  if (!currentFavId || currentEpIdx < 0) return;
2661
- // 너무 잦은 쓰기 방지: 5초마다
 
2662
  const now = Date.now();
2663
- if ((playEpisode._lastSave || 0) + 5000 > now) return;
2664
  playEpisode._lastSave = now;
2665
  const fav = favs.find(f => f.id === currentFavId);
2666
  if (!fav) return;
@@ -3657,12 +3665,29 @@ function setupVideoErrorRetry() {
3657
  if (!currentFavId || currentEpIdx < 0) return;
3658
  const ep = currentEpList[currentEpIdx];
3659
  const resumeTime = v.currentTime;
 
 
 
3660
  showMediaToast('스트림 재연결 중…', 2500);
3661
  playEpisode(currentFavId, ep.sid, ep.nid, { userInitiated: false }).then(() => {
3662
  // 끊긴 위치에서 재개
3663
  const onCanPlay = () => {
3664
  try { v.currentTime = resumeTime; v.play().catch(() => {}); } catch {}
3665
  v.removeEventListener('canplay', onCanPlay);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3666
  };
3667
  v.addEventListener('canplay', onCanPlay);
3668
  }).catch(() => {});
 
2564
  return Math.sqrt(dx * dx + dy * dy);
2565
  }
2566
 
2567
+ // src 바뀌면 리셋 — 단, 풀스크린 유지 중이면 저장된 zoom을 다시 복원 (HLS 리로드/에러 복구/자동 다음화 등)
2568
+ const obs = new MutationObserver(() => {
2569
+ zoom = 1; tx = 0; ty = 0; apply();
2570
+ if (isFullscreen()) restoreSavedZoom();
2571
+ });
2572
  obs.observe(v, { attributes: true, attributeFilter: ['src'] });
2573
+ // HLS는 src 속성이 안 바뀌고 MediaSource로 attach되므로, loadedmetadata에서도 한 번 더 복원 시도
2574
+ v.addEventListener('loadedmetadata', () => {
2575
+ if (isFullscreen() && zoom === 1) restoreSavedZoom();
2576
+ });
2577
 
2578
  // 단축키 핸들러에서 사용 가능하도록 전역 노출
2579
  window._videoZoom = {
 
2665
  }
2666
  }
2667
  if (!currentFavId || currentEpIdx < 0) return;
2668
+ // 너무 잦은 쓰기 방지: 30초마다 (이어보기 정확도 vs NAS 푸시 부하 균형).
2669
+ // 5초 throttle은 재생 중 NAS push가 5~6초마다 발생해 autossh tunnel을 polluting → SOCKS5 stall.
2670
  const now = Date.now();
2671
+ if ((playEpisode._lastSave || 0) + 30000 > now) return;
2672
  playEpisode._lastSave = now;
2673
  const fav = favs.find(f => f.id === currentFavId);
2674
  if (!fav) return;
 
3665
  if (!currentFavId || currentEpIdx < 0) return;
3666
  const ep = currentEpList[currentEpIdx];
3667
  const resumeTime = v.currentTime;
3668
+ // 재로드 직전 zoom 상태 보존 — 모바일 일부 브라우저는 src 교체 시 fullscreen auto-exit하며 zoom이 리셋됨
3669
+ const savedZoom = window._videoZoom?.getZoom?.() ?? 1;
3670
+ const wasFullscreen = window._videoZoom?.isFullscreen?.() ?? false;
3671
  showMediaToast('스트림 재연결 중…', 2500);
3672
  playEpisode(currentFavId, ep.sid, ep.nid, { userInitiated: false }).then(() => {
3673
  // 끊긴 위치에서 재개
3674
  const onCanPlay = () => {
3675
  try { v.currentTime = resumeTime; v.play().catch(() => {}); } catch {}
3676
  v.removeEventListener('canplay', onCanPlay);
3677
+ // zoom 복원 — fullscreen이 자동 종료됐다면 다시 진입한 뒤에 적용
3678
+ if (savedZoom > 1) {
3679
+ const restoreZoom = () => {
3680
+ try { window._videoZoom?.setZoom?.(savedZoom); } catch {}
3681
+ };
3682
+ if (wasFullscreen && !window._videoZoom?.isFullscreen?.()) {
3683
+ // 자동 풀스크린 재진입 시도. 실패해도 다음 사용자 진입 시 restoreSavedZoom이 fav 저장값으로 복원.
3684
+ const wrap = document.getElementById('videoWrap');
3685
+ (wrap?.requestFullscreen?.call(wrap) || wrap?.webkitRequestFullscreen?.call(wrap) || Promise.resolve())
3686
+ .then(restoreZoom).catch(restoreZoom);
3687
+ } else if (window._videoZoom?.isFullscreen?.()) {
3688
+ restoreZoom();
3689
+ }
3690
+ }
3691
  };
3692
  v.addEventListener('canplay', onCanPlay);
3693
  }).catch(() => {});
server.js CHANGED
@@ -176,14 +176,22 @@ async function pingNas() {
176
  markNasStatus(ok);
177
  }
178
 
 
 
 
 
179
  const _pushTimers = new Map();
 
 
180
  function schedulePushToNas(profile) {
181
  const key = `p${profile}`;
182
  if (_pushTimers.has(key)) clearTimeout(_pushTimers.get(key));
 
 
183
  _pushTimers.set(key, setTimeout(() => {
184
  _pushTimers.delete(key);
185
  doPushToNas(profile);
186
- }, 2000));
187
  }
188
 
189
  // 직전에 성공적으로 푸시한 파일의 해시. 동일 내용 반복 푸시 차단용.
@@ -219,6 +227,7 @@ function doPushToNas(profile) {
219
  if (_lastPushedHash.get(profile) === hash) {
220
  return;
221
  }
 
222
  const args = [...sshCommonArgs(keyPath), `cat > ${remote}`];
223
  console.log(`[nas-favs] pushing p${profile} via ssh -p ${process.env.NAS_SSH_PORT || '22'}...`);
224
  const proc = spawn('ssh', args, { stdio: ['pipe', 'pipe', 'pipe'] });
 
176
  markNasStatus(ok);
177
  }
178
 
179
+ // schedulePushToNas: 두 가지 보호장치
180
+ // (1) 디바운스 2초 — 연속된 saveFavs 묶기
181
+ // (2) 최소 간격 15초 — 재생 중 timeupdate(5초마다)처럼 띄엄띄엄 들어오는 호출 throttle.
182
+ // 마지막 푸시 성공 후 15초 이내 호출이면 남은 시간만큼 지연.
183
  const _pushTimers = new Map();
184
+ const _lastPushAt = new Map(); // profile → 마지막 doPushToNas 진입 시각
185
+ const MIN_PUSH_INTERVAL_MS = 15 * 1000;
186
  function schedulePushToNas(profile) {
187
  const key = `p${profile}`;
188
  if (_pushTimers.has(key)) clearTimeout(_pushTimers.get(key));
189
+ const sinceLast = Date.now() - (_lastPushAt.get(profile) || 0);
190
+ const minDelay = Math.max(2000, MIN_PUSH_INTERVAL_MS - sinceLast);
191
  _pushTimers.set(key, setTimeout(() => {
192
  _pushTimers.delete(key);
193
  doPushToNas(profile);
194
+ }, minDelay));
195
  }
196
 
197
  // 직전에 성공적으로 푸시한 파일의 해시. 동일 내용 반복 푸시 차단용.
 
227
  if (_lastPushedHash.get(profile) === hash) {
228
  return;
229
  }
230
+ _lastPushAt.set(profile, Date.now());
231
  const args = [...sshCommonArgs(keyPath), `cat > ${remote}`];
232
  console.log(`[nas-favs] pushing p${profile} via ssh -p ${process.env.NAS_SSH_PORT || '22'}...`);
233
  const proc = spawn('ssh', args, { stdio: ['pipe', 'pipe', 'pipe'] });