forked from ddrilling/AsbCloudServer
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/well/{idWell}/drillingProgram")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class DrillingProgramController : ControllerBase
|
|
{
|
|
private readonly IDrillingProgramService drillingProgramService;
|
|
private readonly IFileService fileService;
|
|
|
|
public DrillingProgramController(IDrillingProgramService drillingProgramService, IFileService fileService)
|
|
{
|
|
this.drillingProgramService = drillingProgramService;
|
|
this.fileService = fileService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Создает программу бурения
|
|
/// </summary>
|
|
/// <param name="idWell"> id скважины </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns> Возвращает файл программы бурения </returns>
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
|
{
|
|
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
|
.ConfigureAwait(false);
|
|
if (fileInfo is null)
|
|
return NoContent();
|
|
|
|
var relativePath = fileService.GetUrl(fileInfo);
|
|
|
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Создает программу бурения
|
|
/// </summary>
|
|
/// <param name="idWell"> id скважины </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns> Возвращает ссылку на файл программы бурения в облаке </returns>
|
|
[HttpGet("webUrl")]
|
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetFileWebLinkAsync(int idWell, CancellationToken token = default)
|
|
{
|
|
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
|
|
.ConfigureAwait(false);
|
|
if (fileInfo is null)
|
|
return NoContent();
|
|
|
|
var fileWebUrl = fileInfo.PublishInfo?.WebStorageFileUrl;
|
|
|
|
if (!string.IsNullOrEmpty(fileWebUrl))
|
|
return Ok(fileWebUrl);
|
|
|
|
var relativePath = fileService.GetUrl(fileInfo);
|
|
var userLogin = User.Identity?.Name ?? "";
|
|
|
|
fileWebUrl = await fileService.GetFileWebUrlAsync(fileInfo,
|
|
userLogin, relativePath, token);
|
|
|
|
return Ok(fileWebUrl);
|
|
}
|
|
}
|
|
}
|