Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions TelegramDownloader/Configuration/config.a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"api_id": "62071",
"hash_id": "2204b5c6075aeb2e1cdc81e68e2f9256",
"mongo_connection_string": "mongodb://mateo:mateoMongo@192.168.0.22:27017",
"avoid_checking_certificate": true
}
7 changes: 4 additions & 3 deletions TelegramDownloader/Controllers/FileController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http.Features;
#nullable disable
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;

using MongoDB.Driver;
Expand Down Expand Up @@ -526,8 +527,8 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,
Response.StatusCode = StatusCodes.Status206PartialContent; // StatusCodes.Status206PartialContent;
Response.ContentType = mimeType;
Response.Headers["Content-Disposition"] = $"inline; filename=\"{HttpUtility.UrlEncode(fileName)}\"";
Response.Headers.Add("Content-Range", $"bytes {(initialFrom >= totalLength ? totalLength - 1 : initialFrom)}-{(initialFrom >= totalLength ? totalLength - 1 : initialFrom + Response.ContentLength - 1)}/{totalLength}");
Response.Headers.Add("Accept-Ranges", "bytes");
Response.Headers["Content-Range"] = $"bytes {(initialFrom >= totalLength ? totalLength - 1 : initialFrom)}-{(initialFrom >= totalLength ? totalLength - 1 : initialFrom + Response.ContentLength - 1)}/{totalLength}";
Response.Headers["Accept-Ranges"] = "bytes";

