Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8995608
chore: add dropdown button to channel name
mateof Nov 18, 2024
fc098ca
Merge remote-tracking branch 'GitHub/main' into develop
mateof Nov 18, 2024
8b4ecda
feat: deleting shared
mateof Nov 18, 2024
35a32a6
chore: improves
mateof Nov 19, 2024
44951f3
feat: improve import shared files and folders
mateof Nov 20, 2024
0e5ed54
fix: solve anonymous tab issue
mateof Nov 20, 2024
2075a6a
chore: avoid check certificate
mateof Nov 21, 2024
067c0c8
Merge remote-tracking branch 'GitHub/main' into develop
mateof Nov 25, 2024
54cb556
Merge pull request #14 from mateof/main
mateof Nov 25, 2024
19eac33
chore: avoid add bad files and folders to upload
mateof Nov 25, 2024
909bf1e
chore: improve count files on upload
mateof Nov 25, 2024
0367368
chore: avoid directories
mateof Nov 25, 2024
5edd79f
chore: not contains no sincronized folders
mateof Nov 25, 2024
9411372
feat: video first step
mateof Nov 25, 2024
78a4e20
chore: web video player
mateof Nov 26, 2024
f60078b
feat: bump to dot net 8
mateof Dec 1, 2024
6e69678
Merge pull request #15 from mateof/feature/update_to_dot_net_8
mateof Dec 1, 2024
8ee3095
fix: fix docker port
mateof Dec 1, 2024
17d177b
Update README.md
mateof Dec 1, 2024
7f01ebe
Merge pull request #17 from mateof/main
mateof Dec 1, 2024
6c8bb01
Update buildrelease.yml
mateof Dec 1, 2024
6f2f070
feat: download pending
mateof Dec 6, 2024
9d5fe1d
chore: update libraries
mateof Dec 27, 2024
29b4550
bugfix: fix get log path in native apps
mateof Dec 30, 2024
c5728ec
Merge: Main into develop (#20)
mateof Dec 30, 2024
9a181a3
Overwrite only new files when upload
mateof Jan 23, 2025
79a1bbf
Merge pull request #21 from mateof/feature/overwrite-only-new-files
mateof Jan 23, 2025
6406c6a
fix: fix date check
mateof Jan 23, 2025
29e3846
feat: add show all messages
mateof Feb 6, 2025
8c73301
Merge remote-tracking branch 'GitHub/main' into develop
mateof Feb 6, 2025
7ce55c1
feat: add path for upload files in tooltip
mateof Feb 13, 2025
a1e0bb9
feat: add spinner
mateof Feb 13, 2025
bb1fa1f
Merge remote-tracking branch 'GitHub/main' into develop
mateof Feb 14, 2025
3120577
feat: add mac os arm version
mateof Feb 14, 2025
ef6270f
Merge pull request #25 from mateof/internal/publish-macos-arm
mateof Feb 14, 2025
7340420
Merge remote-tracking branch 'GitHub/main' into develop
mateof Feb 14, 2025
c14d56c
feat: show speed (#27)
mateof Feb 19, 2025
df22f6e
refactor: modify transactionInfoService to singleton
mateof Feb 20, 2025
687a23b
chore: solve start timer
mateof Feb 20, 2025
7fb1fc3
chore: solve timer problem
mateof Feb 20, 2025
f6884d9
chore: reset upload bytes
mateof Feb 20, 2025
9d8e3cb
feat: add relative path to caption
mateof Feb 24, 2025
ed34339
Merge branch 'develop' of https://github.com/mateof/TelegramFileManag…
mateof Feb 24, 2025
9b12a0b
Merge branch 'main' of https://github.com/mateof/TelegramFileManager …
mateof Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TelegramDownloader/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public async Task<IActionResult> GetFile(string id, string? idChannel, string? i
cm.message = idM;
file = new FileStream(System.IO.Path.Combine(FileService.TEMPDIR, "_temp", $"{idChannel}-{idFile}-{id}"), FileMode.Create, FileAccess.ReadWrite);
DownloadModel dm = new DownloadModel();
dm.tis = _tis;
dm.channelName = _ts.getChatName(Convert.ToInt64(idChannel));
_tis.addToDownloadList(dm);
await _ts.DownloadFileAndReturn(cm, file, model: dm);
Expand Down
30 changes: 21 additions & 9 deletions TelegramDownloader/Data/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ public static void functionCalll(string dbName, int messageId, string destPath)
private async Task downloadFromTelegram(string dbName, int messageId, string destPath, BsonFileManagerModel file = null)
{
DownloadModel model = new DownloadModel();
model.tis = _tis;
if (file != null)
{
model.name = file.Name;
Expand All @@ -817,7 +818,11 @@ private async Task downloadFromTelegram(string dbName, int messageId, string des
public async Task DownloadFileFromChat(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null)
{
if (model == null)
{
model = new DownloadModel();
model.tis = _tis;
}

model.name = fileName;
if (message.message.media is MessageMediaDocument { document: Document document })
{
Expand Down Expand Up @@ -1099,6 +1104,7 @@ public async Task CreateDatabase(string id)
public async Task AddUploadFileFromServer(string dbName, string currentPath, List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> files, InfoDownloadTaksModel idt = null) // ItemsUploadedEventArgs<FileManagerDirectoryContent> args)
{
idt = new InfoDownloadTaksModel();
idt.tis = _tis;
idt.id = Guid.NewGuid().ToString();
idt.total = 0;
idt.totalSize = 0;
Expand Down Expand Up @@ -1135,9 +1141,8 @@ public async Task AddUploadFileFromServer(string dbName, string currentPath, Lis
}
idt.callbacks = new Callbacks();
idt.callbacks.callback = async () => await UploadFileFromServer(dbName, currentPath, files, idt);
TransactionInfoService ti = new TransactionInfoService();
ti.addToInfoDownloadTaskList(idt);
ti.CheckPendingUploadInfoTasks();
_tis.addToInfoDownloadTaskList(idt);
_tis.CheckPendingUploadInfoTasks();
}


Expand Down Expand Up @@ -1254,6 +1259,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
int attempts = 3;
int waitForNextAttempt = 1000;
UploadModel um = new UploadModel();
um.tis = _tis;
um.path = currentFilePath;
um.chatName = _ts.getChatName(Convert.ToInt64(dbName));
// add upload to task list
Expand All @@ -1264,7 +1270,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
{
wt = new WaitingTime();
using (FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.Read))
m = await _ts.uploadFile(dbName, fs, $"({i} of {filesSplit.Count}) - " + file.Name, um: um);
m = await _ts.uploadFile(dbName, fs, $"({i} of {filesSplit.Count}) - " + file.Name, um: um, caption: getCaption(filePath));
attempts = 0;
await wt.Sleep(); // sleep 1 second to avoid 420 flood_wait_x
}
Expand Down Expand Up @@ -1303,6 +1309,7 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
int attempts = 3;
int waitForNextAttempt = 60000;
UploadModel um = new UploadModel();
um.tis = _tis;
um.path = currentFilePath;
um.chatName = _ts.getChatName(Convert.ToInt64(dbName));
// add upload to task list
Expand All @@ -1317,17 +1324,17 @@ public async Task UploadFileFromServer(string dbName, string currentPath, List<S
using (FileStream ms = new FileStream(System.IO.Path.Combine(currentFilePath), FileMode.Open))
if (ImageExtensions.Any(x => file.Name.ToUpper().EndsWith(x)) && file.Size >= MAXIMAGESIZE)
{
m = await _ts.uploadFile(dbName, ms, file.Name, "application/octet-stream", um);
m = await _ts.uploadFile(dbName, ms, file.Name, "application/octet-stream", um, caption: getCaption(filePath));
}
else
m = await _ts.uploadFile(dbName, ms, file.Name, um: um);
m = await _ts.uploadFile(dbName, ms, file.Name, um: um, caption: getCaption(filePath));
}
catch (Exception ex)
{
if (new List<string> { "IMAGE", "PHOTO" }.Any(x => ex.Message.Contains(x)))
{
using (FileStream ms = new FileStream(System.IO.Path.Combine(currentFilePath), FileMode.Open))
m = await _ts.uploadFile(dbName, ms, file.Name, "application/octet-stream", um);
m = await _ts.uploadFile(dbName, ms, file.Name, "application/octet-stream", um, caption: getCaption(filePath));
}
else
{
Expand Down Expand Up @@ -1508,7 +1515,7 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
foreach (string s in files)
{
using (FileStream fs = new FileStream(s, FileMode.Open, FileAccess.Read, FileShare.Read))
m = await _ts.uploadFile(dbName, fs, $"({i} of {files.Count}) - " + file.File.Name);
m = await _ts.uploadFile(dbName, fs, $"({i} of {files.Count}) - " + file.File.Name, caption: getCaption(currentPath));
model.ListMessageId.Add(m.ID);
File.Delete(s);
i++;
Expand All @@ -1519,7 +1526,7 @@ public async Task UploadFile(string dbName, string currentPath, UploadFiles file
{
using (FileStream ms = new FileStream(System.IO.Path.Combine(currentFilePath, file.File.Name), FileMode.Open))
{
m = await _ts.uploadFile(dbName, ms, file.File.Name);
m = await _ts.uploadFile(dbName, ms, file.File.Name, caption: getCaption(currentPath));
}
model.MessageId = m.ID;
}
Expand Down Expand Up @@ -1751,6 +1758,11 @@ private async Task<List<ExpandoObject>> AddChildRecords(string id, string parent
return response;
}

private string? getCaption(string filePath)
{
return GeneralConfigStatic.config.ShouldShowCaptionPath ? filePath : null;
}

private async Task<MemoryStream> ToMemoryStreamAsync(Stream stream)
{
var memoryStream = new MemoryStream();
Expand Down
2 changes: 1 addition & 1 deletion TelegramDownloader/Data/ITelegramService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface ITelegramService
Task<string> getPhotoThumb(ChatBase chat);
Task logOff();
Task sendVerificationCode(string vc);
Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null);
Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null, string caption = null);

}
}
13 changes: 11 additions & 2 deletions TelegramDownloader/Data/TelegramService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,18 @@ public async Task<List<ChatViewBase>> getAllSavedChats()
return allChats;
}

public async Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null)
public async Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null, string caption = null)
{
um = um ?? new UploadModel();
um.tis = _tis;

InputPeer peer = chats.chats[Convert.ToInt64(chatId)];
um.name = fileName;
um._size = file.Length;
um._transmitted = 0;
_tis.addToUploadList(um);
var inputFile = await client.UploadFileAsync(file, fileName, um.ProgressCallback);
return await client.SendMediaAsync(peer, fileName, inputFile, mimeType);
return await client.SendMediaAsync(peer, caption ?? fileName, inputFile, mimeType);
}

public async Task deleteFile(string chatId, int idMessage)
Expand Down Expand Up @@ -417,7 +418,11 @@ public async Task RemoveFavouriteChannel(long id)
public async Task<Stream> DownloadFileAndReturn(ChatMessages message, Stream ms = null, string fileName = null, string folder = null, DownloadModel model = null)
{
if (model == null)
{
model = new DownloadModel();
model.tis = _tis;
}

model.m = message;
model.channel = message.user;

Expand Down Expand Up @@ -466,7 +471,11 @@ public async Task<Stream> DownloadFileAndReturn(ChatMessages message, Stream ms
public async Task<string> DownloadFile(ChatMessages message, string fileName = null, string folder = null, DownloadModel model = null, bool shouldAddToList = false)
{
if (model == null)
{
model = new DownloadModel();
model.tis = _tis;
}

model.m = message;
model.channel = message.user;

Expand Down
18 changes: 10 additions & 8 deletions TelegramDownloader/Models/DownloadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class InfoDownloadTaksModel
public int progress { get; set; }
public List<UploadModel> currentUploads { get; set; } = new List<UploadModel>();
public List<DownloadModel> currentDownloads { get; set; } = new List<DownloadModel>();
public TransactionInfoService tis { get; set; }

public async void AddOne(long size)
{
Expand All @@ -48,7 +49,6 @@ public async void AddOne(long size)
public async void markAsCompleted()
{
state = StateTask.Completed;
TransactionInfoService tis = new TransactionInfoService();
tis.CheckPendingUploadInfoTasks();
EventChanged?.Invoke(this, new InfoTaskEventArgs());

Expand Down Expand Up @@ -82,7 +82,6 @@ public void Retry()
{
state = StateTask.Pending;
currentUpload = 0;
TransactionInfoService tis = new TransactionInfoService();
tis.CheckPendingUploadInfoTasks();
}

Expand All @@ -107,7 +106,6 @@ public void cancelTask()
um.Cancel();
}
}
TransactionInfoService tis = new TransactionInfoService();
tis.CheckPendingUploadInfoTasks();
}

Expand All @@ -119,6 +117,7 @@ private void deleteNotWorkingTasks()
}
public class DownloadModel
{
public Mutex mutex = new Mutex();
public event EventHandler<DownloadEventArgs> EventChanged;
public string id = Guid.NewGuid().ToString();
public string action { get; set; } = "Download";
Expand All @@ -129,14 +128,16 @@ public class DownloadModel
public Callbacks callbacks { get; set; }

public long _size { get; set; }
public long _transmitted { get; set; }
public long _transmitted { get; set; } = 0;

public string _sizeString { get; set; }
public string _transmittedString { get; set; }

public IPeerInfo channel { get; set; }
public string channelName { get; set; }
public int progress { get; set; }
public TransactionInfoService tis { get; set; }


public DownloadModel(string? name = null)
{
Expand All @@ -150,11 +151,12 @@ public void ProgressCallback(long transmitted, long totalSize)
throw new Exception($"Canceled {name}");
if (state == StateTask.Paused)
{
TransactionInfoService tis = new TransactionInfoService();

state = StateTask.Working;
tis.deleteDownloadInList(this);
throw new Exception($"Paused {name}");
}
tis.addDownloadBytes(transmitted - _transmitted);
_transmitted = transmitted;
_sizeString = HelperService.SizeSuffix(totalSize);
_transmittedString = HelperService.SizeSuffix(transmitted);
Expand All @@ -165,7 +167,6 @@ public void ProgressCallback(long transmitted, long totalSize)
state = StateTask.Completed;
NotificationModel nm = new NotificationModel();
nm.sendEvent(new Notification($"Download {name} completed", "Download Completed", NotificationTypes.Success));
TransactionInfoService tis = new TransactionInfoService();
tis.CheckPendingDownloads();
}

Expand All @@ -174,7 +175,6 @@ public void ProgressCallback(long transmitted, long totalSize)
public void Cancel()
{
state = StateTask.Canceled;
TransactionInfoService tis = new TransactionInfoService();
tis.CheckPendingDownloads();
EventChanged?.Invoke(this, new DownloadEventArgs());
}
Expand Down Expand Up @@ -202,19 +202,21 @@ public class UploadModel
public string path { get; set; }

public long _size { get; set; }
public long _transmitted { get; set; }
public long _transmitted { get; set; } = 0;

public string _sizeString { get; set; }
public string _transmittedString { get; set; }
public string chatName { get; set; }
public IPeerInfo channel { get; set; }
public int progress { get; set; }
public Thread thread { get; set; }
public TransactionInfoService tis { get; set; }

public virtual void ProgressCallback(long transmitted, long totalSize)
{
if (state == StateTask.Canceled)
throw new Exception($"Canceled {name}");
tis.addUploadBytes(transmitted - _transmitted);
_transmitted = transmitted;
_sizeString = HelperService.SizeSuffix(totalSize);
_transmittedString = HelperService.SizeSuffix(transmitted);
Expand Down
1 change: 1 addition & 0 deletions TelegramDownloader/Models/GeneralConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class GeneralConfig
public int SplitSize { get; set; } = 0;
public int MaxSimultaneousDownloads = 1;
public bool CheckHash { get; set; } = false;
public bool ShouldShowCaptionPath { get; set; } = false;
public bool ShouldShowLogInTerminal { get; set; } = false;
public List<long> FavouriteChannels { get; set; } = new List<long>();

Expand Down
Loading