[ADD] Added endpoint for providing files
This commit is contained in:
@@ -10,6 +10,7 @@ public interface ILibraryService
|
||||
{
|
||||
public Task<Result> FetchChannelImagesAsync(InnertubeChannel innertubeChannel);
|
||||
public Task<Result> SaveClientAsync(ClientAccountEntity client, CancellationToken cancellationToken = default);
|
||||
public Task<Result<LibraryFile>> GetFileByIdAsync(Guid id, CancellationToken cancellationToken = default);
|
||||
public Task<Result<ChannelEntity>> GetChannelByIdAsync(string id, CancellationToken cancellationToken = default);
|
||||
public Task<Result> SaveChannelAsync(InnertubeChannel innertubeChannel, CancellationToken cancellationToken = default);
|
||||
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Net.Mime;
|
||||
using DotBased.Monads;
|
||||
using Manager.App.Constants;
|
||||
using Manager.App.Models.Library;
|
||||
@@ -51,7 +52,7 @@ public class LibraryService : ILibraryService
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
return HandleException(e);
|
||||
}
|
||||
|
||||
return Result.Success();
|
||||
@@ -134,7 +135,27 @@ public class LibraryService : ILibraryService
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
return HandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Result<LibraryFile>> GetFileByIdAsync(Guid id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
var file = context.Files.FirstOrDefault(f => f.Id == id);
|
||||
if (file == null)
|
||||
{
|
||||
return ResultError.Fail($"File with id {id} not found.");
|
||||
}
|
||||
|
||||
var fs = new FileStream(Path.Combine(_libraryDirectory.FullName, file.RelativePath), FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
return new LibraryFile { DataStream = fs, SizeBytes = file.SizeBytes, FileName = file.OriginalFileName ?? file.Id.ToString(), MimeType = file.MimeType ?? MediaTypeNames.Application.Octet };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return HandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +306,7 @@ public class LibraryService : ILibraryService
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
return HandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +365,7 @@ public class LibraryService : ILibraryService
|
||||
return ResultError.Fail("Library service operation cancelled");
|
||||
}
|
||||
|
||||
_logger.LogError(exception, "Failed to get library information");
|
||||
_logger.LogError(exception, "Service error");
|
||||
return ResultError.Fail("Failed to get library information");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user