forked from ddrilling/AsbCloudServer
valid file extension
This commit is contained in:
parent
325c5054fe
commit
b7f1962c6f
@ -51,6 +51,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
private const int idStateReady = 3;
|
private const int idStateReady = 3;
|
||||||
private const int idStateError = 4;
|
private const int idStateError = 4;
|
||||||
|
|
||||||
|
private static readonly string[] filePermittedExt = { ".xlsx", ".xls", ".ods", ".odt", ".doc", ".docx", ".pdf" };
|
||||||
|
|
||||||
public DrillingProgramService(
|
public DrillingProgramService(
|
||||||
IAsbCloudDbContext context,
|
IAsbCloudDbContext context,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
@ -161,9 +163,19 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
await EnqueueMakeProgramWorkAsync(idWell, state, token);
|
await EnqueueMakeProgramWorkAsync(idWell, state, token);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
private bool ValidExtFile(string file)
|
||||||
|
{
|
||||||
|
var fileExt = Path.GetExtension(file);
|
||||||
|
var badExt = Array.Find(filePermittedExt, e => e == fileExt);
|
||||||
|
if (badExt is null)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public async Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default)
|
public async Task<int> AddFile(int idWell, int idFileCategory, int idUser, string fileFullName, System.IO.Stream fileStream, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
if (!ValidExtFile(fileFullName))
|
||||||
|
throw new FileFormatException($"Файл {fileFullName} - неподдерживаемого формата. Файл не может быть загружен. ");
|
||||||
|
|
||||||
var part = await context.DrillingProgramParts
|
var part = await context.DrillingProgramParts
|
||||||
.Include(p => p.RelatedUsers)
|
.Include(p => p.RelatedUsers)
|
||||||
.ThenInclude(r => r.User)
|
.ThenInclude(r => r.User)
|
||||||
@ -465,6 +477,8 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
|||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private async Task EnqueueMakeProgramWorkAsync(int idWell, DrillingProgramStateDto state, CancellationToken token)
|
private async Task EnqueueMakeProgramWorkAsync(int idWell, DrillingProgramStateDto state, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (state.IdState == idStateCreating)
|
if (state.IdState == idStateCreating)
|
||||||
|
Loading…
Reference in New Issue
Block a user