//if (Request.Headers.ContainsKey("Range"))
//{
Expand Down
72 changes: 67 additions & 5 deletions TelegramDownloader/Data/FileService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorBootstrap;
#nullable disable
using BlazorBootstrap;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.StaticFiles;
using MongoDB.Driver;
Expand Down Expand Up @@ -873,7 +874,7 @@ public virtual async Task downloadFromTelegram(string dbName, int messageId, str
try
{
model.channelName = _ts.getChatName(Convert.ToInt64(dbName));
} catch(Exception ex) {
} catch {
model.channelName = "Public or Shared";
}
var tcs = new TaskCompletionSource<bool>();
Expand Down Expand Up @@ -1280,10 +1281,10 @@ public async Task<String> CreateStrmFiles(string path, string dbName, string hos
{
Directory.Delete(basePath, true);
}
catch (Exception ex)
catch
{
}

Directory.CreateDirectory(basePath);
List<BsonFileManagerModel> filesAndFolders = await _db.getAllChildFilesInDirectory(dbName, path);
foreach (BsonFileManagerModel file in filesAndFolders)
Expand Down Expand Up @@ -1314,6 +1315,45 @@ public async Task<String> CreateStrmFiles(string path, string dbName, string hos
Directory.Delete(basePath, true);
return zipPath;
}

public async Task CreateStrmFilesToLocal(string path, string dbName, string host, string destinationFolder)
{
String folderPathName = Path.GetFileName(path.TrimEnd('/'));
String basePath = Path.Combine(LOCALDIR, destinationFolder, folderPathName);

// Create destination directory
Directory.CreateDirectory(basePath);

List<BsonFileManagerModel> filesAndFolders = await _db.getAllChildFilesInDirectory(dbName, path);
foreach (BsonFileManagerModel file in filesAndFolders)
{
String filePath = Path.Combine(basePath, file.FilePath.Substring(path.Length));
if (file.IsFile)
{
if (FileExtensionTypeTest.isVideoExtension(file.Type) || FileExtensionTypeTest.isAudioExtension(file.Type))
{
string contenido = Path.Combine(host, "api/file/GetFileStream", dbName, file.Id, "file" + file.Type).Replace("\\", "/");
if (GeneralConfigStatic.config.PreloadFilesOnStream || HelperService.bytesToMegaBytes(file.Size) < GeneralConfigStatic.config.MaxPreloadFileSizeInMb)
{
contenido = Path.Combine(host, "api/file/GetFileByTfmId", Uri.EscapeDataString(file.Name)).Replace("\\", "/") + $"?idChannel={dbName}&idFile={file.Id}";
}
string pattern = $@"\.({file.Type.Replace(".", "")})$";
// Ensure parent directory exists
var parentDir = Path.GetDirectoryName(Regex.Replace(filePath, pattern, ".strm"));
if (!string.IsNullOrEmpty(parentDir))
{
Directory.CreateDirectory(parentDir);
}
File.WriteAllText(Regex.Replace(filePath, pattern, ".strm"), contenido);
}
}
else
{
Directory.CreateDirectory(filePath);
}
}
}

public async Task UploadFileFromServer(string dbName, string currentPath, List<Syncfusion.Blazor.FileManager.FileManagerDirectoryContent> files, InfoDownloadTaksModel dm = null) // ItemsUploadedEventArgs<FileManagerDirectoryContent> args)
{
_logger.LogInformation("Starting upload from server - DbName: {DbName}, Path: {Path}, FilesCount: {Count}",
Expand Down Expand Up @@ -1797,7 +1837,7 @@ public static string getMimeType(string extension)
{
return MIMETypesDictionary[extension.Replace(".", "")] ?? "application/octet-stream";
}
catch (Exception e)
catch
{
return "application/octet-stream";
}
Expand Down Expand Up @@ -1941,6 +1981,28 @@ private async Task<List<ExpandoObject>> AddChildRecords(string id, string parent
var matchingFolder = Data.FirstOrDefault(x => x.FilePath + "/" == path)
?? Data.FirstOrDefault(x => x.FilePath == path.TrimEnd('/'));

// If not found in Data, try searching by name and parent FilterPath
// This handles cases where FilePath format doesn't match (e.g., first-level folders)
if (matchingFolder == null)
{
// Extract folder name and parent path from the navigation path
// e.g., "/FolderA/" -> name = "FolderA", parentPath = "/"
// e.g., "/Parent/Child/" -> name = "Child", parentPath = "/Parent/"
var pathParts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (pathParts.Length > 0)
{
var folderName = pathParts[pathParts.Length - 1];
var parentPath = pathParts.Length == 1
? "/"
: "/" + string.Join("/", pathParts.Take(pathParts.Length - 1)) + "/";

// Search for folder by name and parent FilterPath
matchingFolder = collectionName == null
? await _db.getFolderByNameAndParentPath(dbName, folderName, parentPath)
: await _db.getFolderByNameAndParentPath(dbName, folderName, parentPath, collectionName);
}
}

if (matchingFolder != null)
{
childItem = matchingFolder.toFileManagerContent();
Expand Down
5 changes: 3 additions & 2 deletions TelegramDownloader/Data/FileServiceV2.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorBootstrap;
#nullable disable
using BlazorBootstrap;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.StaticFiles;
using MongoDB.Driver;
Expand Down Expand Up @@ -129,7 +130,7 @@ public async Task downloadFromTelegramV2(string dbName, int messageId, string de
{
model.channelName = _ts.getChatName(Convert.ToInt64(dbName));
}
catch (Exception ex)
catch
{
model.channelName = "Public or Shared";
}
Expand Down
4 changes: 3 additions & 1 deletion TelegramDownloader/Data/IFileService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Syncfusion.Blazor.FileManager;
#nullable disable
using Syncfusion.Blazor.FileManager;
using Syncfusion.Blazor.Inputs;
using System.Dynamic;
using TelegramDownloader.Models;
Expand Down Expand Up @@ -30,6 +31,7 @@ public interface IFileService
Task<List<BsonFileManagerModel>> getTelegramFoldersByParentId(string dbName, string? parentId);
Task<List<ExpandoObject>> GetTelegramFoldersExpando(string id, string parentId);
Task<String> CreateStrmFiles(string path, string dbName, string host);
Task CreateStrmFilesToLocal(string path, string dbName, string host, string destinationFolder);
Task importData(string dbName, string path, GenericNotificationProgressModel gnp);
Task importSharedData(ShareFilesModel sfm, GenericNotificationProgressModel gnp);
Task<FileManagerResponse<FileManagerDirectoryContent>> itemDeleteAsync(string dbName, ItemsDeleteEventArgs<FileManagerDirectoryContent> args);
Expand Down
9 changes: 8 additions & 1 deletion TelegramDownloader/Data/ITelegramService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BlazorBootstrap;
#nullable disable
using BlazorBootstrap;
using TelegramDownloader.Models;
using TL;
using WTelegram;
Expand All @@ -7,6 +8,8 @@ namespace TelegramDownloader.Data
{
public interface ITelegramService
{
bool IsConfigured { get; }
void InitializeClient();
Task<string> checkAuth(string number, bool isPhone = false);
Task<User> GetUser();
bool checkChannelExist(string id);
Expand Down Expand Up @@ -40,6 +43,10 @@ public interface ITelegramService
Task<Message> uploadFile(string chatId, Stream file, string fileName, string mimeType = null, UploadModel um = null, string caption = null);
Task<List<TelegramChatDocuments>> searchAllChannelFiles(long id, int lastId);
bool isMyChat(long id);
bool isChannelOwner(long id);
Task<TL.Channel?> CreateChannel(string title, string about);
Task LeaveChannel(long id);
Task DeleteChannel(long id);
(string? name, bool exists) GetChannelInfo(long id);
}
}
Loading