Skip to content

Commit 00c0e91

Browse files
committed
feat: add download grid from channels
chore: bump versions
1 parent 4290b18 commit 00c0e91

10 files changed

Lines changed: 195 additions & 12 deletions

File tree

TelegramDownloader/Data/ITelegramService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ public interface ITelegramService
2222
Task RemoveFavouriteChannel(long id);
2323
Task<List<ChatViewBase>> getAllChats();
2424
Task<List<ChatViewBase>> getAllSavedChats();
25-
Task<List<ChatMessages>> getAllMessages(long id);
25+
Task<List<ChatMessages>> getAllMessages(long id, Boolean onlyFiles = false);
2626
Task<List<ChatMessages>> getChatHistory(long id, int limit = 30, int addOffset = 0);
2727
string getChatName(long id);
2828
Task<Message> getMessageFile(string chatId, int idMessage);
2929
Task<string> getPhotoThumb(ChatBase chat);
30+
Task<string> downloadPhotoThumb(Photo thumb);
3031
Task logOff();
3132
Task sendVerificationCode(string vc);
3233
Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null, string caption = null);

TelegramDownloader/Data/TelegramService.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,46 @@ public async Task<Message> getMessageFile(string chatId, int idMessage)
317317
//return m;
318318
}
319319

320-
public async Task<List<ChatMessages>> getAllMessages(long id)
320+
public async Task<List<ChatMessages>> getAllMessages(long id, Boolean onlyFiles = false)
321+
{
322+
List<ChatMessages> cm = new List<ChatMessages>();
323+
InputPeer peer = chats.chats[id];
324+
for (int offset_id = 0; ;)
325+
{
326+
var messages = await client.Messages_GetHistory(peer, offset_id);
327+
if (messages.Messages.Length == 0) break;
328+
foreach (MessageBase msgBase in messages.Messages)
329+
{
330+
if (msgBase is Message msg)
331+
{
332+
ChatMessages cm2 = new ChatMessages();
333+
cm2.htmlMessage = client.EntitiesToHtml(msg.message, msg.entities);
334+
cm2.message = msg;
335+
336+
cm2.user = messages.UserOrChat(msg.From ?? msg.Peer);
337+
cm2.isDocument = false;
338+
if (msg.media is MessageMediaDocument { document: Document document })
339+
{
340+
cm2.isDocument = true;
341+
}
342+
if (onlyFiles)
343+
{
344+
if (cm2.isDocument)
345+
cm.Add(cm2);
346+
} else
347+
{
348+
cm.Add(cm2);
349+
}
350+
351+
352+
}
353+
}
354+
offset_id = messages.Messages[^1].ID;
355+
}
356+
return cm;
357+
}
358+
359+
public async Task<List<ChatMessages>> getAllFileMessages(long id)
321360
{
322361
List<ChatMessages> cm = new List<ChatMessages>();
323362
InputPeer peer = chats.chats[id];
@@ -395,6 +434,17 @@ public async Task<string> getPhotoThumb(ChatBase chat)
395434

396435
}
397436

