Skip to content

Commit 5769557

Browse files
authored
release: merge from Develop (#23)
* 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 * Merge: Main into develop (#20) * Develop (#18) * 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 * 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 * Overwrite only new files when upload * fix: fix date check * feat: add show all messages feat: change md5 to xxhash feat: add more info in upload table feat: allow disable hash calculator by config refactor: chatMessage
1 parent 8015bae commit 5769557

13 files changed

Lines changed: 350 additions & 100 deletions

TelegramDownloader/Data/FileService.cs

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
using Syncfusion.EJ2.Linq;
1313
using Syncfusion.EJ2.Notifications;
1414
using System.Dynamic;
15+
using System.IO;
1516
using System.IO.Compression;
17+
using System.IO.Hashing;
1618
using System.Security.Cryptography;
1719
using System.Text.Json;
1820
using System.Xml.Linq;
@@ -382,6 +384,67 @@ public async Task<List<BsonFileManagerModel>> ShareFile(string dbName, string bs
382384
return await GetFilesPath(dbName, args.Path);
383385
}
384386

387+
private async Task itemDeleteAsync(string dbName, string filterPath, string name, string parentId, string path)
388+
{
389+
390+
BsonFileManagerModel entry = await _db.getEntry(dbName, filterPath, name);
391+
if (entry == null)
392+
throw new Exception($"File {System.IO.Path.Combine(filterPath, name)} not found");
393+
if (!entry.IsFile)
394+
{
395+
List<BsonFileManagerModel> allChilds = await _db.getAllChildFilesInDirectory(dbName, filterPath + name + "/");
396+
foreach (BsonFileManagerModel child in allChilds)
397+
{
398+
await _db.deleteEntry(dbName, child.Id);
399+
if (child.IsFile)
400+
{
401+
if (child.isSplit)
402+
{
403+
foreach (int id in child.ListMessageId)
404+
{
405+
if (!await _db.existItemByTelegramId(dbName, id))
406+
await _ts.deleteFile(dbName, id);
407+
}
408+
}
409+
else
410+
{
411+
if (!await _db.existItemByTelegramId(dbName, (int)child.MessageId))
412+
await _ts.deleteFile(dbName, (int)child.MessageId);
413+
}
414+
}
415+
416+
//if (item.IsFile)
417+
// await _db.subBytesToFolder(dbName, item.ParentId, item.Size);
418+
}
419+
await _db.deleteEntry(dbName, entry.Id);
420+
// await _db.subBytesToFolder(dbName, entry.ParentId, entry.Size);
421+
}
422+
423+
if (entry.IsFile)
424+
{
425+
await _db.deleteEntry(dbName, entry.Id);
426+
if (entry.isSplit)
427+
{
428+
foreach (int id in entry.ListMessageId)
429+
{
430+
if (!await _db.existItemByTelegramId(dbName, id))
431+
await _ts.deleteFile(dbName, id);
432+
}
433+
}
434+
else
435+
{
436+
if (!await _db.existItemByTelegramId(dbName, (int)entry.MessageId))
437+
await _ts.deleteFile(dbName, (int)entry.MessageId);
438+
}
439+
}
440+
441+
442+
443+
await _db.subBytesToFolder(dbName, entry.ParentId, entry.Size);
444+
445+
await _db.checkAndSetDirectoryHasChild(dbName, parentId);
446+
}
447+
385448
public async Task oneItemDeleteAsync(string dbName, Syncfusion.Blazor.FileManager.FileManagerDirectoryContent File)
386449
{
387450

@@ -1163,15 +1226,19 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
11631226
continue;
11641227
}
11651228
idt.currentUpload++;
1166-
if (file.Size == 0 || (await _db.getFileByPath(dbName, System.IO.Path.Combine(currentPath, file.Name))) != null)
1229+
BsonFileManagerModel savedFile = await _db.getFileByPath(dbName, System.IO.Path.Combine(currentPath, file.Name));
1230+
if (file.Size == 0 || (savedFile != null && savedFile.DateModified > file.DateModified))
11671231
{
11681232
if (idt != null) idt.AddOne(file.Size);
11691233
continue;
11701234
};
11711235
model.Size = fileInfo.Length;
1172-
_logger.LogInformation($"Calculating MD5 of file {currentFilePath}");
1173-
model.MD5Hash = GetMd5HashFromFile(currentFilePath);
1174-
_logger.LogInformation($"Calculated MD5 of file {currentFilePath}: {model.MD5Hash}");
1236+
if (GeneralConfigStatic.config.CheckHash)
1237+
{
1238+
_logger.LogInformation($"Calculating HASH of file {currentFilePath}");
1239+
model.XXHash = ComputeXXHash64(currentFilePath);
1240+
_logger.LogInformation($"Calculated HASH of file {currentFilePath}: {model.XXHash}");
1241+
}
11751242
TL.Message m = null;
11761243
long max = (long)MaxSize * (long)TelegramService.splitSizeGB;
11771244
if (fileInfo.Length > max)
@@ -1187,6 +1254,8 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
11871254
int attempts = 3;
11881255
int waitForNextAttempt = 1000;
11891256
UploadModel um = new UploadModel();
1257+
um.path = currentFilePath;
1258+
um.chatName = _ts.getChatName(Convert.ToInt64(dbName));
11901259
// add upload to task list
11911260
idt.addUpload(um);
11921261
um.thread = Thread.CurrentThread;
@@ -1234,6 +1303,8 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
12341303
int attempts = 3;
12351304
int waitForNextAttempt = 60000;
12361305
UploadModel um = new UploadModel();
1306+
um.path = currentFilePath;
1307+
um.chatName = _ts.getChatName(Convert.ToInt64(dbName));
12371308
// add upload to task list
12381309
idt.addUpload(um);
12391310
while (attempts != 0 || um.state == StateTask.Canceled)
@@ -1294,7 +1365,11 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
12941365

12951366
model.MessageId = m.ID;
12961367
}
1297-
1368+
// delete previous file, when the new modified date file is newest
1369+
if (savedFile != null)
1370+
{
1371+
await itemDeleteAsync(dbName, savedFile.FilterPath, savedFile.Name, savedFile.ParentId, savedFile.FilePath);
1372+
}
12981373
}
12991374
BsonFileManagerModel parent = await _db.getParentDirectoryByPath(dbName, currentPath);
13001375
model.Name = file.IsFile ? fileInfo.Name : file.Name;
@@ -1700,6 +1775,26 @@ private string GetMd5HashFromFile(string filePath)
17001775
}
17011776
}
17021777

