M0: remote access server - Kestrel embedded (token auth/pair/queue API/library/range streaming/web companion zero-install), QR pairing window, DownloadQueueAdapter, auto-start+palette commands. Server E2E green (102 tests)
This commit is contained in:
parent
40c1b39b70
commit
bb569acd96
15 changed files with 734 additions and 0 deletions
45
VideoDownloader.Server/MediaLibrary.cs
Normal file
45
VideoDownloader.Server/MediaLibrary.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System.Security.Cryptography;
|
||||
|
||||
namespace VideoDownloader.Server;
|
||||
|
||||
/// <summary>저장 폴더 미디어 라이브러리: 파일 나열/조회(ID = SHA-256 경로 해시 12자).</summary>
|
||||
public static class MediaLibrary
|
||||
{
|
||||
private static readonly string[] VideoExts = { ".mp4", ".mkv", ".webm", ".ts", ".mov", ".m4v", ".avi", ".mp3", ".m4a" };
|
||||
|
||||
public static List<LibraryItemDto> List(string folder)
|
||||
{
|
||||
var result = new List<LibraryItemDto>();
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder)) return result;
|
||||
foreach (var f in Directory.EnumerateFiles(folder).OrderByDescending(f => File.GetLastWriteTimeUtc(f)))
|
||||
{
|
||||
var ext = Path.GetExtension(f).ToLowerInvariant();
|
||||
if (!VideoExts.Contains(ext)) continue;
|
||||
var fi = new FileInfo(f);
|
||||
result.Add(new LibraryItemDto(IdOf(f), fi.Name, fi.Length, fi.LastWriteTimeUtc));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return result;
|
||||
}
|
||||
|
||||
public static (string FullPath, string FileName)? Find(string folder, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder)) return null;
|
||||
foreach (var f in Directory.EnumerateFiles(folder))
|
||||
if (IdOf(f) == id) return (f, Path.GetFileName(f));
|
||||
}
|
||||
catch { }
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string IdOf(string path)
|
||||
{
|
||||
var hash = SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(Path.GetFullPath(path)));
|
||||
return Convert.ToHexString(hash)[..12].ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue