68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using ReviewProxy.Lib;
|
|
|
|
namespace ReviewProxy.Controllers;
|
|
|
|
public class HomeController : Controller
|
|
{
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var inputStream = this.HttpContext.Request.Body;
|
|
if (inputStream is null)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
Console.WriteLine($"Receive Request: {this.HttpContext.Connection.RemoteIpAddress} {this.HttpContext.Request.ContentLength}");
|
|
|
|
try
|
|
{
|
|
string workDir = Path.Combine(Directory.GetCurrentDirectory(), "encoding");
|
|
string zipFilePath = Path.Combine(Directory.GetCurrentDirectory(), "encoded.zip");
|
|
|
|
var encoder = new FileEncoder(inputStream, workDir, zipFilePath);
|
|
|
|
this.HttpContext.Response.RegisterForDispose(encoder);
|
|
|
|
await encoder.EncodeAsync().ConfigureAwait(false);
|
|
|
|
var result = new PhysicalFileResult(zipFilePath, "application/octet-stream");
|
|
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex);
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
public async Task<IActionResult> Stream()
|
|
{
|
|
var inputStream = this.HttpContext.Request.Body;
|
|
if (inputStream is null)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
try
|
|
{
|
|
string workDir = Path.Combine(Directory.GetCurrentDirectory(), "encoding");
|
|
string zipFilePath = Path.Combine(Directory.GetCurrentDirectory(), "encoded.zip");
|
|
|
|
var encoder = new StreamEncoder(inputStream, workDir, zipFilePath);
|
|
await encoder.EncodeAsync().ConfigureAwait(false);
|
|
|
|
var result = new PhysicalFileResult(zipFilePath, "application/octet-stream");
|
|
|
|
this.HttpContext.Response.RegisterForDispose(encoder);
|
|
|
|
return result;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex);
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
}
|