1778+
private string ComputeXXHash64(string filePath)
1779+
{
1780+
XxHashModel _xxHash = new XxHashModel();
1781+
_xxHash.path = filePath;
1782+
var hashAlgorithm = new XxHash64();
1783+
var buffer = new Span<byte>(new byte[512]);
1784+
using (Stream entryStream = File.OpenRead(filePath))
1785+
{
1786+
_tis.addToUploadList(_xxHash);
1787+
_xxHash.Init(entryStream.Length, Path.GetFileName(filePath));
1788+
while (entryStream.Read(buffer) > 0)
1789+
{
1790+
hashAlgorithm.Append(buffer);
1791+
}
1792+
}
1793+
1794+
return BitConverter.ToString(hashAlgorithm.GetHashAndReset()).Replace("-", string.Empty);
1795+
1796+
}
1797+
17031798
private async Task<List<Stream>> splitFileAsync(Stream s, int size)
17041799
{
17051800
List<Stream> ls = new List<Stream>();

TelegramDownloader/Data/ITelegramService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ 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);
2526
Task<List<ChatMessages>> getChatHistory(long id, int limit = 30, int addOffset = 0);
2627
string getChatName(long id);
2728
Task<Message> getMessageFile(string chatId, int idMessage);

TelegramDownloader/Data/TelegramService.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,37 @@ public async Task<Message> getMessageFile(string chatId, int idMessage)
316316
//return m;
317317
}
318318

