init
This commit is contained in:
@@ -38,6 +38,46 @@ public class FilesController : ControllerBase
|
||||
return new FileStreamResult(fileStream, GetMimeType(physicalPath));
|
||||
}
|
||||
|
||||
[HttpGet("{id}/small")]
|
||||
public async Task<IActionResult> GetSmallThumbnail(int id)
|
||||
{
|
||||
await using var context = await _context.CreateDbContextAsync();
|
||||
FilePathListing fileRecord = await context.ArtifactFilePaths.FindAsync(id);
|
||||
|
||||
if (fileRecord == null) return NotFound();
|
||||
|
||||
var path = !string.IsNullOrEmpty(fileRecord.SmallThumbnailPath) && System.IO.File.Exists(fileRecord.SmallThumbnailPath)
|
||||
? fileRecord.SmallThumbnailPath
|
||||
: fileRecord.Path;
|
||||
|
||||
if (!System.IO.File.Exists(path)) return NotFound();
|
||||
|
||||
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var mimeType = path == fileRecord.SmallThumbnailPath ? "image/webp" : GetMimeType(path);
|
||||
|
||||
return new FileStreamResult(fileStream, mimeType);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/large")]
|
||||
public async Task<IActionResult> GetLargeThumbnail(int id)
|
||||
{
|
||||
await using var context = await _context.CreateDbContextAsync();
|
||||
FilePathListing fileRecord = await context.ArtifactFilePaths.FindAsync(id);
|
||||
|
||||
if (fileRecord == null) return NotFound();
|
||||
|
||||
var path = !string.IsNullOrEmpty(fileRecord.LargeThumbnailPath) && System.IO.File.Exists(fileRecord.LargeThumbnailPath)
|
||||
? fileRecord.LargeThumbnailPath
|
||||
: fileRecord.Path;
|
||||
|
||||
if (!System.IO.File.Exists(path)) return NotFound();
|
||||
|
||||
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var mimeType = path == fileRecord.LargeThumbnailPath ? "image/webp" : GetMimeType(path);
|
||||
|
||||
return new FileStreamResult(fileStream, mimeType);
|
||||
}
|
||||
|
||||
private static string GetMimeType(string filePath)
|
||||
{
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
@@ -47,6 +87,8 @@ public class FilesController : ControllerBase
|
||||
".jpeg" => "image/jpeg",
|
||||
".png" => "image/png",
|
||||
".gif" => "image/gif",
|
||||
".txt" => "text/plain",
|
||||
".pdf" => "application/pdf",
|
||||
_ => "application/octet-stream", // Default for unknown file types
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user