Dosya Yöneticisi Resim güncellemeleri
This commit is contained in:
parent
401db7bfef
commit
cb4a74bf81
2 changed files with 52 additions and 8 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -324,6 +324,8 @@ const FileItem = forwardRef<HTMLDivElement, FileItemProps>((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 (
|
||||
<div className="w-full h-full bg-gray-100 dark:bg-gray-700 rounded flex items-center justify-center overflow-hidden">
|
||||
{!imageError ? (
|
||||
|
|
@ -378,7 +380,7 @@ const FileItem = forwardRef<HTMLDivElement, FileItemProps>((props, ref) => {
|
|||
<div className="w-8 h-8">
|
||||
{item.type === 'file' && item.mimeType?.startsWith('image/') ? (
|
||||
<ImagePreview
|
||||
src={`/api/app/file-management/${item.id}/download-file`}
|
||||
src={FILE_URL(item.path, item.tenantId)}
|
||||
alt={item.name}
|
||||
/>
|
||||
) : (
|
||||
|
|
@ -477,7 +479,7 @@ const FileItem = forwardRef<HTMLDivElement, FileItemProps>((props, ref) => {
|
|||
{item.type === 'file' && item.mimeType?.startsWith('image/') ? (
|
||||
<div className="w-16 h-16">
|
||||
<ImagePreview
|
||||
src={`/api/app/file-management/${item.id}/download-file`}
|
||||
src={FILE_URL(item.path, item.tenantId)}
|
||||
alt={item.name}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue