feat: update file storage paths and enhance thumbnail generation with category support
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -362,3 +362,7 @@ MigrationBackup/
|
||||
# # Fody - auto-generated XML schema
|
||||
# FodyWeavers.xsd
|
||||
.idea
|
||||
|
||||
# Storage folder - ignore all uploaded files, thumbnails, and temporary files
|
||||
ServiceHost/Storage
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public class TaskChatMessage : EntityBase<Guid>
|
||||
throw new BadRequestException("فقط فرستنده میتواند پیام را ویرایش کند");
|
||||
}
|
||||
|
||||
if (MessageType != MessageType.Text)
|
||||
if (MessageType != MessageType.Text || (MessageType != MessageType.Text && !string.IsNullOrWhiteSpace(TextContent)))
|
||||
{
|
||||
throw new BadRequestException("فقط پیامهای متنی قابل ویرایش هستند");
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ public class LocalFileStorageService : IFileStorageService
|
||||
var request = httpContextAccessor.HttpContext?.Request;
|
||||
if (request != null)
|
||||
{
|
||||
_baseUrl = $"{request.Scheme}://{request.Host}/uploads";
|
||||
_baseUrl = $"{request.Scheme}://{request.Host}/storage";
|
||||
}
|
||||
else
|
||||
{
|
||||
_baseUrl = configuration["FileStorage:BaseUrl"] ?? "http://localhost:5000/uploads";
|
||||
_baseUrl = configuration["FileStorage:BaseUrl"] ?? "http://localhost:5000/storage";
|
||||
}
|
||||
|
||||
// ایجاد پوشه اگر وجود نداشت
|
||||
|
||||
@@ -65,21 +65,12 @@ public class ThumbnailGeneratorService : IThumbnailGeneratorService
|
||||
var extension = Path.GetExtension(imagePath);
|
||||
var thumbnailFileName = $"{fileName}_thumb{extension}";
|
||||
|
||||
var categoryFolder = string.IsNullOrWhiteSpace(category) ? "general" : category;
|
||||
var categoryPath = Path.Combine(_thumbnailBasePath, categoryFolder);
|
||||
if (!Directory.Exists(categoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(categoryPath);
|
||||
}
|
||||
|
||||
// مسیر ذخیره thumbnail
|
||||
var thumbnailPath = Path.Combine(categoryPath, thumbnailFileName);
|
||||
// دریافت مسیر و URL توسط متد private
|
||||
var (thumbnailPath, thumbnailUrl) = GetThumbnailPathAndUrl(thumbnailFileName, category);
|
||||
|
||||
// ذخیره thumbnail با کیفیت 80
|
||||
await image.SaveAsync(thumbnailPath, new JpegEncoder { Quality = 80 });
|
||||
|
||||
// URL thumbnail
|
||||
var thumbnailUrl = $"{_baseUrl}/thumbnails/{categoryFolder}/{thumbnailFileName}";
|
||||
|
||||
return (thumbnailPath, thumbnailUrl);
|
||||
}
|
||||
@@ -125,4 +116,29 @@ public class ThumbnailGeneratorService : IThumbnailGeneratorService
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// دریافت مسیر فیزیکی و URL برای thumbnail بر اساس category
|
||||
/// </summary>
|
||||
private (string ThumbnailPath, string ThumbnailUrl) GetThumbnailPathAndUrl(string thumbnailFileName, string category)
|
||||
{
|
||||
var categoryFolder = string.IsNullOrWhiteSpace(category) ? "general" : category;
|
||||
var categoryPath = Path.Combine(Directory.GetCurrentDirectory(), "storage", categoryFolder);
|
||||
|
||||
if (!Directory.Exists(categoryPath))
|
||||
{
|
||||
Directory.CreateDirectory(categoryPath);
|
||||
}
|
||||
|
||||
var thumbnailSubPath = Path.Combine(categoryPath, "Thumbnails");
|
||||
if (!Directory.Exists(thumbnailSubPath))
|
||||
{
|
||||
Directory.CreateDirectory(thumbnailSubPath);
|
||||
}
|
||||
|
||||
var thumbnailPath = Path.Combine(thumbnailSubPath, thumbnailFileName);
|
||||
var thumbnailUrl = $"{_baseUrl}/{categoryFolder}/thumbnails/{thumbnailFileName}";
|
||||
|
||||
return (thumbnailPath, thumbnailUrl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user