more fixes
This commit is contained in:
@@ -22,7 +22,7 @@ public class FileCleanupService : IHostedService
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_services = services;
|
_services = services;
|
||||||
_configuration = configuration.GetRequiredSection("MareSynchronos");
|
_configuration = configuration.GetRequiredSection("MareSynchronos");
|
||||||
_isMainServer = string.IsNullOrEmpty(_configuration.GetValue("RemoteCacheSource", string.Empty));
|
_isMainServer = string.IsNullOrEmpty(_configuration.GetValue("RemoteCacheSourceUri", string.Empty));
|
||||||
_cacheDir = _configuration.GetValue<string>("CacheDirectory");
|
_cacheDir = _configuration.GetValue<string>("CacheDirectory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ public class FileCleanupService : IHostedService
|
|||||||
_metrics.DecGauge(MetricsAPI.GaugeFilesTotalSize, file.Length);
|
_metrics.DecGauge(MetricsAPI.GaugeFilesTotalSize, file.Length);
|
||||||
_metrics.DecGauge(MetricsAPI.GaugeFilesTotal);
|
_metrics.DecGauge(MetricsAPI.GaugeFilesTotal);
|
||||||
file.Delete();
|
file.Delete();
|
||||||
_logger.LogInformation("File not in DB, deleting: {fileName}", file.FullName);
|
_logger.LogInformation("File not in DB, deleting: {fileName}", file.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ public class GrpcFileService : FileService.FileServiceBase
|
|||||||
var filePath = FilePathUtil.GetFilePath(_basePath, uploadMsg.Hash);
|
var filePath = FilePathUtil.GetFilePath(_basePath, uploadMsg.Hash);
|
||||||
using var fileWriter = File.OpenWrite(filePath);
|
using var fileWriter = File.OpenWrite(filePath);
|
||||||
var file = await _mareDbContext.Files.SingleOrDefaultAsync(f => f.Hash == uploadMsg.Hash && f.UploaderUID == uploadMsg.Uploader).ConfigureAwait(false);
|
var file = await _mareDbContext.Files.SingleOrDefaultAsync(f => f.Hash == uploadMsg.Hash && f.UploaderUID == uploadMsg.Uploader).ConfigureAwait(false);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
if (file != null)
|
if (file != null)
|
||||||
{
|
{
|
||||||
await fileWriter.WriteAsync(uploadMsg.FileData.ToArray()).ConfigureAwait(false);
|
await fileWriter.WriteAsync(uploadMsg.FileData.ToArray()).ConfigureAwait(false);
|
||||||
@@ -43,12 +46,25 @@ public class GrpcFileService : FileService.FileServiceBase
|
|||||||
var fileSize = new FileInfo(filePath).Length;
|
var fileSize = new FileInfo(filePath).Length;
|
||||||
file.Uploaded = true;
|
file.Uploaded = true;
|
||||||
|
|
||||||
|
await _mareDbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_metricsClient.IncGauge(MetricsAPI.GaugeFilesTotal, 1);
|
_metricsClient.IncGauge(MetricsAPI.GaugeFilesTotal, 1);
|
||||||
_metricsClient.IncGauge(MetricsAPI.GaugeFilesTotalSize, fileSize);
|
_metricsClient.IncGauge(MetricsAPI.GaugeFilesTotalSize, fileSize);
|
||||||
|
|
||||||
await _mareDbContext.SaveChangesAsync().ConfigureAwait(false);
|
|
||||||
_logger.LogInformation("User {user} uploaded file {hash}", uploadMsg.Uploader, uploadMsg.Hash);
|
_logger.LogInformation("User {user} uploaded file {hash}", uploadMsg.Uploader, uploadMsg.Hash);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(ex, "Error during UploadFile");
|
||||||
|
var fileNew = await _mareDbContext.Files.SingleOrDefaultAsync(f => f.Hash == uploadMsg.Hash && f.UploaderUID == uploadMsg.Uploader).ConfigureAwait(false);
|
||||||
|
if (fileNew != null)
|
||||||
|
{
|
||||||
|
_mareDbContext.Files.Remove(fileNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _mareDbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
return new Empty();
|
return new Empty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user