|
@@ -2,6 +2,7 @@ using System.Security.Claims;
|
|
|
using LiteDB;
|
|
using LiteDB;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
using RunnersMeet.Server.Domain;
|
|
using RunnersMeet.Server.Domain;
|
|
|
using RunnersMeet.Server.GpxFormat;
|
|
using RunnersMeet.Server.GpxFormat;
|
|
|
using RunnersMeet.Server.Persistence;
|
|
using RunnersMeet.Server.Persistence;
|
|
@@ -13,19 +14,17 @@ namespace RunnersMeet.Server.Controllers;
|
|
|
[Authorize("Tracks")]
|
|
[Authorize("Tracks")]
|
|
|
public class TracksController : ControllerBase
|
|
public class TracksController : ControllerBase
|
|
|
{
|
|
{
|
|
|
- private const int PageSize = 3;
|
|
|
|
|
-
|
|
|
|
|
private readonly IFileStorage _fileStorage;
|
|
private readonly IFileStorage _fileStorage;
|
|
|
private readonly GpxParser _gpxParser;
|
|
private readonly GpxParser _gpxParser;
|
|
|
private readonly QueryFactory _queryFactory;
|
|
private readonly QueryFactory _queryFactory;
|
|
|
- private readonly IConfiguration _config;
|
|
|
|
|
|
|
+ private readonly ApiSettings _settings;
|
|
|
|
|
|
|
|
- public TracksController(IFileStorage fileStorage, GpxParser gpxParser, QueryFactory queryFactory, IConfiguration config)
|
|
|
|
|
|
|
+ public TracksController(IFileStorage fileStorage, GpxParser gpxParser, QueryFactory queryFactory, IOptions<ApiSettings> apiOptions)
|
|
|
{
|
|
{
|
|
|
_fileStorage = fileStorage;
|
|
_fileStorage = fileStorage;
|
|
|
_gpxParser = gpxParser;
|
|
_gpxParser = gpxParser;
|
|
|
_queryFactory = queryFactory;
|
|
_queryFactory = queryFactory;
|
|
|
- _config = config;
|
|
|
|
|
|
|
+ _settings = apiOptions.Value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[HttpGet]
|
|
[HttpGet]
|
|
@@ -46,7 +45,7 @@ public class TracksController : ControllerBase
|
|
|
query.FilterByName(filter);
|
|
query.FilterByName(filter);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- query.Paging((page ?? 0) * PageSize, PageSize);
|
|
|
|
|
|
|
+ query.Paging((page ?? 0) * _settings.PageSize, _settings.PageSize);
|
|
|
|
|
|
|
|
return Ok(query.Get());
|
|
return Ok(query.Get());
|
|
|
}
|
|
}
|
|
@@ -54,10 +53,9 @@ public class TracksController : ControllerBase
|
|
|
[HttpPost]
|
|
[HttpPost]
|
|
|
public async Task<ActionResult<Track>> CreateTrack([FromForm] IFormFile file, CancellationToken cancellationToken = default)
|
|
public async Task<ActionResult<Track>> CreateTrack([FromForm] IFormFile file, CancellationToken cancellationToken = default)
|
|
|
{
|
|
{
|
|
|
- var limit = _config.GetValue<long>("GpxFileSizeLimit");
|
|
|
|
|
- if (file.Length > limit)
|
|
|
|
|
|
|
+ if (file.Length > _settings.GpxFileSizeLimit)
|
|
|
{
|
|
{
|
|
|
- throw new ApiException($"Uploaded tracks cannot be larger than {limit / (1024 * 1024)}MB");
|
|
|
|
|
|
|
+ throw new ApiException($"Uploaded tracks cannot be larger than {_settings.GpxFileSizeLimit / (1024 * 1024)}MB");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var fileName = await _fileStorage.UploadFileAsync(file, cancellationToken);
|
|
var fileName = await _fileStorage.UploadFileAsync(file, cancellationToken);
|