try fix delete
This commit is contained in:
@ -45,7 +45,7 @@ public static class Extensions
|
|||||||
RegionEndpoint = !string.IsNullOrEmpty(c.Region) ? RegionEndpoint.GetBySystemName(c.Region) : null,
|
RegionEndpoint = !string.IsNullOrEmpty(c.Region) ? RegionEndpoint.GetBySystemName(c.Region) : null,
|
||||||
ServiceURL = c.ServiceUrl.ToString(),
|
ServiceURL = c.ServiceUrl.ToString(),
|
||||||
UseHttp = c.ServiceUrl.Scheme == "http",
|
UseHttp = c.ServiceUrl.Scheme == "http",
|
||||||
ForcePathStyle = true
|
ForcePathStyle = true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,20 +6,11 @@ using NostrStreamer.Database;
|
|||||||
|
|
||||||
namespace NostrStreamer.Services.Dvr;
|
namespace NostrStreamer.Services.Dvr;
|
||||||
|
|
||||||
public class S3DvrStore : IDvrStore
|
public class S3DvrStore(Config config, HttpClient httpClient, ILogger<S3DvrStore> logger)
|
||||||
|
: IDvrStore
|
||||||
{
|
{
|
||||||
private readonly AmazonS3Client _client;
|
private readonly AmazonS3Client _client = config.S3Store.CreateClient();
|
||||||
private readonly S3BlobConfig _config;
|
private readonly S3BlobConfig _config = config.S3Store;
|
||||||
private readonly HttpClient _httpClient;
|
|
||||||
private readonly ILogger<S3DvrStore> _logger;
|
|
||||||
|
|
||||||
public S3DvrStore(Config config, HttpClient httpClient, ILogger<S3DvrStore> logger)
|
|
||||||
{
|
|
||||||
_httpClient = httpClient;
|
|
||||||
_logger = logger;
|
|
||||||
_config = config.S3Store;
|
|
||||||
_client = config.S3Store.CreateClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<UploadResult> UploadRecording(UserStream stream, Uri source)
|
public async Task<UploadResult> UploadRecording(UserStream stream, Uri source)
|
||||||
{
|
{
|
||||||
@ -43,7 +34,7 @@ public class S3DvrStore : IDvrStore
|
|||||||
|
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
await using var fs = new FileStream(tmpFile, FileMode.Create, FileAccess.ReadWrite);
|
await using var fs = new FileStream(tmpFile, FileMode.Create, FileAccess.ReadWrite);
|
||||||
var dl = await _httpClient.GetStreamAsync(source);
|
var dl = await httpClient.GetStreamAsync(source);
|
||||||
await dl.CopyToAsync(fs);
|
await dl.CopyToAsync(fs);
|
||||||
await fs.FlushAsync();
|
await fs.FlushAsync();
|
||||||
fs.Seek(0, SeekOrigin.Begin);
|
fs.Seek(0, SeekOrigin.Begin);
|
||||||
@ -87,7 +78,7 @@ public class S3DvrStore : IDvrStore
|
|||||||
fs.Close();
|
fs.Close();
|
||||||
File.Delete(tmpFile);
|
File.Delete(tmpFile);
|
||||||
|
|
||||||
_logger.LogInformation("download={tc:#,##0}ms, probe={pc:#,##0}ms, upload={uc:#,##0}ms",
|
logger.LogInformation("download={tc:#,##0}ms, probe={pc:#,##0}ms, upload={uc:#,##0}ms",
|
||||||
tsDownload.TotalMilliseconds,
|
tsDownload.TotalMilliseconds,
|
||||||
tsProbe.TotalMilliseconds, tsUpload.TotalMilliseconds);
|
tsProbe.TotalMilliseconds, tsUpload.TotalMilliseconds);
|
||||||
|
|
||||||
@ -97,7 +88,7 @@ public class S3DvrStore : IDvrStore
|
|||||||
public async Task<List<Guid>> DeleteRecordings(UserStream stream)
|
public async Task<List<Guid>> DeleteRecordings(UserStream stream)
|
||||||
{
|
{
|
||||||
var deleted = new List<Guid>();
|
var deleted = new List<Guid>();
|
||||||
foreach (var batch in stream.Recordings.Select((a, i) => (Batch: i / 1000, Item: a)).GroupBy(a => a.Batch))
|
foreach (var batch in stream.Recordings.Select((a, i) => (Batch: i / 100, Item: a)).GroupBy(a => a.Batch))
|
||||||
{
|
{
|
||||||
var res = await _client.DeleteObjectsAsync(new()
|
var res = await _client.DeleteObjectsAsync(new()
|
||||||
{
|
{
|
||||||
@ -110,6 +101,12 @@ public class S3DvrStore : IDvrStore
|
|||||||
deleted.AddRange(res.DeletedObjects.Select(a => Guid.Parse(Path.GetFileNameWithoutExtension(a.Key))));
|
deleted.AddRange(res.DeletedObjects.Select(a => Guid.Parse(Path.GetFileNameWithoutExtension(a.Key))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _client.DeleteObjectAsync(new()
|
||||||
|
{
|
||||||
|
BucketName = _config.BucketName,
|
||||||
|
Key = $"{stream.Id}/"
|
||||||
|
});
|
||||||
|
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,16 +5,10 @@ using NostrStreamer.Database;
|
|||||||
|
|
||||||
namespace NostrStreamer.Services.Thumbnail;
|
namespace NostrStreamer.Services.Thumbnail;
|
||||||
|
|
||||||
public class S3ThumbnailService : BaseThumbnailService, IThumbnailService
|
public class S3ThumbnailService(Config config, ILogger<S3ThumbnailService> logger, StreamerContext context)
|
||||||
|
: BaseThumbnailService(config, logger), IThumbnailService
|
||||||
{
|
{
|
||||||
private readonly AmazonS3Client _client;
|
private readonly AmazonS3Client _client = config.S3Store.CreateClient();
|
||||||
private readonly StreamerContext _context;
|
|
||||||
|
|
||||||
public S3ThumbnailService(Config config, ILogger<S3ThumbnailService> logger, StreamerContext context) : base(config, logger)
|
|
||||||
{
|
|
||||||
_client = config.S3Store.CreateClient();
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task GenerateThumb(UserStream stream)
|
public async Task GenerateThumb(UserStream stream)
|
||||||
{
|
{
|
||||||
@ -54,7 +48,7 @@ public class S3ThumbnailService : BaseThumbnailService, IThumbnailService
|
|||||||
|
|
||||||
var tUpload = sw.Elapsed;
|
var tUpload = sw.Elapsed;
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
await _context.Streams.Where(a => a.Id == stream.Id)
|
await context.Streams.Where(a => a.Id == stream.Id)
|
||||||
.ExecuteUpdateAsync(o => o.SetProperty(v => v.Thumbnail, ub.Uri.ToString()));
|
.ExecuteUpdateAsync(o => o.SetProperty(v => v.Thumbnail, ub.Uri.ToString()));
|
||||||
|
|
||||||
var tDbUpdate = sw.Elapsed;
|
var tDbUpdate = sw.Elapsed;
|
||||||
|
Reference in New Issue
Block a user