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
73
VideoDownloader.Mobile/OfflineStore.cs
Normal file
73
VideoDownloader.Mobile/OfflineStore.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System.Text.Json;
|
||||
|
||||
namespace VideoDownloader.Mobile;
|
||||
|
||||
public sealed record OfflineItem(string Id, string FileName, long SizeBytes);
|
||||
|
||||
/// <summary>
|
||||
/// 폰 오프라인 저장(U4): 라이브러리 항목을 앱 전용 폴더에 저장·목록·삭제.
|
||||
/// manifest.json(id→파일명)으로 서버 항목과 매핑한다.
|
||||
/// </summary>
|
||||
public sealed class OfflineStore
|
||||
{
|
||||
public static OfflineStore Default { get; } = new();
|
||||
|
||||
private readonly string _dir;
|
||||
private readonly string _manifestPath;
|
||||
private readonly object _gate = new();
|
||||
private Dictionary<string, string> _manifest;
|
||||
|
||||
public OfflineStore()
|
||||
{
|
||||
_dir = Path.Combine(FileSystem.AppDataDirectory, "offline");
|
||||
_manifestPath = Path.Combine(_dir, "manifest.json");
|
||||
try
|
||||
{
|
||||
if (File.Exists(_manifestPath))
|
||||
_manifest = JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(_manifestPath)) ?? new();
|
||||
}
|
||||
catch { }
|
||||
_manifest ??= new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public string Directory => _dir;
|
||||
|
||||
public string PathFor(string id) => Path.Combine(_dir, id + Path.GetExtension(_manifest.GetValueOrDefault(id, ".mp4")));
|
||||
|
||||
public bool Exists(string id) { lock (_gate) { var p = PathFor(id); return File.Exists(p) && _manifest.ContainsKey(id); } }
|
||||
|
||||
/// <summary>다운로드 완료 후 등록.</summary>
|
||||
public void Record(string id, string fileName)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(_dir);
|
||||
_manifest[id] = fileName;
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(string id)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
try { if (File.Exists(PathFor(id))) File.Delete(PathFor(id)); } catch { }
|
||||
_manifest.Remove(id);
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
public List<OfflineItem> List()
|
||||
{
|
||||
lock (_gate)
|
||||
return _manifest.Select(kv =>
|
||||
{
|
||||
var p = PathFor(kv.Key);
|
||||
return new OfflineItem(kv.Key, kv.Value, File.Exists(p) ? new FileInfo(p).Length : 0);
|
||||
}).Where(i => i.SizeBytes > 0).ToList();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
try { System.IO.Directory.CreateDirectory(_dir); File.WriteAllText(_manifestPath, JsonSerializer.Serialize(_manifest)); } catch { }
|
||||
}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue