feat-visualization (#33)
尽管里面有点粪,但还是生成了漂亮的树,就当给树施肥了 剩下一个小问题:未考虑节点的宽度(因为名称不一样长),但目前未发现对图生成的明显影响 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#33 Co-authored-by: Ichirinko <1621543655@qq.com> Co-committed-by: Ichirinko <1621543655@qq.com>
This commit is contained in:
33
Canon.Server/Controllers/CompilerController.cs
Normal file
33
Canon.Server/Controllers/CompilerController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Canon.Server.Models;
|
||||
using Canon.Server.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Canon.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CompilerController(CompileDbContext dbContext, CompilerService compilerService) : ControllerBase
|
||||
{
|
||||
[HttpGet("{compileId}")]
|
||||
public async Task<ActionResult<CompileResponse>> GetResponse(string compileId)
|
||||
{
|
||||
CompileResult? result = await dbContext.CompileResults
|
||||
.Where(r => r.CompileId == compileId)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CompileResponse>> Compile(SourceCode sourceCode)
|
||||
{
|
||||
CompileResponse response = await compilerService.Compile(sourceCode);
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
24
Canon.Server/Controllers/FileController.cs
Normal file
24
Canon.Server/Controllers/FileController.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Canon.Server.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MongoDB.Driver.GridFS;
|
||||
|
||||
namespace Canon.Server.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FileController(GridFsService gridFsService) : ControllerBase
|
||||
{
|
||||
[HttpGet("{filename}")]
|
||||
public async Task<ActionResult> DownloadFile(string filename)
|
||||
{
|
||||
GridFSFileInfo? fileInfo = await gridFsService.FindAsync(filename);
|
||||
|
||||
if (fileInfo is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Stream fileStream = await gridFsService.OpenReadStream(fileInfo.Id);
|
||||
return File(fileStream, fileInfo.Metadata["content-type"].AsString);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user