Skip to content

Commit

Permalink
fix(code style): csharp naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Aug 13, 2023
1 parent bdd86e3 commit d997867
Show file tree
Hide file tree
Showing 36 changed files with 983 additions and 999 deletions.
180 changes: 90 additions & 90 deletions src/GZCTF/Controllers/AccountController.cs

Large diffs are not rendered by default.

168 changes: 84 additions & 84 deletions src/GZCTF/Controllers/AdminController.cs

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions src/GZCTF/Controllers/AssetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@ namespace GZCTF.Controllers;
[ProducesResponseType(typeof(RequestResponse), StatusCodes.Status403Forbidden)]
public class AssetsController : ControllerBase
{
private readonly ILogger<AssetsController> logger;
private readonly IFileRepository fileRepository;
private readonly IConfiguration configuration;
private readonly string basepath;
private readonly FileExtensionContentTypeProvider extProvider = new();
private readonly ILogger<AssetsController> _logger;
private readonly IFileRepository _fileRepository;
private readonly FileExtensionContentTypeProvider _extProvider = new();

public AssetsController(IFileRepository _fileeService,
IConfiguration _configuration,
ILogger<AssetsController> _logger)
private readonly string _basepath;

public AssetsController(IFileRepository fileeService,
IConfiguration configuration,
ILogger<AssetsController> logger)
{
fileRepository = _fileeService;
configuration = _configuration;
logger = _logger;
basepath = configuration.GetSection("UploadFolder").Value ?? "uploads";
_fileRepository = fileeService;
_logger = logger;
_basepath = configuration.GetSection("UploadFolder").Value ?? "uploads";
}

/// <summary>
Expand All @@ -49,15 +48,15 @@ public AssetsController(IFileRepository _fileeService,
public IActionResult GetFile([RegularExpression("[0-9a-f]{64}")] string hash, string filename)
{
var path = $"{hash[..2]}/{hash[2..4]}/{hash}";
path = Path.GetFullPath(Path.Combine(basepath, path));
path = Path.GetFullPath(Path.Combine(_basepath, path));

if (!System.IO.File.Exists(path))
{
logger.Log($"尝试获取不存在的文件 [{hash[..8]}] {filename}", HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "0.0.0.0", TaskStatus.NotFound, LogLevel.Warning);
_logger.Log($"尝试获取不存在的文件 [{hash[..8]}] {filename}", HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "0.0.0.0", TaskStatus.NotFound, LogLevel.Warning);
return NotFound(new RequestResponse("文件不存在", 404));
}

if (!extProvider.TryGetContentType(filename, out string? contentType))
if (!_extProvider.TryGetContentType(filename, out string? contentType))
contentType = MediaTypeNames.Application.Octet;

return new PhysicalFileResult(path, contentType)
Expand Down Expand Up @@ -92,16 +91,16 @@ public async Task<IActionResult> Upload(List<IFormFile> files, [FromQuery] strin
{
if (file.Length > 0)
{
var res = await fileRepository.CreateOrUpdateFile(file, filename, token);
logger.SystemLog($"更新文件 [{res.Hash[..8]}] {filename ?? file.FileName} @ {file.Length} bytes", TaskStatus.Success, LogLevel.Debug);
var res = await _fileRepository.CreateOrUpdateFile(file, filename, token);
_logger.SystemLog($"更新文件 [{res.Hash[..8]}] {filename ?? file.FileName} @ {file.Length} bytes", TaskStatus.Success, LogLevel.Debug);
results.Add(res);
}
}
return Ok(results);
}
catch (Exception ex)
{
logger.LogError(ex, ex.Message);
_logger.LogError(ex, ex.Message);
return BadRequest(new RequestResponse("遇到IO错误"));
}
}
Expand All @@ -125,9 +124,9 @@ public async Task<IActionResult> Upload(List<IFormFile> files, [FromQuery] strin
[ProducesResponseType(typeof(RequestResponse), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Delete(string hash, CancellationToken token)
{
var result = await fileRepository.DeleteFileByHash(hash, token);
var result = await _fileRepository.DeleteFileByHash(hash, token);

logger.SystemLog($"删除文件 [{hash[..8]}]...", result, LogLevel.Information);
_logger.SystemLog($"删除文件 [{hash[..8]}]...", result, LogLevel.Information);

return result switch
{
Expand Down
Loading

0 comments on commit d997867

Please sign in to comment.