437+
public async Task<string> downloadPhotoThumb(Photo thumb)
438+
{
439+
MemoryStream ms = new MemoryStream();
440+
if (await client.DownloadFileAsync(thumb, ms) != 0)
441+
{
442+
return $"data:image/jpeg;base64,{Convert.ToBase64String(ms.ToArray())}";
443+
};
444+
return "";
445+
446+
}
447+
398448
public async Task AddFavouriteChannel(long id)
399449
{
400450
if (!GeneralConfigStatic.config.FavouriteChannels.Contains(id))

TelegramDownloader/Pages/Config.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171

7272
</div>
7373

74-
7574
<div>
7675
<div class="d-flex flex-row mb-3">
7776
@if (TelegramService.isPremium)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
@page "/filegrid/{id}"
2+
3+
@using TL
4+
@using TelegramDownloader.Data;
5+
@using TelegramDownloader.Models;
6+
@using TelegramDownloader.Services;
7+
8+
@inject ITelegramService ts;
9+
@inject PreloadService PreloadService;
10+
11+
<h3>File Grid</h3>
12+
13+
@if (SelectedItems.Any())
14+
{
15+
<button class="btn btn-primary mt-3 download-btn" @onclick="GetSelectedItems">Download Selected</button>
16+
}
17+
18+
<Grid TItem="ChatMessages"
19+
Class="table table-hover table-bordered table-striped"
20+
DataProvider="ChatsDataProvider"
21+
AllowPaging="true"
22+
PageSize="25"
23+
AllowSelection="true"
24+
SelectionMode="GridSelectionMode.Multiple"
25+
@bind-SelectedItems="@SelectedItems"
26+
PageSizeSelectorVisible="true"
27+
PageSizeSelectorItems="@(new int[] { 25, 50, 100 })"
28+
Responsive="true">
29+
30+
<GridColumns>
31+
<GridColumn TItem="ChatMessages" HeaderText="Id">
32+
@context.message.id
33+
</GridColumn>
34+
<GridColumn TItem="ChatMessages" HeaderText="Name">
35+
@context.message.message
36+
</GridColumn>
37+
<GridColumn TItem="ChatMessages" HeaderText="Created">
38+
@context.message.Date.ToString("dd/MM/yyyy HH:mm:ss")
39+
</GridColumn>
40+
<GridColumn TItem="ChatMessages" HeaderText="Edited">
41+
@(context.message.edit_date.Year > 1900
42+
? context.message.edit_date.ToString("dd/MM/yyyy HH:mm:ss")
43+
: "")
44+
</GridColumn>
45+
<GridColumn TItem="ChatMessages" HeaderText="File Name">
46+
@if (context.message.media is MessageMediaDocument { document: Document document })
47+
{
48+
<span>@document.Filename</span>
49+
}
50+
</GridColumn>
51+
<GridColumn TItem="ChatMessages" HeaderText="Size">
52+
@if (context.message.media is MessageMediaDocument { document: Document document })
53+
{
54+
<span>@HelperService.SizeSuffix(document.size)</span>
55+
}
56+
</GridColumn>
57+
<GridColumn TItem="ChatMessages" HeaderText="Extension">
58+
@if (context.message.media is MessageMediaDocument { document: Document document })
59+
{
60+
<span>@document.mime_type</span>
61+
}
62+
</GridColumn>
63+
<GridColumn TItem="ChatMessages" HeaderText="Preview">
64+
@context.videoThumb
65+
@if (context.message.media is MessageMediaPhoto { photo: Photo photo })
66+
{
67+
<img src="@ts.downloadPhotoThumb(photo)" style="max-width:-webkit-fill-available;" />
68+
} else {
69+
<img src="@context.videoThumb" style="max-width:-webkit-fill-available;" />
70+
}
71+
</GridColumn>
72+
</GridColumns>
73+
</Grid>
74+
75+
<div class="mt-3">
76+
Selected Items Count: @SelectedItems.Count
77+
</div>
78+
79+
<TelegramDownloader.Pages.Modals.DowloadFromTelegram @ref="Modal"></TelegramDownloader.Pages.Modals.DowloadFromTelegram>
80+
81+
82+
83+
@code {
84+
[Parameter]
85+
public string id { get; set; }
86+
public List<ChatMessages> messages = default!;
87+
88+
private Modals.DowloadFromTelegram Modal { get; set; }
89+
private HashSet<ChatMessages> SelectedItems { get; set; } = new();
90+
91+
private async Task<GridDataProviderResult<ChatMessages>> ChatsDataProvider(GridDataProviderRequest<ChatMessages> request)
92+
{
93+
if (messages is null) {
94+
PreloadService.Show(SpinnerColor.Light, "Loading data...");
95+
messages = await ts.getAllMessages(Convert.ToInt64(id), true);
96+
PreloadService.Hide();
97+
}
98+
99+
return await Task.FromResult(request.ApplyTo(messages));
100+
}
101+
102+
private void GetSelectedItems()
103+
{
104+
Modal.chatMessages = SelectedItems.ToList();
105+
Modal.isDownloadingChatMessages = true;
106+
Modal.Open();
107+
// Aquí puedes manejar los elementos seleccionados
108+
// Console.WriteLine($"Elementos seleccionados: {SelectedItems.Count}");
109+
// foreach (var item in SelectedItems)
110+
// {
111+
// Console.WriteLine($"Id: {item.message.id}, Name: {item.message.message}");
112+
// }
113+
}
114+
}

TelegramDownloader/Pages/Modals/DowloadFromTelegram.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
[Parameter]
4646
public BsonSharedInfoModel bsi { get; set; }
4747
public string filePath { get; set; }
48+
4849
public List<FileManagerDirectoryContent> fileList { get; set; }
50+
public List<ChatMessages> chatMessages { get; set; }
51+
public bool isDownloadingChatMessages { get; set; } = false;
4952

5053
public string filename = "";
5154
public string size = "";
@@ -79,6 +82,11 @@
7982

8083
private async Task Submit()
8184
{
85+
if (isDownloadingChatMessages)
86+
{
87+
chatMessages.ForEach(message => fs.DownloadFileFromChat(message, null, ddtree.selectedNode == null ? null : ddtree.selectedNode.FirstOrDefault(), null));
88+
return;
89+
}
8290
// ts.
8391
if (isShare)
8492
fs.downloadFile(DbService.SHARED_DB_NAME, fileList.ToList(), ddtree.selectedNode == null ? null : ddtree.selectedNode.FirstOrDefault(), bsi.CollectionId, bsi.ChannelId);

TelegramDownloader/Pages/_Layout.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<script src="_framework/blazor.server.js"></script>
4646
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
4747
<!-- Add chart.js reference if chart components are used in your application. -->
48-
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.0.1/chart.umd.js" integrity="sha512-gQhCDsnnnUfaRzD8k1L5llCCV6O9HN09zClIzzeJ8OJ9MpGmIlCxm+pdCkqTwqJ4JcjbojFr79rl2F1mzcoLMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
48+
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.js" integrity="sha512-gQhCDsnnnUfaRzD8k1L5llCCV6O9HN09zClIzzeJ8OJ9MpGmIlCxm+pdCkqTwqJ4JcjbojFr79rl2F1mzcoLMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
4949
<!-- Add chartjs-plugin-datalabels.min.js reference if chart components with data label feature is used in your application. -->
5050
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.2.0/chartjs-plugin-datalabels.min.js" integrity="sha512-JPcRR8yFa8mmCsfrw4TNte1ZvF1e3+1SdGMslZvmrzDYxS69J7J49vkFL8u6u8PlPJK+H3voElBtUCzaXj+6ig==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
5151
<!-- Add sortable.js reference if SortableList component is used in your application. -->

TelegramDownloader/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
var builder = WebApplication.CreateBuilder(args);
36-
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MzY0NjIwOUAzMjM4MmUzMDJlMzBZdngxNkEzSjRTQTczaDdlWkxEd1BIeUovNjh1eHByNEg5SkRVZ1lmWHc4PQ==");
36+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MzgzMTc5MUAzMjM5MmUzMDJlMzAzYjMyMzkzYmw1ZDhSMmlTeTVTMFl0Ky9YaHBpZlRhd0NZS2RuQlVvenpnRVduRHFtZkE9");
3737
builder.Services.AddSyncfusionBlazor();
3838

3939
if (!Directory.Exists(FileService.IMGDIR))

TelegramDownloader/Shared/NavMenu.razor

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
</div>
7777
</div>
7878
<div class="col-2" style="position: relative; padding-top: 2%; padding-left: 0;">
79+
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/filegrid/{cb.chat.ID}"))">
80+
<span style="color:white" class="bi bi-table"></span>
81+
</button>
7982
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/fm/{cb.chat.ID}"))">
8083
<span style="color:white" class="bi bi-folder"></span>
8184
</button>
@@ -109,6 +112,9 @@
109112
</div>
110113
</div>
111114
<div class="col-2" style="position: relative; padding-top: 2%; padding-left: 0;">
115+
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/filegrid/{cb.chat.ID}"))">
116+
<span style="color:white" class="bi bi-table"></span>
117+
</button>
112118
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/fm/{cb.chat.ID}"))">
113119
<span style="color:white" class="bi bi-folder"></span>
114120
</button>
@@ -191,7 +197,9 @@
191197
</div>
192198
</div>
193199
<div class="col-2" style="position: relative; padding-top: 2%; padding-left: 0;">
194-
200+
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/filegrid/{cb.chat.ID}"))">
201+
<span style="color:white" class="bi bi-table"></span>
202+
</button>
195203
<button class="btn" type="button" style="padding:0" data-bs-toggle="dropdown" aria-expanded="false" @onclick="@(async () => await goTo($"/fm/{cb.chat.ID}"))">
196204
<span style="color:white" class="bi bi-folder"></span>
197205
</button>

TelegramDownloader/TelegramDownloader.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<ItemGroup>
1616
<PackageReference Include="Blazor.Bootstrap" Version="3.3.1" />
1717
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
18-
<PackageReference Include="MongoDB.Driver" Version="3.1.0" />
18+
<PackageReference Include="MongoDB.Driver" Version="3.3.0" />
1919
<PackageReference Include="QRCoder" Version="1.6.0" />
20-
<PackageReference Include="Syncfusion.Blazor" Version="28.2.4" />
21-
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
22-
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="28.2.4" />
23-
<PackageReference Include="System.IO.Hashing" Version="9.0.1" />
24-
<PackageReference Include="WTelegramClient" Version="4.2.8" />
20+
<PackageReference Include="Syncfusion.Blazor" Version="29.1.39" />
21+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.2" />
22+
<PackageReference Include="Syncfusion.EJ2.AspNet.Core" Version="29.1.39" />
23+
<PackageReference Include="System.IO.Hashing" Version="9.0.4" />
24+
<PackageReference Include="WTelegramClient" Version="4.3.3" />
2525
</ItemGroup>
2626

2727
<ItemGroup>

TelegramDownloader/wwwroot/css/site.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ a, .btn-link {
103103
padding-bottom: 5%;
104104
}
105105

106+
.download-btn {
107+
margin-bottom: 2% !important;
108+
}

0 commit comments

Comments
 (0)