diff --git a/api/src/Sozsoft.Platform.Application/FileManagement/FileManagementAppService.cs b/api/src/Sozsoft.Platform.Application/FileManagement/FileManagementAppService.cs index da57029..9171ccf 100644 --- a/api/src/Sozsoft.Platform.Application/FileManagement/FileManagementAppService.cs +++ b/api/src/Sozsoft.Platform.Application/FileManagement/FileManagementAppService.cs @@ -51,6 +51,34 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe private string GetTenantPrefix(string tenantId) => $"tenants/{tenantId}/"; + private static string NormalizeExtension(string? extensionOrFileName) + { + if (string.IsNullOrWhiteSpace(extensionOrFileName)) + { + return string.Empty; + } + + var ext = extensionOrFileName.Trim(); + + // If a path was provided, extract extension from the file name + if (ext.Contains('/') || ext.Contains('\\')) + { + ext = Path.GetExtension(ext); + } + else if (!ext.StartsWith('.') && ext.Contains('.')) + { + // File name like "photo.jpg" (but not an extension like ".jpg") + ext = Path.GetExtension(ext); + } + + if (string.IsNullOrWhiteSpace(ext)) + { + return string.Empty; + } + + return ext.Trim().TrimStart('.').ToLowerInvariant(); + } + private string GetEffectiveTenantId(string? inputTenantId) => !string.IsNullOrEmpty(inputTenantId) ? inputTenantId : (_currentTenant.Id?.ToString() ?? "host"); @@ -170,6 +198,8 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe var fileInfo = new FileInfo(file); var relativePath = string.IsNullOrEmpty(folderPath) ? fileInfo.Name : $"{folderPath}/{fileInfo.Name}"; + var normalizedExtension = NormalizeExtension(fileInfo.Extension); + items.Add(new FileMetadata { Id = EncodePathAsId(relativePath), @@ -181,7 +211,9 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe Path = relativePath, ParentId = folderPath ?? "", IsReadOnly = false, - TenantId = tenantId == "host" ? null : tenantId + TenantId = tenantId == "host" ? null : tenantId, + Extension = normalizedExtension, + MimeType = GetMimeType(normalizedExtension) }); } @@ -379,6 +411,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe } var fileInfo = new FileInfo(uniqueFileName); + var normalizedExtension = NormalizeExtension(fileInfo.Extension); var metadata = new FileMetadata { @@ -386,8 +419,8 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe Name = uniqueFileName, Type = "file", Size = fileSize, - Extension = fileInfo.Extension, - MimeType = GetMimeType(fileInfo.Extension), + Extension = normalizedExtension, + MimeType = GetMimeType(normalizedExtension), CreatedAt = DateTime.UtcNow, ModifiedAt = DateTime.UtcNow, Path = filePath, @@ -711,7 +744,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe File.Copy(sourceFullPath, uniqueTargetPath); var fileInfo = new FileInfo(uniqueTargetPath); - var extension = fileInfo.Extension; + var extension = NormalizeExtension(fileInfo.Extension); copiedItems.Add(new FileItemDto { @@ -839,7 +872,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe File.Move(sourceFullPath, uniqueTargetPath); var fileInfo = new FileInfo(uniqueTargetPath); - var extension = fileInfo.Extension; + var extension = NormalizeExtension(fileInfo.Extension); movedItems.Add(new FileItemDto { @@ -1013,7 +1046,16 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe private string GetMimeType(string extension) { - return extension.ToLowerInvariant() switch + if (string.IsNullOrWhiteSpace(extension)) + { + return "application/octet-stream"; + } + + var normalized = extension.Trim(); + normalized = normalized.StartsWith('.') ? normalized : "." + normalized; + normalized = normalized.ToLowerInvariant(); + + return normalized switch { ".txt" => "text/plain", ".pdf" => "application/pdf", diff --git a/ui/src/views/admin/files/components/FileItem.tsx b/ui/src/views/admin/files/components/FileItem.tsx index 7ae2a47..aef54e8 100644 --- a/ui/src/views/admin/files/components/FileItem.tsx +++ b/ui/src/views/admin/files/components/FileItem.tsx @@ -324,6 +324,8 @@ const FileItem = forwardRef((props, ref) => { const ImagePreview = ({ src, alt }: { src: string; alt: string }) => { const [imageError, setImageError] = useState(false) + console.log('Rendering ImagePreview with src:', src) // Debug için + return (
{!imageError ? ( @@ -378,7 +380,7 @@ const FileItem = forwardRef((props, ref) => {
{item.type === 'file' && item.mimeType?.startsWith('image/') ? ( ) : ( @@ -477,7 +479,7 @@ const FileItem = forwardRef((props, ref) => { {item.type === 'file' && item.mimeType?.startsWith('image/') ? (