319+
public async Task<List<ChatMessages>> getAllMessages(long id)
320+
{
321+
List<ChatMessages> cm = new List<ChatMessages>();
322+
InputPeer peer = chats.chats[id];
323+
for (int offset_id = 0; ;)
324+
{
325+
var messages = await client.Messages_GetHistory(peer, offset_id);
326+
if (messages.Messages.Length == 0) break;
327+
foreach (MessageBase msgBase in messages.Messages)
328+
{
329+
if (msgBase is Message msg)
330+
{
331+
ChatMessages cm2 = new ChatMessages();
332+
cm2.htmlMessage = client.EntitiesToHtml(msg.message, msg.entities);
333+
cm2.message = msg;
334+
335+
cm2.user = messages.UserOrChat(msg.From ?? msg.Peer);
336+
cm2.isDocument = false;
337+
if (msg.media is MessageMediaDocument { document: Document document })
338+
{
339+
cm2.isDocument = true;
340+
}
341+
342+
cm.Add(cm2);
343+
}
344+
}
345+
offset_id = messages.Messages[^1].ID;
346+
}
347+
return cm;
348+
}
349+
319350
public async Task<List<ChatMessages>> getChatHistory(long id, int limit = 30, int addOffset = 0)
320351
{
321352
List<ChatMessages> cm = new List<ChatMessages>();
@@ -478,5 +509,6 @@ public async Task<string> DownloadFile(ChatMessages message, string fileName = n
478509
}
479510
return null;
480511
}
512+
481513
}
482514
}

TelegramDownloader/Models/DownloadModel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,14 @@ public class UploadModel
199199
public StateTask state { get; set; } = StateTask.Working;
200200
public ChatMessages m { get; set; }
201201
public string name { get; set; }
202+
public string path { get; set; }
202203

203204
public long _size { get; set; }
204205
public long _transmitted { get; set; }
205206

206207
public string _sizeString { get; set; }
207208
public string _transmittedString { get; set; }
208-
209+
public string chatName { get; set; }
209210
public IPeerInfo channel { get; set; }
210211
public int progress { get; set; }
211212
public Thread thread { get; set; }
@@ -280,21 +281,29 @@ public Md5Model() : base()
280281
{
281282
action = "MD5 Calc";
282283
}
283-
public void Init(long size, string filename)
284+
public virtual void Init(long size, string filename)
284285
{
285286
_sizeString = HelperService.SizeSuffix(size);
286287
name = filename;
287288
base.InvokeEvent(new UploadEventArgs());
288289
}
289290

290-
public void Finish()
291+
public virtual void Finish()
291292
{
292293
state = StateTask.Completed;
293294
progress = 100;
294295
base.InvokeEvent(new UploadEventArgs());
295296
}
296297
}
297298

299+
public class XxHashModel : Md5Model
300+
{
301+
public XxHashModel() : base()
302+
{
303+
action = "XxHash Calc";
304+
}
305+
}
306+
298307
public class NewDownloadModel
299308
{
300309
public string newName { get; set; }

TelegramDownloader/Models/FileModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class BsonFileManagerModel
4747
public List<int>? ListMessageId { get; set; }
4848
public bool isEncrypted { get; set; } = false;
4949
public string MD5Hash { get; set; }
50+
public string XXHash { get; set; }
5051

5152
public BsonFileManagerModel()
5253
{

TelegramDownloader/Models/GeneralConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class GeneralConfig
7171
public int TimeSleepBetweenTransactions { get; set; } = 2000;
7272
public int SplitSize { get; set; } = 0;
7373
public int MaxSimultaneousDownloads = 1;
74+
public bool CheckHash { get; set; } = false;
7475
public bool ShouldShowLogInTerminal { get; set; } = false;
7576
public List<long> FavouriteChannels { get; set; } = new List<long>();
7677

TelegramDownloader/Pages/Config.razor

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
</div>
3535
</div>
3636

37+
<div>
38+
<div class="form-check form-switch">
39+
<InputCheckbox @bind-Value="Model!.CheckHash" class="form-check-input" type="checkbox" id="CheckHash" />
40+
<label class="form-check-label" for="ShouldShowNotifications">Check Hash</label>
41+
</div>
42+
43+
44+
</div>
45+
3746
<div>
3847
<div class="form-check form-switch">
3948
<InputCheckbox @bind-Value="Model!.ShouldNotify" class="form-check-input" type="checkbox" id="ShouldShowNotifications" />

0 commit comments

Comments
 (0)