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
14 changes: 14 additions & 0 deletions TelegramDownloader/Controllers/FileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,19 @@ public async Task<IActionResult> GetFile(string id, string? idChannel, string? i
};
}

[Route("strm")]
public async Task<IActionResult> GetStrm([FromQuery] string idChannel, [FromQuery] string path, [FromQuery] string host)
{
String zip = await _fs.CreateStrmFiles(path, idChannel, host);

FileStream fs = new FileStream(zip, FileMode.Open);

return new FileStreamResult(fs, "application/octet-stream")
{
FileDownloadName = Path.GetFileName(zip)
};
}

[Route("GetFileStream/{idChannel}/{idFile}/{name}")]
public async Task<IActionResult> GetFileStream(string idChannel, string idFile, string name)
{
Expand All @@ -275,6 +288,7 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,

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

var file = await _fs.getItemById(idChannel, idFile);
long totalLength = file.Size;
Expand Down
81 changes: 81 additions & 0 deletions TelegramDownloader/Controllers/WebDavController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Microsoft.AspNetCore.Mvc;
using TelegramDownloader.Data.db;
using TelegramDownloader.Data;
using TelegramDownloader.Models;
using System.Text.Json;

namespace TelegramDownloader.Controllers
{
[Route("api/nodes")]
[ApiController]
public class WebDavController : ControllerBase
{
IDbService _db { get; set; }

public WebDavController(IDbService db)
{
_db = db;
}
[HttpGet]
public async Task<List<WebDavFileModel>> webDavPaths([FromQuery] string path, [FromQuery] string depth)
{
Console.WriteLine("Peticion de webDavPaths: " + path);
var isFile = Path.HasExtension(path);
if (!path.EndsWith("/") && !isFile)
path = path + "/";
if (String.IsNullOrEmpty(path))
throw new BadHttpRequestException("Path is null or empty");
string channel = path.Split("/")[1];
if (String.IsNullOrEmpty(channel))
throw new BadHttpRequestException("Channel is empty");
path = path.Remove(0, path.IndexOf("/", 1));
List<WebDavFileModel> files = new List<WebDavFileModel>();
if (isFile)
{
var bsonFile = await _db.getFileByPath(channel, path);
if (!(bsonFile == null) && bsonFile.IsFile)
{
WebDavFileModel file = bsonFile.toWebDavFileModel(channel);
files = new List<WebDavFileModel>();
files.Add(file);
}
}
if ((!isFile) || files.Count == 0)
{
if (depth == "0")
{
var bsonFile = await _db.getFileByPath(channel, path[..^1]);
if (bsonFile != null)
{
WebDavFileModel file = bsonFile.toWebDavFileModel(channel);
files = new List<WebDavFileModel>();
files.Add(file);
}

}
else
files = (await _db.getAllFilesInDirectoryPath(channel, path)).Select(file => file.toWebDavFileModel()).ToList();
}

// Console.WriteLine(JsonSerializer.Serialize(files));
return files;
}

[HttpGet("meta")]
public async Task<object> webDavMetadata([FromQuery] string path)
{
Console.WriteLine("Peticion de webDavMetadata: " + path);
if (String.IsNullOrEmpty(path))
throw new Exception("Path is null or empty");
string channel = path.Split("/")[1];
if (String.IsNullOrEmpty(channel))
throw new Exception("Channel is empty");
path = path.Remove(0, path.IndexOf("/", 1));
var bsonFile = await _db.getFileByPath(channel, path);
if (bsonFile == null || !bsonFile.IsFile)
throw new FileNotFoundException();
WebDavFileModel files = bsonFile.toWebDavFileModel(channel);
return files;
}
}
}
Loading