Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion TelegramDownloader/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,50 @@ public async Task<IActionResult> GetFile(string id, string? idChannel, string? i
{
FileDownloadName = fileName,
EnableRangeProcessing = true


};
}

/// <summary>
/// View file inline (for PDF viewer, etc.) - doesn't trigger download
/// </summary>
[Route("ViewFile/{id}")]
public async Task<IActionResult> ViewFile(string id, string? idChannel, string? idFile)
{
var fileName = id;
var mimeType = FileService.getMimeType(id.Split(".").Last());
var file = _fs.ExistFileIntempFolder($"{idChannel}-{idFile}-{id}");
if (file == null)
{
TL.Message idM = await _ts.getMessageFile(idChannel, Convert.ToInt32(idFile));
ChatMessages cm = new ChatMessages();
cm.message = idM;
string filePath = System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{idFile}-{id}");
file = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
DownloadModel dm = new DownloadModel();
dm.tis = _tis;
dm.startDate = DateTime.Now;
dm.path = filePath;
if (cm.message is Message msgBase)
{
if (msgBase.media is MessageMediaDocument mediaDoc &&
mediaDoc.document is TL.Document doc)
{
dm._size = doc.size;
dm.name = doc.Filename;
}
}
dm.channelName = _ts.getChatName(Convert.ToInt64(idChannel));
_tis.addToDownloadList(dm);
await _ts.DownloadFileAndReturn(cm, file, model: dm);
file.Position = 0;
}

// Return file for inline viewing (no download header)
Response.Headers["Content-Disposition"] = $"inline; filename=\"{HttpUtility.UrlEncode(fileName)}\"";
return new FileStreamResult(file, mimeType)
{
EnableRangeProcessing = true
};
}

Expand Down
22 changes: 9 additions & 13 deletions TelegramDownloader/Data/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,10 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
{
if (!item.IsFile)
{
var result = await copyAllDirectoryFiles(dbName, item.Id, args.TargetData, args.TargetPath + item.Name + "/");
// Pass args.IsCopy to handle internal files correctly (delete originals when moving)
var result = await copyAllDirectoryFiles(dbName, item.Id, args.TargetData, args.TargetPath + item.Name + "/", args.IsCopy);
lista.Add(result.toFileManagerContentInCopy());

// Note: copyAllDirectoryFiles now handles deletion of the folder when IsCopy=false
}
else
{
Expand All @@ -539,7 +540,6 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
{
await _db.deleteEntry(dbName, item.Id);
}

}
await _db.addBytesToFolder(dbName, item.ParentId, item.Size);
}
Expand Down Expand Up @@ -573,12 +573,10 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
{
if (!item.IsFile)
{
var result = await copyAllDirectoryFiles(dbName, item.Id, targetData, targetPath + item.Name + "/");
// Pass isCopy to handle internal files correctly (delete originals when moving)
var result = await copyAllDirectoryFiles(dbName, item.Id, targetData, targetPath + item.Name + "/", isCopy);
lista.Add(result.toFileManagerContentInCopy());
if (!isCopy)
{
await _db.deleteEntry(dbName, item.Id);
}
// Note: copyAllDirectoryFiles now handles deletion of the folder when isCopy=false
}
else
{
Expand Down Expand Up @@ -626,11 +624,9 @@ private async Task<BsonFileManagerModel> copyAllDirectoryFiles(string dbName, st
}
else
{
await copyAllDirectoryFiles(dbName, file.Id, result.toFileManagerContent(), targetPath + file.Name + "/");
if (!isCopy)
{
await _db.deleteEntry(dbName, file.Id);
}
// Pass isCopy to recursive call to handle nested folders correctly
await copyAllDirectoryFiles(dbName, file.Id, result.toFileManagerContent(), targetPath + file.Name + "/", isCopy);
// Note: recursive call handles deletion when isCopy=false, no need to delete here
}
}
if (!isCopy)
Expand Down
8 changes: 5 additions & 3 deletions TelegramDownloader/Data/db/DbService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,12 @@ public async Task<BsonFileManagerModel> copyItem(string dbName, string sourceId,
result.Id = null;
result.ParentId = target.Id;
result.DateModified = DateTime.Now;
result.FilterId = target.FilterId + target.Id + "/";
result.FilterId = (target.FilterId ?? "") + target.Id + "/";
result.ParentId = target.Id;
result.FilterPath = target.FilterPath == "" ? "/" : target.FilterPath + target.Name + "/";
result.FilePath = isFile ? targetPath + result.Name : targetPath;
// Both empty string and "/" indicate root folder
var isRootTarget = string.IsNullOrEmpty(target.FilterPath) || target.FilterPath == "/";
result.FilterPath = isRootTarget ? "/" : target.FilterPath + target.Name + "/";
result.FilePath = isFile ? targetPath + result.Name : targetPath.TrimEnd('/');
await getDatabase(dbName).GetCollection<BsonFileManagerModel>(collectionName).InsertOneAsync(result);
return result;

Expand Down
11 changes: 11 additions & 0 deletions TelegramDownloader/Pages/FileManager.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
}
}

<DropdownDivider />
<DropdownItem @onclick="openDeleteChannelModal" Type="DropdownItemType.Button" Class="text-danger">
<i class="bi bi-trash"></i> Delete Database
</DropdownItem>
</DropdownMenu>
</Dropdown>
@if (webDavService.IsRunning)
Expand All @@ -71,13 +75,15 @@
<TelegramDownloader.Pages.Partials.impl.FileManagerImpl @ref="fileManagerImpl" id="@id"></TelegramDownloader.Pages.Partials.impl.FileManagerImpl>
<TelegramDownloader.Pages.Modals.ImportDataModal id="@id" @ref="ImportModal"></TelegramDownloader.Pages.Modals.ImportDataModal>
<TelegramDownloader.Pages.Modals.InfoModals.MediaUrlModal @ref="mediaUrlModal" title="WebDav URL" url="@webDavUrl"></TelegramDownloader.Pages.Modals.InfoModals.MediaUrlModal>
<TelegramDownloader.Pages.Modals.InfoModals.DeleteChannelModal @ref="deleteChannelModal" ChannelId="@id" ChannelName="@chatName"></TelegramDownloader.Pages.Modals.InfoModals.DeleteChannelModal>

@code {
private Modals.ImportDataModal ImportModal { get; set; }
private TelegramDownloader.Pages.Partials.impl.FileManagerImpl fileManagerImpl { get; set; } = default!;
[Parameter]
public string id { get; set; }
private MediaUrlModal mediaUrlModal { get; set; } = default!;
private DeleteChannelModal deleteChannelModal { get; set; } = default!;

private WebbDavService webDavService = GeneralConfigStatic.config.webDav.webDavService ?? new WebbDavService();
private String webDavUrl = "";
Expand Down Expand Up @@ -156,4 +162,9 @@
await InvokeAsync(StateHasChanged);
}
}

public async Task openDeleteChannelModal()
{
await deleteChannelModal.ShowAsync();
}
}
17 changes: 17 additions & 0 deletions TelegramDownloader/Pages/LocalFiles.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@page "/local-files"

<style>
.e-filemanager .e-splitter {
height: 75vh !important;
}

.e-filemanager {
height: 80vh !important;
}
</style>

<h3>
<i class="bi bi-folder2-open me-2"></i>Local File Manager
</h3>

<TelegramDownloader.Pages.Partials.impl.LocalFileManagerImpl id="local" isShared="true"></TelegramDownloader.Pages.Partials.impl.LocalFileManagerImpl>
Loading