fix use fileshare only when needed.

This commit is contained in:
Фролов 2021-11-17 13:06:48 +05:00
parent 361aceed96
commit b6c2f60296
8 changed files with 18 additions and 18 deletions

View File

@ -9,7 +9,7 @@ namespace AsbCloudApp.Services
Task<int> CreateFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token); Task<int> CreateFileMarkAsync(FileMarkDto fileMarkDto, int idUser, CancellationToken token);
Task<FileInfoDto> GetOrCreateAsync(int idWell, int fileChangerId, Task<FileInfoDto> GetOrCreateAsync(int idWell, int fileChangerId,
CancellationToken token = default); CancellationToken token = default);
Task<string> GetOrCreateSharedUrlAsync(int idWell, int idUser, CancellationToken token = default); Task<string> GetOrCreateSharedUrlAsync(int idWell, int idUser, IFileShareService fileShareService, CancellationToken token = default);
Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token); Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token);
} }
} }

View File

@ -11,8 +11,8 @@ namespace AsbCloudApp.Services
{ {
string RootPath { get; } string RootPath { get; }
Task<string> GetSharedUrlAsync(int idFileInfo, int idUser, CancellationToken token); Task<string> GetSharedUrlAsync(int idFileInfo, int idUser, IFileShareService fileShareService, CancellationToken token);
Task<string> GetSharedUrlAsync(FileInfoDto dto, int idUser, Task<string> GetSharedUrlAsync(FileInfoDto dto, int idUser, IFileShareService fileShareService,
CancellationToken token = default); CancellationToken token = default);
Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default); Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default);

View File

@ -23,4 +23,6 @@ sudo -u postgres pg_dump -Fc -U postgres postgres -W > 2021-11-13_dump.sql.gz
#restore #restore
``` ```
psql postgres < dump_file_name psql postgres < dump_file_name
``` ```
sudo -u postgres psql -p 5499 -U postgres postgres -W < 2021-11-16_dump.sql.gz

View File

@ -26,7 +26,7 @@ namespace AsbCloudInfrastructure.Services
this.wellService = wellService; this.wellService = wellService;
} }
public async Task<string> GetOrCreateSharedUrlAsync(int idWell, int idUser, CancellationToken token = default) public async Task<string> GetOrCreateSharedUrlAsync(int idWell, int idUser, IFileShareService fileShareService, CancellationToken token = default)
{ {
var fileInfo = await GetOrCreateAsync(idWell, idUser, token) var fileInfo = await GetOrCreateAsync(idWell, idUser, token)
.ConfigureAwait(false); .ConfigureAwait(false);
@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services
if (fileInfo is null) if (fileInfo is null)
return null; return null;
var sharedUrl = await fileService.GetSharedUrlAsync(fileInfo, idUser, token) var sharedUrl = await fileService.GetSharedUrlAsync(fileInfo, idUser, fileShareService, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return sharedUrl; return sharedUrl;

View File

@ -18,13 +18,11 @@ namespace AsbCloudInfrastructure.Services
private readonly IQueryable<AsbCloudDb.Model.FileInfo> dbSetConfigured; private readonly IQueryable<AsbCloudDb.Model.FileInfo> dbSetConfigured;
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IFileShareService fileShareService;
public FileService(IAsbCloudDbContext db, IFileShareService fileShareService) public FileService(IAsbCloudDbContext db)
{ {
RootPath = "files"; RootPath = "files";
this.db = db; this.db = db;
this.fileShareService = fileShareService;
dbSetConfigured = db.Files dbSetConfigured = db.Files
.Include(f => f.Author) .Include(f => f.Author)
.ThenInclude(u => u.Company) .ThenInclude(u => u.Company)
@ -33,17 +31,17 @@ namespace AsbCloudInfrastructure.Services
.ThenInclude(m => m.User); .ThenInclude(m => m.User);
} }
public async Task<string> GetSharedUrlAsync(int idFileInfo, int idUser, public async Task<string> GetSharedUrlAsync(int idFileInfo, int idUser, IFileShareService fileShareService,
CancellationToken token) CancellationToken token)
{ {
var fileInfo = await GetInfoAsync(idFileInfo, token); var fileInfo = await GetInfoAsync(idFileInfo, token);
if (fileInfo is null) if (fileInfo is null)
return null; return null;
var sharedUrl = await GetSharedUrlAsync(fileInfo, idUser, token); var sharedUrl = await GetSharedUrlAsync(fileInfo, idUser, fileShareService, token);
return sharedUrl; return sharedUrl;
} }
public async Task<string> GetSharedUrlAsync( FileInfoDto fileInfo, int idUser, public async Task<string> GetSharedUrlAsync( FileInfoDto fileInfo, int idUser, IFileShareService fileShareService,
CancellationToken token) CancellationToken token)
{ {
var fileWebUrl = fileInfo.PublishInfo?.WebStorageFileUrl; var fileWebUrl = fileInfo.PublishInfo?.WebStorageFileUrl;

View File

@ -11,7 +11,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using Google.Apis.Auth.OAuth2.Responses;
namespace AsbCloudInfrastructure.Services namespace AsbCloudInfrastructure.Services
{ {

View File

@ -23,7 +23,7 @@ namespace AsbCloudInfrastructure.Services
private readonly IReportsBackgroundQueue queue; private readonly IReportsBackgroundQueue queue;
public ReportService(IAsbCloudDbContext db, IConfiguration configuration, public ReportService(IAsbCloudDbContext db, IConfiguration configuration,
ITelemetryService telemetryService, IFileService fileService, ITelemetryService telemetryService,
IReportsBackgroundQueue queue) IReportsBackgroundQueue queue)
{ {
this.db = db; this.db = db;
@ -59,7 +59,7 @@ namespace AsbCloudInfrastructure.Services
}; };
generator.Make(reportFileName); generator.Make(reportFileName);
var fileService = new FileService(context, new GoogleDriveService()); var fileService = new FileService(context);
var fileInfo = fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName).Result; var fileInfo = fileService.MoveAsync(idWell, idUser, ReportCategoryId, reportFileName, reportFileName).Result;
progressHandler.Invoke(new progressHandler.Invoke(new

View File

@ -55,16 +55,17 @@ namespace AsbCloudWebApi.Controllers
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name); return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
} }
/// <summary> /// <summary>
/// Создает программу бурения /// Создает программу бурения
/// </summary> /// </summary>
/// <param name="idWell"> id скважины </param> /// <param name="idWell"> id скважины </param>
/// <param name="fileShareService"></param>
/// <param name="token"> Токен отмены задачи </param> /// <param name="token"> Токен отмены задачи </param>
/// <returns> Возвращает ссылку на файл программы бурения в облаке </returns> /// <returns> Возвращает ссылку на файл программы бурения в облаке </returns>
[HttpGet("webUrl")] [HttpGet("webUrl")]
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetOrCreateSharedUrlAsync(int idWell, CancellationToken token = default) public async Task<IActionResult> GetOrCreateSharedUrlAsync(int idWell, [FromServices]IFileShareService fileShareService, CancellationToken token = default)
{ {
var idCompany = User.GetCompanyId(); var idCompany = User.GetCompanyId();
@ -76,7 +77,7 @@ namespace AsbCloudWebApi.Controllers
return Forbid(); return Forbid();
var sharedUrl = await drillingProgramService.GetOrCreateSharedUrlAsync(idWell, var sharedUrl = await drillingProgramService.GetOrCreateSharedUrlAsync(idWell,
(int)idUser, token) (int)idUser, fileShareService, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(sharedUrl); return Ok(sharedUrl);