M2-U3+U4 완성: 이어보기 위치 동기화(POST/GET /api/position + PositionStore JSON 영속, 플레이어 5초 주기·종료 저장·재개 시크) + 폰 오프라인 저장(ApiClient.DownloadFileAsync .part 스트리밍, OfflineStore manifest, 라이브러리 💾 버튼, 저장 탭 오프라인 재생/삭제). 서버 RED→GREEN E2E + 에뮬레이터 E2E(위치 13.3→35.2초 이어재생, 서버 정지 후 오프라인 재생 프레임 실증). 104 tests GREEN
This commit is contained in:
parent
17f3e41cd2
commit
27c91c04dd
9 changed files with 356 additions and 8 deletions
44
VideoDownloader.Server/PositionStore.cs
Normal file
44
VideoDownloader.Server/PositionStore.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System.Text.Json;
|
||||
|
||||
namespace VideoDownloader.Server;
|
||||
|
||||
/// <summary>
|
||||
/// 이어보기 위치 저장(U3). 라이브러리 폴더의 positions.json 에 영속 —
|
||||
/// 서버 재시작·PC 재부팅 후에도 폰과 같은 위치에서 이어보기.
|
||||
/// </summary>
|
||||
public sealed class PositionStore
|
||||
{
|
||||
private const string FileName = "positions.json";
|
||||
private readonly object _gate = new();
|
||||
private readonly string _path;
|
||||
|
||||
private Dictionary<string, double> _positions;
|
||||
|
||||
public PositionStore(string libraryFolder)
|
||||
{
|
||||
_path = Path.Combine(libraryFolder, FileName);
|
||||
try
|
||||
{
|
||||
if (File.Exists(_path))
|
||||
_positions = JsonSerializer.Deserialize<Dictionary<string, double>>(File.ReadAllText(_path)) ?? new();
|
||||
}
|
||||
catch { /* 손상 파일 → 빈 상태로 시작 */ }
|
||||
_positions ??= new Dictionary<string, double>();
|
||||
}
|
||||
|
||||
public double Get(string id)
|
||||
{
|
||||
lock (_gate) return _positions.GetValueOrDefault(id, 0);
|
||||
}
|
||||
|
||||
public void Set(string id, double positionSec)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id) || positionSec < 0 || double.IsNaN(positionSec) || double.IsInfinity(positionSec))
|
||||
return;
|
||||
lock (_gate)
|
||||
{
|
||||
_positions[id] = positionSec;
|
||||
try { File.WriteAllText(_path, JsonSerializer.Serialize(_positions)); } catch { /* 디스크 오류는 무시 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue