playback 파일 다운로드 기능 추가
This commit is contained in:
@@ -76,6 +76,16 @@ namespace XRServer
|
||||
return; // '/playback/list' 요청은 별도로 처리하므로 여기서 종료합니다.
|
||||
}
|
||||
|
||||
if (url.StartsWith("/playback/", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// URL에서 "/playback/" 접두사를 제외한 나머지 부분을 파일 이름으로 추출합니다.
|
||||
string fileName = url.Substring("/playback/".Length);
|
||||
// 파일 이름에 포함될 수 있는 URL 인코딩(예: %20)을 디코딩합니다.
|
||||
string decodedFileName = System.Net.WebUtility.UrlDecode(fileName);
|
||||
handlePlaybackFile(context, decodedFileName);
|
||||
return; // '/playback/' 요청은 별도로 처리하므로 여기서 종료합니다.
|
||||
}
|
||||
|
||||
// 1. URL에서 'mm:ss' 형식의 시간 부분이 있는지 정규식으로 확인합니다.
|
||||
Match match = TimeFormatRegex.Match(url);
|
||||
// 만약 'mm:ss' 형식이 URL에 없다면, 기본값으로 현재 설정된 MM:SS 값을 사용합니다.
|
||||
@@ -191,6 +201,34 @@ namespace XRServer
|
||||
context.Response = new HttpResponse(HttpResponseCode.Ok, responsePayload.ToString(Formatting.None), headers, context.Request.Headers.KeepAliveConnection());
|
||||
}
|
||||
|
||||
private void handlePlaybackFile(IHttpContext context, string fileName)
|
||||
{
|
||||
// 요청된 파일이 존재하는지 확인합니다.
|
||||
string filePath = Path.Combine(PlaybackFolderPath, fileName);
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
// 파일이 없으면 404 오류를 반환합니다.
|
||||
context.Response = new HttpResponse(HttpResponseCode.NotFound, "요청한 파일을 찾을 수 없습니다.", false);
|
||||
return;
|
||||
}
|
||||
// 파일이 존재하면 해당 파일을 읽어 응답으로 보냅니다.
|
||||
byte[] fileBytes = File.ReadAllBytes(filePath);
|
||||
var headers = new List<KeyValuePair<string, string>>
|
||||
{
|
||||
new KeyValuePair<string, string>("Content-Disposition", $"attachment; filename=\"{fileName}\""),
|
||||
new KeyValuePair<string, string>("Content-Encoding", "7zip"), // 데이터가 gzip으로 압축되었음을 클라이언트에 알림
|
||||
new KeyValuePair<string, string>("Content-Length", fileBytes.Length.ToString()), // 압축된 데이터의 크기
|
||||
new KeyValuePair<string, string>("Access-Control-Allow-Origin", "*") // CORS 헤더 추가
|
||||
};
|
||||
|
||||
context.Response = new HttpResponse(
|
||||
HttpResponseCode.Ok,
|
||||
"application/octet-stream",
|
||||
new MemoryStream(fileBytes),
|
||||
context.Request.Headers.KeepAliveConnection(),
|
||||
headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// URL 경로에서 요청 타입을 추출합니다. (예: "baseinfo")
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user