Skip to content

Commit 10ef101

Browse files
committed
fix: multi download problem
1 parent ce5c42e commit 10ef101

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

TelegramDownloader/Controllers/FileController.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using System.Net;
1919
using System.Net.Http.Headers;
20+
using System.Runtime.CompilerServices;
2021
using System.Runtime.Serialization.Formatters.Binary;
2122
using System.Web;
2223
using System.Xml.Linq;
@@ -278,9 +279,13 @@ public async Task<IActionResult> GetFileByTfmId(string id, [FromQuery] string id
278279
return new ObjectResult("") { StatusCode = (int)HttpStatusCode.NotFound };
279280
}
280281
var file = _fs.ExistFileIntempFolder($"{idChannel}-{(dbFile.MessageId != null ? dbFile.MessageId.ToString() : dbFile.Id)}-{id}");
281-
if (file == null)
282+
dbFile.Name = $"{idChannel}-{(dbFile.MessageId != null ? dbFile.MessageId.ToString() : dbFile.Id)}-{id}";
283+
String path = Path.Combine(FileService.TEMPDIR, "_temp");
284+
String filePath = Path.Combine(path, dbFile.Name);
285+
if (file == null && !_tis.isFileDownloaded(path))
282286
{
283-
_fs.downloadFile(idChannel, new List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> { dbFile.toFileManagerContent() }, System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{(dbFile.MessageId != null ? dbFile.MessageId.ToString() : dbFile.Id)}-{id}"));
287+
288+
await _fs.downloadFile(idChannel, new List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> { dbFile.toFileManagerContent() }, path);
284289
//TL.Message idM = await _ts.getMessageFile(idChannel, Convert.ToInt32(dbFile.MessageId));
285290
//ChatMessages cm = new ChatMessages();
286291
//cm.message = idM;

TelegramDownloader/Data/FileService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,12 @@ private async Task downloadSplitFiles(FileManagerDirectoryContent itemFile, Bson
763763
List<string> splitPaths = new List<string>();
764764
foreach (int messageId in file.ListMessageId)
765765
{
766-
string filePathPart = System.IO.Path.Combine(currentFilePath, $"({i})" + itemFile.Name);
767-
await downloadFromTelegram(dbName, messageId, filePathPart, file, true);
766+
string filePathPart = Path.Combine(currentFilePath, $"({i})" + itemFile.Name);
767+
await downloadFromTelegram(dbName, messageId, filePathPart, file, true, Path.Combine(currentFilePath, itemFile.Name));
768768
splitPaths.Add(filePathPart);
769769
i++;
770770
}
771-
await mergeFileStreamAsync(splitPaths, System.IO.Path.Combine(currentFilePath, itemFile.Name));
771+
await mergeFileStreamAsync(splitPaths, Path.Combine(currentFilePath, itemFile.Name));
772772
foreach (string filePath in splitPaths)
773773
{
774774
File.Delete(filePath);
@@ -800,9 +800,10 @@ public static void functionCalll(string dbName, int messageId, string destPath)
800800
{
801801

802802
}
803-
private async Task downloadFromTelegram(string dbName, int messageId, string destPath, BsonFileManagerModel file = null, bool shouldWait = false)
803+
private async Task downloadFromTelegram(string dbName, int messageId, string destPath, BsonFileManagerModel file = null, bool shouldWait = false, string path = null)
804804
{
805805
DownloadModel model = new DownloadModel();
806+
model.path = path ?? destPath;
806807
model.tis = _tis;
807808
if (file != null)
808809
{

TelegramDownloader/Models/DownloadModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public class DownloadModel
133133
public string idTask { get; set; }
134134
public ChatMessages m { get; set; }
135135
public string name { get; set; }
136+
public string path { get; set; }
136137
public Callbacks callbacks { get; set; }
137138

138139
public long _size { get; set; }

TelegramDownloader/Services/TransactionInfoService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public bool isWorking()
4747
return true;
4848
}
4949

50+
public bool isFileDownloaded(String path)
51+
{
52+
return downloadModels.Any(x => x.path == path);
53+
}
54+
5055
public bool isUploading()
5156
{
5257
return uploadModels.Where(x => x.state == StateTask.Working).Count() > 0;

0 commit comments

Comments
 (0)