Skip to content

Commit f1130a8

Browse files
authored
internal: Develop to main (#40)
* feat: add download grid from channels chore: bump versions * feat: show channel files * feat: add media streaming from telegram (#32) * feat: media stream for huge files (#34) * feat: add webdav and export files to strm (#39) feat: improves fix: error on download root files fix: error on download splitted files * chore: dockerfile * chore: dockerfile change * chore: python virtual env * chore: add beta tags * chore: log refresh
1 parent 5295aa5 commit f1130a8

29 files changed

Lines changed: 1109 additions & 207 deletions

TelegramDownloader/Controllers/FileController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,19 @@ public async Task<IActionResult> GetFile(string id, string? idChannel, string? i
267267
};
268268
}
269269

270+
[Route("strm")]
271+
public async Task<IActionResult> GetStrm([FromQuery] string idChannel, [FromQuery] string path, [FromQuery] string host)
272+
{
273+
String zip = await _fs.CreateStrmFiles(path, idChannel, host);
274+
275+
FileStream fs = new FileStream(zip, FileMode.Open);
276+
277+
return new FileStreamResult(fs, "application/octet-stream")
278+
{
279+
FileDownloadName = Path.GetFileName(zip)
280+
};
281+
}
282+
270283
[Route("GetFileStream/{idChannel}/{idFile}/{name}")]
271284
public async Task<IActionResult> GetFileStream(string idChannel, string idFile, string name)
272285
{
@@ -275,6 +288,7 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,
275288

276289
var request = HttpContext.Request;
277290
var rangeHeader = request.Headers["Range"].ToString();
291+
Console.WriteLine("range: ", rangeHeader);
278292

279293
var file = await _fs.getItemById(idChannel, idFile);
280294
long totalLength = file.Size;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using TelegramDownloader.Data.db;
3+
using TelegramDownloader.Data;
4+
using TelegramDownloader.Models;
5+
using System.Text.Json;
6+
7+
namespace TelegramDownloader.Controllers
8+
{
9+
[Route("api/nodes")]
10+
[ApiController]
11+
public class WebDavController : ControllerBase
12+
{
13+
IDbService _db { get; set; }
14+
15+
public WebDavController(IDbService db)
16+
{
17+
_db = db;
18+
}
19+
[HttpGet]
20+
public async Task<List<WebDavFileModel>> webDavPaths([FromQuery] string path, [FromQuery] string depth)
21+
{
22+
Console.WriteLine("Peticion de webDavPaths: " + path);
23+
var isFile = Path.HasExtension(path);
24+
if (!path.EndsWith("/") && !isFile)
25+
path = path + "/";
26+
if (String.IsNullOrEmpty(path))
27+
throw new BadHttpRequestException("Path is null or empty");
28+
string channel = path.Split("/")[1];
29+
if (String.IsNullOrEmpty(channel))
30+
throw new BadHttpRequestException("Channel is empty");
31+
path = path.Remove(0, path.IndexOf("/", 1));
32+
List<WebDavFileModel> files = new List<WebDavFileModel>();
33+
if (isFile)
34+
{
35+
var bsonFile = await _db.getFileByPath(channel, path);
36+
if (!(bsonFile == null) && bsonFile.IsFile)
37+
{
38+
WebDavFileModel file = bsonFile.toWebDavFileModel(channel);
39+
files = new List<WebDavFileModel>();
40+
files.Add(file);
41+
}
42+
}
43+
if ((!isFile) || files.Count == 0)
44+
{
45+
if (depth == "0")
46+
{
47+
var bsonFile = await _db.getFileByPath(channel, path[..^1]);
48+
if (bsonFile != null)
49+
{
50+
WebDavFileModel file = bsonFile.toWebDavFileModel(channel);
51+
files = new List<WebDavFileModel>();
52+
files.Add(file);
53+
}
54+
55+
}
56+
else
57+
files = (await _db.getAllFilesInDirectoryPath(channel, path)).Select(file => file.toWebDavFileModel()).ToList();
58+
}
59+
60+
// Console.WriteLine(JsonSerializer.Serialize(files));
61+
return files;
62+
}
63+
64+
[HttpGet("meta")]
65+
public async Task<object> webDavMetadata([FromQuery] string path)
66+
{
67+
Console.WriteLine("Peticion de webDavMetadata: " + path);
68+
if (String.IsNullOrEmpty(path))
69+
throw new Exception("Path is null or empty");
70+
string channel = path.Split("/")[1];
71+
if (String.IsNullOrEmpty(channel))
72+
throw new Exception("Channel is empty");
73+
path = path.Remove(0, path.IndexOf("/", 1));
74+
var bsonFile = await _db.getFileByPath(channel, path);
75+
if (bsonFile == null || !bsonFile.IsFile)
76+
throw new FileNotFoundException();
77+
WebDavFileModel files = bsonFile.toWebDavFileModel(channel);
78+
return files;
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)