Skip to content

Commit 8015bae

Browse files
authored
merge: Develop into main (#19)
* chore: add dropdown button to channel name * feat: deleting shared feat: refresh after import feat: remember tab * chore: improves * feat: improve import shared files and folders * fix: solve anonymous tab issue * chore: avoid check certificate * chore: avoid add bad files and folders to upload * chore: improve count files on upload * chore: avoid directories * chore: not contains no sincronized folders * feat: video first step * chore: web video player * feat: bump to dot net 8 * fix: fix docker port * Update README.md * Update buildrelease.yml Add .net library to compilation executable * feat: download pending * chore: update libraries * bugfix: fix get log path in native apps
1 parent 523631f commit 8015bae

15 files changed

Lines changed: 104 additions & 41 deletions

TelegramDownloader/Controllers/FileController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public async Task<IActionResult> Upload([FromForm] string path, IFormFile file,
208208
this.operation.RootFolder(Path.Combine(basePath, root));
209209
FileManagerResponse uploadResponse;
210210

211-
uploadResponse = operation.Upload(Path.Combine(basePath, root, path), lfile, action, null);
211+
uploadResponse = operation.Upload(Path.Combine(basePath, root, path), lfile, action, 0, null);
212212
if (uploadResponse.Error != null)
213213
{
214214
Response.Clear();

TelegramDownloader/Controllers/TempController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public async Task<IActionResult> Upload([FromForm] string path, IFormFile file,
220220
this.operation.RootFolder(Path.Combine(basePath, root, id.ToString()));
221221
FileManagerResponse uploadResponse;
222222

223-
uploadResponse = operation.Upload(Path.Combine(basePath, root, path), lfile, action, null);
223+
uploadResponse = operation.Upload(Path.Combine(basePath, root, path), lfile, action, 0, null);
224224
if (uploadResponse.Error != null)
225225
{
226226
Response.Clear();

TelegramDownloader/Data/FileService.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
using Syncfusion.EJ2.FileManager.PhysicalFileProvider;
1212
using Syncfusion.EJ2.Linq;
13+
using Syncfusion.EJ2.Notifications;
1314
using System.Dynamic;
1415
using System.IO.Compression;
1516
using System.Security.Cryptography;
@@ -706,7 +707,7 @@ public async Task downloadFile(string dbName, List<FileManagerDirectoryContent>
706707

707708
private async Task<MemoryStream> downloadFromTelegramAndReturn(string dbName, int messageId, string destPath, MemoryStream ms = null)
708709
{
709-
Message m = await _ts.getMessageFile(dbName, messageId);
710+
TL.Message m = await _ts.getMessageFile(dbName, messageId);
710711
ChatMessages cm = new ChatMessages();
711712
cm.message = m;
712713

@@ -750,6 +751,28 @@ private async Task downloadFromTelegram(string dbName, int messageId, string des
750751
_tis.addToPendingDownloadList(model);
751752
}
752753

754+
public async Task DownloadFileFromChat(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null)
755+
{
756+
if (model == null)
757+
model = new DownloadModel();
758+
model.name = fileName;
759+
if (message.message.media is MessageMediaDocument { document: Document document })
760+
{
761+
model._size = document.size;
762+
}
763+
if (message.user is Channel channel)
764+
{
765+
model.channelName = channel.Title;
766+
}
767+
model._transmitted = 0;
768+
model.channel = message.user;
769+
//model.channelName = message.user.;
770+
model.callbacks = new Callbacks();
771+
772+
model.callbacks.callback = async () => await _ts.DownloadFile(message,fileName, folder, model);
773+
_tis.addToPendingDownloadList(model);
774+
}
775+
753776
public async Task DownloadFileNow(string dbName, int messageId, string destPath, DownloadModel model)
754777
{
755778
TL.Message m = await _ts.getMessageFile(dbName, messageId);
@@ -1149,7 +1172,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
11491172
_logger.LogInformation($"Calculating MD5 of file {currentFilePath}");
11501173
model.MD5Hash = GetMd5HashFromFile(currentFilePath);
11511174
_logger.LogInformation($"Calculated MD5 of file {currentFilePath}: {model.MD5Hash}");
1152-
Message m = null;
1175+
TL.Message m = null;
11531176
long max = (long)MaxSize * (long)TelegramService.splitSizeGB;
11541177
if (fileInfo.Length > max)
11551178
{
@@ -1398,7 +1421,7 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
13981421

13991422
BsonFileManagerModel model = new BsonFileManagerModel();
14001423
model.Size = file.File.Size;
1401-
Message m = null;
1424+
TL.Message m = null;
14021425
if (file.File.Size > MaxSize)
14031426
{
14041427

TelegramDownloader/Data/IFileService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IFileService
1515
Task DeleteShared(string id, string collectionId);
1616
Task downloadFile(string dbName, List<FileManagerDirectoryContent> files, string targetPath, string? collectionId = null, string? channelId = null);
1717
Task downloadFile(string dbName, string path, List<string> files, string targetPath, string? collectionId = null, string? channelId = null);
18+
Task DownloadFileFromChat(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null);
1819
Task downloadFileToServer(string dbName, string path, string destPath);
1920
FileStream? ExistFileIntempFolder(string id);
2021
Task<MemoryStream> exportAllData(string dbName);

TelegramDownloader/Data/ITelegramService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface ITelegramService
1515
Task<InvitationInfo?> getInvitationHash(long id);
1616
Task joinChatInvitationHash(string? hash);
1717
Task<User> CallQrGenerator(Action<string> func, CancellationToken ct, bool logoutFirst = false);
18-
Task<string> DownloadFile(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null);
18+
Task<string> DownloadFile(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null, bool shouldAddToList = false);
1919
Task<Stream> DownloadFileAndReturn(ChatMessages message, Stream ms = null, string fileName = null, string folder = null, DownloadModel model = null);
2020
Task<List<ChatViewBase>> GetFouriteChannels(bool mustRefresh = true);
2121
Task AddFavouriteChannel(long id);

TelegramDownloader/Data/TelegramService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public async Task<Stream> DownloadFileAndReturn(ChatMessages message, Stream ms
432432
return null;
433433
}
434434

435-
public async Task<string> DownloadFile(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null)
435+
public async Task<string> DownloadFile(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null, bool shouldAddToList = false)
436436
{
437437
if (model == null)
438438
model = new DownloadModel();
@@ -447,7 +447,8 @@ public async Task<string> DownloadFile(ChatMessages message, string fileName = n
447447
var filename = fileName ?? document.Filename;
448448
filename ??= $"{document.id}.{document.mime_type[(document.mime_type.IndexOf('/') + 1)..]}";
449449
model.name = filename;
450-
_tis.addToDownloadList(model);
450+
if (shouldAddToList)
451+
_tis.addToDownloadList(model);
451452
Console.WriteLine("Downloading " + filename);
452453
// using var fileStream = File.Create(filename);
453454
using var dest = new FileStream($"{Path.Combine(folder != null ? folder : Path.Combine(Environment.CurrentDirectory, "local", "temp"), filename)}", FileMode.Create, FileAccess.Write);

TelegramDownloader/Pages/Downloads.razor

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@
3232
</div>
3333

3434
</div>
35-
<TelegramDownloader.Pages.Partials.DownloadsTable></TelegramDownloader.Pages.Partials.DownloadsTable>
35+
<Tabs>
36+
<Tab Title="Downloads">
37+
<Content>
38+
<TelegramDownloader.Pages.Partials.DownloadsTable isPending="false"></TelegramDownloader.Pages.Partials.DownloadsTable>
39+
</Content>
40+
</Tab>
41+
<Tab Title="Pending">
42+
<Content>
43+
<TelegramDownloader.Pages.Partials.DownloadsTable isPending="true"></TelegramDownloader.Pages.Partials.DownloadsTable>
44+
</Content>
45+
</Tab>
46+
</Tabs>
47+
3648
</Content>
3749
</Tab>
3850
<Tab Title="Uploads">

TelegramDownloader/Pages/LogList.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
private FilesAndCount getLogs(int pageNumber, int pageSize)
5858
{
5959
FilesAndCount fac = new FilesAndCount();
60-
List<string> totalLogs = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "logs")).ToList();
60+
List<string> totalLogs = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? AppDomain.CurrentDomain.BaseDirectory, "logs")).ToList();
6161
totalLogs.Reverse();
6262
fac.totalFiles = totalLogs.Count();
6363

TelegramDownloader/Pages/Modals/DownloadModal.razor

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
@inject ITelegramService ts
9+
@inject IFileService fs
910

1011
<div class="modal @ModalClass" tabindex="-1" role="dialog" style="display:@ModalDisplay">
1112
<div class="modal-dialog" role="document">
@@ -31,10 +32,10 @@
3132
</div>
3233
<div>
3334
<TelegramDownloader.Shared.Ddtree idTree="dmtree"
34-
@ref="ddtree"></TelegramDownloader.Shared.Ddtree>
35+
@ref="ddtree"></TelegramDownloader.Shared.Ddtree>
3536
</div>
36-
37-
37+
38+
3839

3940
<div class="form-floating mb-3">
4041
<InputText type="text" class="form-control" id="floatingInput" @bind-Value="model!.newName" />
@@ -100,13 +101,8 @@
100101

101102
private async void Submit()
102103
{
103-
ts.DownloadFile(mc, model?.newName == "" ? null : model.newName, ddtree.selectedNode == null ? null : ddtree.selectedNode.FirstOrDefault());
104+
fs.DownloadFileFromChat(mc, model?.newName == "" ? null : model.newName, ddtree.selectedNode == null ? null : ddtree.selectedNode.FirstOrDefault());
104105
Close();
105-
// Model.type = await ts.checkAuth(Model.value, Model.type == "phone");
106-
// Model.value = "";
107-
// StateHasChanged();
108-
// isLogin();
109-
// Logger.LogInformation("Id = {Id}", Model?.Id);
110106
}
111107
}
112108

TelegramDownloader/Pages/Partials/DownloadsTable.razor

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
@inject TransactionInfoService tis
66

77
<Grid @ref="grid"
8-
TItem="DownloadModel"
9-
Class="table table-hover table-bordered table-striped"
10-
DataProvider="UploadsDataProvider"
11-
AllowFiltering="false"
12-
AllowPaging="true"
13-
AllowSorting="false"
14-
Responsive="true">
8+
TItem="DownloadModel"
9+
Class="table table-hover table-bordered table-striped"
10+
DataProvider="DownloadsDataProvider"
11+
AllowFiltering="false"
12+
AllowPaging="true"
13+
AllowSorting="false"
14+
Responsive="true">
1515

1616
<GridColumn TItem="DownloadModel" HeaderText="ID" PropertyName="id" SortString="id" SortKeySelector="item => item.id" FilterTextboxWidth="50" HeaderTextAlignment="Alignment.Center" TextAlignment="Alignment.Center">
1717
@context.id
@@ -31,7 +31,7 @@
3131
@context._transmittedString of @context._sizeString
3232
</GridColumn>
3333
<GridColumn TItem="DownloadModel" HeaderText="Actions">
34-
@if (context.state == StateTask.Working)
34+
@if (context.state == StateTask.Working && !isPending)
3535
{
3636
<td><button class="btn btn-danger" @onclick="() => cancel(context)" data-bs-toggle="tooltip" data-bs-placement="top" title="Cancel task"><i class="bi bi-x"></i></button></td>
3737
}
@@ -40,7 +40,17 @@
4040
{
4141
<td>
4242
<div class="btn-group" role="group">
43-
<button class="btn btn-info" @onclick="() => retry(context)" data-bs-toggle="tooltip" data-bs-placement="top" title="retry task"><i class="bi bi-arrow-clockwise"></i></button>
43+
@if(!isPending) {
44+
<button class="btn btn-info" @onclick="() => retry(context)" data-bs-toggle="tooltip" data-bs-placement="top" title="retry task"><i class="bi bi-arrow-clockwise"></i></button>
45+
}
46+
<button class="btn btn-danger" @onclick="() => deleteDownload(context)" data-bs-toggle="tooltip" data-bs-placement="top" title="delete task"><i class="bi bi-trash"></i></button>
47+
</div>
48+
</td>
49+
}
50+
@if(isPending)
51+
{
52+
<td>
53+
<div class="btn-group" role="group">
4454
<button class="btn btn-danger" @onclick="() => deleteDownload(context)" data-bs-toggle="tooltip" data-bs-placement="top" title="delete task"><i class="bi bi-trash"></i></button>
4555
</div>
4656
</td>
@@ -50,6 +60,8 @@
5060
</Grid>
5161

5262
@code {
63+
[Parameter]
64+
public bool isPending { get; set; } = false;
5365
public static List<DownloadModel> ldm = new List<DownloadModel>();
5466
BlazorBootstrap.Grid<DownloadModel> grid = default!;
5567

@@ -59,10 +71,10 @@
5971
TransactionInfoService.EventChanged += eventChangedNew;
6072
}
6173

62-
private async Task<GridDataProviderResult<DownloadModel>> UploadsDataProvider(GridDataProviderRequest<DownloadModel> request)
74+
private async Task<GridDataProviderResult<DownloadModel>> DownloadsDataProvider(GridDataProviderRequest<DownloadModel> request)
6375
{
6476
await getDownloadModels(request.PageNumber - 1, request.PageSize, ldm.Count() == 0);
65-
int totalUploads = tis.getTotalDownloads();
77+
int totalUploads = tis.getTotalDownloads(isPending);
6678
return await Task.FromResult(new GridDataProviderResult<DownloadModel> { Data = ldm ?? new List<DownloadModel>(), TotalCount = totalUploads });//request.ApplyTo(uploads));
6779
}
6880

@@ -82,6 +94,10 @@
8294

8395
private async Task deleteDownload(DownloadModel um)
8496
{
97+
if (isPending) {
98+
tis.deletePendingDownloadInList(um);
99+
return;
100+
}
85101
tis.deleteDownloadInList(um);
86102
}
87103

@@ -100,7 +116,7 @@
100116

101117
private async Task getDownloadModels(int pageNumber, int pageSize, bool mustCallEnventHandler = false)
102118
{
103-
ldm = tis.GetDownloadModels(pageNumber, pageSize);
119+
ldm = tis.GetDownloadModels(pageNumber, pageSize, isPending);
104120
if (mustCallEnventHandler)
105121
checkNewEventsHandler();
106122
}

0 commit comments

Comments
 (0)