Skip to content

Commit 754f51c

Browse files
authored
Merge pull request #47 from mateof/develop
internal: Develop to main
2 parents 3718bc5 + 05eca8f commit 754f51c

15 files changed

Lines changed: 2075 additions & 34 deletions

TelegramDownloader/Controllers/FileController.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,50 @@ public async Task<IActionResult> GetFile(string id, string? idChannel, string? i
270270
{
271271
FileDownloadName = fileName,
272272
EnableRangeProcessing = true
273-
273+
274+
};
275+
}
276+
277+
/// <summary>
278+
/// View file inline (for PDF viewer, etc.) - doesn't trigger download
279+
/// </summary>
280+
[Route("ViewFile/{id}")]
281+
public async Task<IActionResult> ViewFile(string id, string? idChannel, string? idFile)
282+
{
283+
var fileName = id;
284+
var mimeType = FileService.getMimeType(id.Split(".").Last());
285+
var file = _fs.ExistFileIntempFolder($"{idChannel}-{idFile}-{id}");
286+
if (file == null)
287+
{
288+
TL.Message idM = await _ts.getMessageFile(idChannel, Convert.ToInt32(idFile));
289+
ChatMessages cm = new ChatMessages();
290+
cm.message = idM;
291+
string filePath = System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{idFile}-{id}");
292+
file = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
293+
DownloadModel dm = new DownloadModel();
294+
dm.tis = _tis;
295+
dm.startDate = DateTime.Now;
296+
dm.path = filePath;
297+
if (cm.message is Message msgBase)
298+
{
299+
if (msgBase.media is MessageMediaDocument mediaDoc &&
300+
mediaDoc.document is TL.Document doc)
301+
{
302+
dm._size = doc.size;
303+
dm.name = doc.Filename;
304+
}
305+
}
306+
dm.channelName = _ts.getChatName(Convert.ToInt64(idChannel));
307+
_tis.addToDownloadList(dm);
308+
await _ts.DownloadFileAndReturn(cm, file, model: dm);
309+
file.Position = 0;
310+
}
311+
312+
// Return file for inline viewing (no download header)
313+
Response.Headers["Content-Disposition"] = $"inline; filename=\"{HttpUtility.UrlEncode(fileName)}\"";
314+
return new FileStreamResult(file, mimeType)
315+
{
316+
EnableRangeProcessing = true
274317
};
275318
}
276319

TelegramDownloader/Data/FileService.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,10 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
527527
{
528528
if (!item.IsFile)
529529
{
530-
var result = await copyAllDirectoryFiles(dbName, item.Id, args.TargetData, args.TargetPath + item.Name + "/");
530+
// Pass args.IsCopy to handle internal files correctly (delete originals when moving)
531+
var result = await copyAllDirectoryFiles(dbName, item.Id, args.TargetData, args.TargetPath + item.Name + "/", args.IsCopy);
531532
lista.Add(result.toFileManagerContentInCopy());
532-
533+
// Note: copyAllDirectoryFiles now handles deletion of the folder when IsCopy=false
533534
}
534535
else
535536
{
@@ -539,7 +540,6 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
539540
{
540541
await _db.deleteEntry(dbName, item.Id);
541542
}
542-
543543
}
544544
await _db.addBytesToFolder(dbName, item.ParentId, item.Size);
545545
}
@@ -573,12 +573,10 @@ public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManage
573573
{
574574
if (!item.IsFile)
575575
{
576-
var result = await copyAllDirectoryFiles(dbName, item.Id, targetData, targetPath + item.Name + "/");
576+
// Pass isCopy to handle internal files correctly (delete originals when moving)
577+
var result = await copyAllDirectoryFiles(dbName, item.Id, targetData, targetPath + item.Name + "/", isCopy);
577578
lista.Add(result.toFileManagerContentInCopy());
578-
if (!isCopy)
579-
{
580-
await _db.deleteEntry(dbName, item.Id);
581-
}
579+
// Note: copyAllDirectoryFiles now handles deletion of the folder when isCopy=false
582580
}
583581
else
584582
{
@@ -626,11 +624,9 @@ private async Task<BsonFileManagerModel> copyAllDirectoryFiles(string dbName, st
626624
}
627625
else
628626
{
629-
await copyAllDirectoryFiles(dbName, file.Id, result.toFileManagerContent(), targetPath + file.Name + "/");
630-
if (!isCopy)
631-
{
632-
await _db.deleteEntry(dbName, file.Id);
633-
}
627+
// Pass isCopy to recursive call to handle nested folders correctly
628+
await copyAllDirectoryFiles(dbName, file.Id, result.toFileManagerContent(), targetPath + file.Name + "/", isCopy);
629+
// Note: recursive call handles deletion when isCopy=false, no need to delete here
634630
}
635631
}
636632
if (!isCopy)

TelegramDownloader/Data/db/DbService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,12 @@ public async Task<BsonFileManagerModel> copyItem(string dbName, string sourceId,
489489
result.Id = null;
490490
result.ParentId = target.Id;
491491
result.DateModified = DateTime.Now;
492-
result.FilterId = target.FilterId + target.Id + "/";
492+
result.FilterId = (target.FilterId ?? "") + target.Id + "/";
493493
result.ParentId = target.Id;
494-
result.FilterPath = target.FilterPath == "" ? "/" : target.FilterPath + target.Name + "/";
495-
result.FilePath = isFile ? targetPath + result.Name : targetPath;
494+
// Both empty string and "/" indicate root folder
495+
var isRootTarget = string.IsNullOrEmpty(target.FilterPath) || target.FilterPath == "/";
496+
result.FilterPath = isRootTarget ? "/" : target.FilterPath + target.Name + "/";
497+
result.FilePath = isFile ? targetPath + result.Name : targetPath.TrimEnd('/');
496498
await getDatabase(dbName).GetCollection<BsonFileManagerModel>(collectionName).InsertOneAsync(result);
497499
return result;
498500

TelegramDownloader/Pages/FileManager.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
}
5151
}
5252

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

7580
@code {
7681
private Modals.ImportDataModal ImportModal { get; set; }
7782
private TelegramDownloader.Pages.Partials.impl.FileManagerImpl fileManagerImpl { get; set; } = default!;
7883
[Parameter]
7984
public string id { get; set; }
8085
private MediaUrlModal mediaUrlModal { get; set; } = default!;
86+
private DeleteChannelModal deleteChannelModal { get; set; } = default!;
8187

8288
private WebbDavService webDavService = GeneralConfigStatic.config.webDav.webDavService ?? new WebbDavService();
8389
private String webDavUrl = "";
@@ -156,4 +162,9 @@
156162
await InvokeAsync(StateHasChanged);
157163
}
158164
}
165+
166+
public async Task openDeleteChannelModal()
167+
{
168+
await deleteChannelModal.ShowAsync();
169+
}
159170
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@page "/local-files"
2+
3+
<style>
4+
.e-filemanager .e-splitter {
5+
height: 75vh !important;
6+
}
7+
8+
.e-filemanager {
9+
height: 80vh !important;
10+
}
11+
</style>
12+
13+
<h3>
14+
<i class="bi bi-folder2-open me-2"></i>Local File Manager
15+
</h3>
16+
17+
<TelegramDownloader.Pages.Partials.impl.LocalFileManagerImpl id="local" isShared="true"></TelegramDownloader.Pages.Partials.impl.LocalFileManagerImpl>

0 commit comments

Comments
 (0)