Skip to content

Commit 828edca

Browse files
authored
Develop to main (#90)
* fix: fix folder creation logic to ensure CurrentFolder is valid before proceeding * fix: solve upload to empty folder and upload to root folder * fix: solve folder problem
1 parent b6f7095 commit 828edca

2 files changed

Lines changed: 38 additions & 22 deletions

File tree

TelegramDownloader/Data/FileService.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,18 @@ public async Task importSharedData(ShareFilesModel sfm, GenericNotificationProgr
10731073

10741074
public async Task<List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent>> createFolder(string dbName, FolderCreateEventArgs<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> args)
10751075
{
1076-
return (await _db.createEntry(dbName, await _db.toBasonFile(args.Path, args.FolderName, args.ParentFolder))).Select(x => x.toFileManagerContent()).ToList();
1076+
var result = (await _db.createEntry(dbName, await _db.toBasonFile(args.Path, args.FolderName, args.ParentFolder))).Select(x => x.toFileManagerContent()).ToList();
1077+
if (!string.IsNullOrEmpty(args.ParentFolder?.Id))
1078+
await _db.setDirectoryHasChild(dbName, args.ParentFolder.Id);
1079+
return result;
10771080
}
10781081

10791082
public async Task<List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent>> createFolder(string dbName, string path, string folderName, Syncfusion.Blazor.FileManager.FileManagerDirectoryContent? parentFolder)
10801083
{
1081-
return (await _db.createEntry(dbName, await _db.toBasonFile(path, folderName, parentFolder))).Select(x => x.toFileManagerContent()).ToList();
1084+
var result = (await _db.createEntry(dbName, await _db.toBasonFile(path, folderName, parentFolder))).Select(x => x.toFileManagerContent()).ToList();
1085+
if (!string.IsNullOrEmpty(parentFolder?.Id))
1086+
await _db.setDirectoryHasChild(dbName, parentFolder.Id);
1087+
return result;
10821088
}
10831089

10841090
public async Task CreateDatabase(string id)
@@ -1608,12 +1614,18 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
16081614
}
16091615
}
16101616
BsonFileManagerModel parent = await _db.getParentDirectoryByPath(dbName, currentPath);
1617+
if (parent == null)
1618+
{
1619+
parent = await _db.getRootFolder(dbName);
1620+
}
16111621
model.Name = file.IsFile ? fileInfo.Name : file.Name;
16121622
model.IsFile = file.IsFile;
16131623
model.HasChild = false;
16141624
model.DateCreated = DateTime.Now;
16151625
model.DateModified = DateTime.Now;
1616-
model.FilterPath = (currentPath == "/" || currentPath == "File/") ? currentPath : string.Concat(parent.FilterPath, parent.Name, "/");
1626+
model.FilterPath = parent.FilterPath == ""
1627+
? "/"
1628+
: string.Concat(parent.FilterPath, parent.Name, "/");
16171629
model.FilterId = string.Concat(parent.FilterId, parent.Id.ToString(), "/");
16181630
model.ParentId = parent.Id;
16191631
model.FilePath = System.IO.Path.Combine(currentPath, file.IsFile ? fileInfo.Name : file.Name);
@@ -1858,14 +1870,20 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
18581870
}
18591871

18601872
BsonFileManagerModel parent = await _db.getParentDirectoryByPath(dbName, currentPath);
1873+
if (parent == null)
1874+
{
1875+
parent = await _db.getRootFolder(dbName);
1876+
}
18611877
_logger.LogDebug("Parent directory found - ParentId: {ParentId}, ParentName: {ParentName}", parent?.Id, parent?.Name);
18621878

18631879
model.Name = file.File.Name;
18641880
model.IsFile = true;
18651881
model.HasChild = false;
18661882
model.DateCreated = DateTime.Now;
18671883
model.DateModified = DateTime.Now;
1868-
model.FilterPath = string.Concat(parent.FilterPath, parent.Name, "/");
1884+
model.FilterPath = parent.FilterPath == ""
1885+
? "/"
1886+
: string.Concat(parent.FilterPath, parent.Name, "/");
18691887
model.FilterId = string.Concat(parent.FilterId, parent.Id.ToString(), "/");
18701888
model.ParentId = parent.Id;
18711889
model.FilePath = System.IO.Path.Combine(currentPath, file.File.Name);

TelegramDownloader/Shared/MobileFileManager/MobileFileManager.razor.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -892,29 +892,27 @@ private async Task ConfirmNewFolder()
892892
{
893893
if (string.IsNullOrWhiteSpace(NewFolderName)) return;
894894

895-
// Use CurrentFolder which has the correct Id from LoadFiles response
896-
FileManagerDirectoryContent parentFolder;
897-
if (CurrentFolder != null)
895+
// If CurrentFolder is missing or has no Id, refresh from the server first
896+
if (CurrentFolder == null || string.IsNullOrEmpty(CurrentFolder.Id))
898897
{
899-
parentFolder = new FileManagerDirectoryContent
900-
{
901-
Id = CurrentFolder.Id,
902-
Name = CurrentFolder.Name,
903-
FilterPath = NormalizePath(CurrentFolder.FilterPath ?? ""),
904-
FilterId = CurrentFolder.FilterId,
905-
IsFile = false
906-
};
898+
await LoadFiles();
907899
}
908-
else
900+
901+
// After refresh, if we still don't have a valid CurrentFolder with Id, abort
902+
if (CurrentFolder == null || string.IsNullOrEmpty(CurrentFolder.Id))
909903
{
910-
// Fallback for root - this shouldn't normally happen as LoadFiles sets CurrentFolder
911-
parentFolder = new FileManagerDirectoryContent
912-
{
913-
FilterPath = NormalizePath(CurrentPath),
914-
IsFile = false
915-
};
904+
return;
916905
}
917906

907+
var parentFolder = new FileManagerDirectoryContent
908+
{
909+
Id = CurrentFolder.Id,
910+
Name = CurrentFolder.Name,
911+
FilterPath = string.IsNullOrEmpty(CurrentFolder.FilterPath) ? "" : NormalizePath(CurrentFolder.FilterPath),
912+
FilterId = CurrentFolder.FilterId ?? "",
913+
IsFile = false
914+
};
915+
918916
var args = new MfmFolderCreateEventArgs
919917
{
920918
FolderName = NewFolderName,

0 commit comments

Comments
 (0)