Initial
This commit is contained in:
33
PdfMarker/Controllers/BallooningController.cs
Normal file
33
PdfMarker/Controllers/BallooningController.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PdfMarker.Models;
|
||||
using PdfMarker.Services;
|
||||
|
||||
namespace PdfMarker.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/ballooning")]
|
||||
public class BallooningController : ControllerBase
|
||||
{
|
||||
private readonly BallooningService _ballooningService;
|
||||
private readonly IWebHostEnvironment _env;
|
||||
|
||||
public BallooningController(BallooningService ballooningService, IWebHostEnvironment env)
|
||||
{
|
||||
_ballooningService = ballooningService;
|
||||
_env = env;
|
||||
}
|
||||
|
||||
[HttpPost("process")]
|
||||
public async Task<ActionResult<AutoBalloonResult>> Process([FromBody] AutoBalloonRequest request)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.FileName))
|
||||
return BadRequest("FileName is required");
|
||||
|
||||
var uploadsPath = Path.Combine(_env.WebRootPath, "uploads");
|
||||
var fName = $"{uploadsPath}/{request.FileName}";
|
||||
|
||||
var result = await _ballooningService.GenerateAsync(fName);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
32
PdfMarker/Controllers/UploadController.cs
Normal file
32
PdfMarker/Controllers/UploadController.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace PdfMarker.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/upload")]
|
||||
public class UploadController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _env;
|
||||
|
||||
public UploadController(IWebHostEnvironment env)
|
||||
{
|
||||
_env = env;
|
||||
}
|
||||
|
||||
[HttpPost("pdf")]
|
||||
public async Task<IActionResult> UploadPdf(IFormFile file)
|
||||
{
|
||||
if (file == null || file.Length == 0)
|
||||
return BadRequest("File mancante");
|
||||
|
||||
var uploadsPath = Path.Combine(_env.WebRootPath, "uploads");
|
||||
Directory.CreateDirectory(uploadsPath);
|
||||
|
||||
var filePath = Path.Combine(uploadsPath, file.FileName);
|
||||
|
||||
await using var stream = new FileStream(filePath, FileMode.Create);
|
||||
await file.CopyToAsync(stream);
|
||||
|
||||
return Ok(new { file = file.FileName });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user