Rename projects to FileShare
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using FileShare_EFCore.Database;
|
||||
using FileShare_EFCore.Models;
|
||||
using FileShare_Services.Core;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FileShare_Services.Services.FileLibrary
|
||||
{
|
||||
public interface IFileStreamService
|
||||
{
|
||||
Task<FileStreamResponse?> GetFileStreamAsync(int id, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public sealed class FileStreamService(AppDataContext db) : IFileStreamService
|
||||
{
|
||||
public async Task<FileStreamResponse?> GetFileStreamAsync(int id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var file = await db.ManagedFileRecords
|
||||
.AsNoTracking()
|
||||
.Include(item => item.LibraryRoot)
|
||||
.FirstOrDefaultAsync(item =>
|
||||
item.Id == id
|
||||
&& item.Exists
|
||||
&& item.LibraryRoot != null
|
||||
&& item.LibraryRoot.IsAvailable,
|
||||
cancellationToken);
|
||||
|
||||
if (file is null || !System.IO.File.Exists(file.AbsolutePath))
|
||||
return null;
|
||||
|
||||
return new FileStreamResponse(
|
||||
file.AbsolutePath,
|
||||
file.FileName,
|
||||
file.ContentType,
|
||||
file.LastWriteTimeUtc);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user