diff --git a/api/src/Kurs.Platform.Application/FileManagement/FileManagementAppService.cs b/api/src/Kurs.Platform.Application/FileManagement/FileManagementAppService.cs index 4ccd3307..63730cb8 100644 --- a/api/src/Kurs.Platform.Application/FileManagement/FileManagementAppService.cs +++ b/api/src/Kurs.Platform.Application/FileManagement/FileManagementAppService.cs @@ -9,6 +9,8 @@ using System.Text.Json; using System.Threading.Tasks; using Kurs.Platform.BlobStoring; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using Volo.Abp; using Volo.Abp.Application.Services; using Volo.Abp.MultiTenancy; @@ -19,6 +21,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe { private readonly ICurrentTenant _currentTenant; private readonly BlobManager _blobContainer; + private readonly IConfiguration _configuration; private const string FileMetadataSuffix = ".metadata.json"; private const string FolderMarkerSuffix = ".folder"; @@ -26,11 +29,13 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe public FileManagementAppService( ICurrentTenant currentTenant, - BlobManager blobContainer + BlobManager blobContainer, + IConfiguration configuration ) { _currentTenant = currentTenant; _blobContainer = blobContainer; + _configuration = configuration; } private string GetTenantPrefix() @@ -46,68 +51,85 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe private async Task> GetFolderIndexAsync(string? parentId = null) { - // Root seviyesinde default klasörleri göster - if (string.IsNullOrEmpty(parentId)) + return await GetRealCdnContentsAsync(parentId); + } + + private async Task> GetRealCdnContentsAsync(string? folderPath) + { + var items = new List(); + var cdnBasePath = _configuration["App:CdnPath"]; + + if (string.IsNullOrEmpty(cdnBasePath)) { - var defaultFolders = new List - { - // Default system folders - new() { - Id = BlobContainerNames.Avatar, - Name = "Avatar", - Type = "folder", - CreatedAt = DateTime.UtcNow, - ModifiedAt = DateTime.UtcNow, - Path = BlobContainerNames.Avatar, - ParentId = "", - IsReadOnly = false, - TenantId = _currentTenant.Id?.ToString() - }, - new() { - Id = BlobContainerNames.Import, - Name = "Import", - Type = "folder", - CreatedAt = DateTime.UtcNow, - ModifiedAt = DateTime.UtcNow, - Path = BlobContainerNames.Import, - ParentId = "", - IsReadOnly = false, - TenantId = _currentTenant.Id?.ToString() - }, - new() { - Id = BlobContainerNames.Activity, - Name = "Activity", - Type = "folder", - CreatedAt = DateTime.UtcNow, - ModifiedAt = DateTime.UtcNow, - Path = BlobContainerNames.Activity, - ParentId = "", - IsReadOnly = false, - TenantId = _currentTenant.Id?.ToString() - } - }; - - // Custom folders from index - var customFolders = await GetCustomFoldersAsync(); - defaultFolders.AddRange(customFolders); - - return defaultFolders; + Logger.LogWarning("CDN path is not configured"); + return items; } - // Alt klasörlerin indexini oku - var indexPath = GetTenantPrefix() + $"{parentId}/{IndexFileName}"; + var tenantId = _currentTenant.Id?.ToString() ?? "host"; + var fullPath = Path.Combine(cdnBasePath, tenantId); + + if (!string.IsNullOrEmpty(folderPath)) + { + fullPath = Path.Combine(fullPath, folderPath); + } try { - var indexBytes = await _blobContainer.GetAllBytesOrNullAsync(indexPath); - if (indexBytes == null) return new List(); + if (!Directory.Exists(fullPath)) + { + Logger.LogWarning($"Directory does not exist: {fullPath}"); + return items; + } - var indexJson = Encoding.UTF8.GetString(indexBytes); - return JsonSerializer.Deserialize>(indexJson) ?? new List(); + // Klasörleri listele + var directories = Directory.GetDirectories(fullPath); + foreach (var dir in directories) + { + var dirInfo = new DirectoryInfo(dir); + var relativePath = string.IsNullOrEmpty(folderPath) ? dirInfo.Name : $"{folderPath}/{dirInfo.Name}"; + + items.Add(new FileMetadata + { + Id = relativePath, + Name = dirInfo.Name, + Type = "folder", + CreatedAt = dirInfo.CreationTime, + ModifiedAt = dirInfo.LastWriteTime, + Path = relativePath, + ParentId = folderPath ?? "", + IsReadOnly = false, + TenantId = _currentTenant.Id?.ToString() + }); + } + + // Dosyaları listele + var files = Directory.GetFiles(fullPath); + foreach (var file in files) + { + var fileInfo = new FileInfo(file); + var relativePath = string.IsNullOrEmpty(folderPath) ? fileInfo.Name : $"{folderPath}/{fileInfo.Name}"; + + items.Add(new FileMetadata + { + Id = relativePath, + Name = fileInfo.Name, + Type = "file", + Size = fileInfo.Length, + CreatedAt = fileInfo.CreationTime, + ModifiedAt = fileInfo.LastWriteTime, + Path = relativePath, + ParentId = folderPath ?? "", + IsReadOnly = false, + TenantId = _currentTenant.Id?.ToString() + }); + } + + return items.OrderBy(x => x.Type == "folder" ? 0 : 1).ThenBy(x => x.Name).ToList(); } - catch + catch (Exception ex) { - return new List(); + Logger.LogError(ex, $"Error reading CDN contents from: {fullPath}"); + return items; } } @@ -555,7 +577,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe private async Task> GetAllItemsRecursivelyAsync(string? parentId = null, List? result = null) { - result ??= new List(); + result ??= []; var items = await GetFolderIndexAsync(parentId); result.AddRange(items); diff --git a/ui/src/views/admin/files/FileManager.tsx b/ui/src/views/admin/files/FileManager.tsx index 1e5b2d71..97c806cc 100644 --- a/ui/src/views/admin/files/FileManager.tsx +++ b/ui/src/views/admin/files/FileManager.tsx @@ -269,11 +269,6 @@ const FileManager = () => { setDeleteModalOpen(true) } - const handleDeleteSelected = () => { - const itemsToDelete = items.filter((item) => selectedItems.includes(item.id)) - openDeleteModal(itemsToDelete) - } - const goUpOneLevel = () => { if (breadcrumbItems.length > 1) { const parentBreadcrumb = breadcrumbItems[breadcrumbItems.length - 2] @@ -311,15 +306,6 @@ const FileManager = () => { Go Up )} - {selectedItems.length > 0 && ( - - )}