Dosya yöneticisi Tenant path düzenlemesi
This commit is contained in:
parent
cb4a74bf81
commit
dd82d405ce
1 changed files with 31 additions and 15 deletions
|
|
@ -49,8 +49,24 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const string HostFolderName = "host";
|
||||||
|
private const string TenantsFolderName = "tenants";
|
||||||
|
|
||||||
private string GetTenantPrefix(string tenantId) => $"tenants/{tenantId}/";
|
private string GetTenantPrefix(string tenantId) => $"tenants/{tenantId}/";
|
||||||
|
|
||||||
|
private static bool IsHostTenant(string tenantId) =>
|
||||||
|
tenantId.Equals(HostFolderName, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
private static string ToSystemPath(string path) =>
|
||||||
|
path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
|
private static string GetCdnTenantRootPath(string cdnBasePath, string effectiveTenantId)
|
||||||
|
{
|
||||||
|
return IsHostTenant(effectiveTenantId)
|
||||||
|
? Path.Combine(cdnBasePath, HostFolderName)
|
||||||
|
: Path.Combine(cdnBasePath, TenantsFolderName, effectiveTenantId);
|
||||||
|
}
|
||||||
|
|
||||||
private static string NormalizeExtension(string? extensionOrFileName)
|
private static string NormalizeExtension(string? extensionOrFileName)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(extensionOrFileName))
|
if (string.IsNullOrWhiteSpace(extensionOrFileName))
|
||||||
|
|
@ -140,11 +156,11 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullPath = Path.Combine(cdnBasePath, tenantId);
|
var fullPath = GetCdnTenantRootPath(cdnBasePath, tenantId);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(folderPath))
|
if (!string.IsNullOrEmpty(folderPath))
|
||||||
{
|
{
|
||||||
fullPath = Path.Combine(fullPath, folderPath);
|
fullPath = Path.Combine(fullPath, ToSystemPath(folderPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -296,13 +312,13 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
}
|
}
|
||||||
|
|
||||||
var tenantId = GetEffectiveTenantId(input.TenantId);
|
var tenantId = GetEffectiveTenantId(input.TenantId);
|
||||||
var parentPath = Path.Combine(cdnBasePath, tenantId);
|
var parentPath = GetCdnTenantRootPath(cdnBasePath, tenantId);
|
||||||
|
|
||||||
string? decodedParentId = null;
|
string? decodedParentId = null;
|
||||||
if (!string.IsNullOrEmpty(input.ParentId))
|
if (!string.IsNullOrEmpty(input.ParentId))
|
||||||
{
|
{
|
||||||
decodedParentId = DecodeIdAsPath(input.ParentId);
|
decodedParentId = DecodeIdAsPath(input.ParentId);
|
||||||
parentPath = Path.Combine(parentPath, decodedParentId);
|
parentPath = Path.Combine(parentPath, ToSystemPath(decodedParentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
var folderPath = Path.Combine(parentPath, input.Name);
|
var folderPath = Path.Combine(parentPath, input.Name);
|
||||||
|
|
@ -383,11 +399,11 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
throw new UserFriendlyException("CDN path is not configured");
|
throw new UserFriendlyException("CDN path is not configured");
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullCdnPath = Path.Combine(cdnBasePath, tenantId);
|
var fullCdnPath = GetCdnTenantRootPath(cdnBasePath, tenantId);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(decodedParentId))
|
if (!string.IsNullOrEmpty(decodedParentId))
|
||||||
{
|
{
|
||||||
fullCdnPath = Path.Combine(fullCdnPath, decodedParentId);
|
fullCdnPath = Path.Combine(fullCdnPath, ToSystemPath(decodedParentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dizini oluştur
|
// Dizini oluştur
|
||||||
|
|
@ -598,7 +614,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
|
|
||||||
var effectiveTenantId = GetEffectiveTenantId(tenantId);
|
var effectiveTenantId = GetEffectiveTenantId(tenantId);
|
||||||
var actualPath = DecodeIdAsPath(id);
|
var actualPath = DecodeIdAsPath(id);
|
||||||
var fullPath = Path.Combine(cdnBasePath, effectiveTenantId, actualPath);
|
var fullPath = Path.Combine(GetCdnTenantRootPath(cdnBasePath, effectiveTenantId), ToSystemPath(actualPath));
|
||||||
|
|
||||||
if (Directory.Exists(fullPath))
|
if (Directory.Exists(fullPath))
|
||||||
{
|
{
|
||||||
|
|
@ -641,7 +657,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
ValidateNotProtectedFolder(itemId, "delete");
|
ValidateNotProtectedFolder(itemId, "delete");
|
||||||
|
|
||||||
var actualPath = DecodeIdAsPath(itemId);
|
var actualPath = DecodeIdAsPath(itemId);
|
||||||
var fullPath = Path.Combine(cdnBasePath, tenantId, actualPath);
|
var fullPath = Path.Combine(GetCdnTenantRootPath(cdnBasePath, tenantId), ToSystemPath(actualPath));
|
||||||
|
|
||||||
if (Directory.Exists(fullPath))
|
if (Directory.Exists(fullPath))
|
||||||
{
|
{
|
||||||
|
|
@ -685,7 +701,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
}
|
}
|
||||||
|
|
||||||
var tenantId = GetEffectiveTenantId(input.TenantId);
|
var tenantId = GetEffectiveTenantId(input.TenantId);
|
||||||
var basePath = Path.Combine(cdnBasePath, tenantId);
|
var basePath = GetCdnTenantRootPath(cdnBasePath, tenantId);
|
||||||
|
|
||||||
string? targetPath = null;
|
string? targetPath = null;
|
||||||
if (!string.IsNullOrEmpty(input.TargetFolderId))
|
if (!string.IsNullOrEmpty(input.TargetFolderId))
|
||||||
|
|
@ -701,14 +717,14 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sourcePath = DecodeIdAsPath(itemId);
|
var sourcePath = DecodeIdAsPath(itemId);
|
||||||
var sourceFullPath = Path.Combine(basePath, sourcePath);
|
var sourceFullPath = Path.Combine(basePath, ToSystemPath(sourcePath));
|
||||||
|
|
||||||
// Get source item name
|
// Get source item name
|
||||||
var sourceItemName = Path.GetFileName(sourcePath);
|
var sourceItemName = Path.GetFileName(sourcePath);
|
||||||
|
|
||||||
// Generate unique name if item already exists in target
|
// Generate unique name if item already exists in target
|
||||||
var targetItemPath = string.IsNullOrEmpty(targetPath) ? sourceItemName : $"{targetPath}/{sourceItemName}";
|
var targetItemPath = string.IsNullOrEmpty(targetPath) ? sourceItemName : $"{targetPath}/{sourceItemName}";
|
||||||
var targetFullPath = Path.Combine(basePath, targetItemPath);
|
var targetFullPath = Path.Combine(basePath, ToSystemPath(targetItemPath));
|
||||||
|
|
||||||
var uniqueTargetPath = GetUniqueItemPath(targetFullPath, sourceItemName);
|
var uniqueTargetPath = GetUniqueItemPath(targetFullPath, sourceItemName);
|
||||||
var finalTargetPath = uniqueTargetPath.Replace(basePath + Path.DirectorySeparatorChar, "").Replace(Path.DirectorySeparatorChar, '/');
|
var finalTargetPath = uniqueTargetPath.Replace(basePath + Path.DirectorySeparatorChar, "").Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
|
@ -796,7 +812,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
}
|
}
|
||||||
|
|
||||||
var tenantId = GetEffectiveTenantId(input.TenantId);
|
var tenantId = GetEffectiveTenantId(input.TenantId);
|
||||||
var basePath = Path.Combine(cdnBasePath, tenantId);
|
var basePath = GetCdnTenantRootPath(cdnBasePath, tenantId);
|
||||||
|
|
||||||
string? targetPath = null;
|
string? targetPath = null;
|
||||||
if (!string.IsNullOrEmpty(input.TargetFolderId))
|
if (!string.IsNullOrEmpty(input.TargetFolderId))
|
||||||
|
|
@ -815,14 +831,14 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
ValidateNotProtectedFolder(itemId, "move");
|
ValidateNotProtectedFolder(itemId, "move");
|
||||||
|
|
||||||
var sourcePath = DecodeIdAsPath(itemId);
|
var sourcePath = DecodeIdAsPath(itemId);
|
||||||
var sourceFullPath = Path.Combine(basePath, sourcePath);
|
var sourceFullPath = Path.Combine(basePath, ToSystemPath(sourcePath));
|
||||||
|
|
||||||
// Get source item name
|
// Get source item name
|
||||||
var sourceItemName = Path.GetFileName(sourcePath);
|
var sourceItemName = Path.GetFileName(sourcePath);
|
||||||
|
|
||||||
// Generate target path
|
// Generate target path
|
||||||
var targetItemPath = string.IsNullOrEmpty(targetPath) ? sourceItemName : $"{targetPath}/{sourceItemName}";
|
var targetItemPath = string.IsNullOrEmpty(targetPath) ? sourceItemName : $"{targetPath}/{sourceItemName}";
|
||||||
var targetFullPath = Path.Combine(basePath, targetItemPath);
|
var targetFullPath = Path.Combine(basePath, ToSystemPath(targetItemPath));
|
||||||
|
|
||||||
// Check if moving to same location
|
// Check if moving to same location
|
||||||
if (Path.GetFullPath(sourceFullPath) == Path.GetFullPath(targetFullPath))
|
if (Path.GetFullPath(sourceFullPath) == Path.GetFullPath(targetFullPath))
|
||||||
|
|
@ -920,7 +936,7 @@ public class FileManagementAppService : ApplicationService, IFileManagementAppSe
|
||||||
|
|
||||||
var effectiveTenantId = GetEffectiveTenantId(tenantId);
|
var effectiveTenantId = GetEffectiveTenantId(tenantId);
|
||||||
var actualPath = DecodeIdAsPath(id);
|
var actualPath = DecodeIdAsPath(id);
|
||||||
var fullFilePath = Path.Combine(cdnBasePath, effectiveTenantId, actualPath);
|
var fullFilePath = Path.Combine(GetCdnTenantRootPath(cdnBasePath, effectiveTenantId), ToSystemPath(actualPath));
|
||||||
|
|
||||||
if (!File.Exists(fullFilePath))
|
if (!File.Exists(fullFilePath))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue