Archived
Private
Public Access
1
0
This commit is contained in:
2023-04-30 22:26:48 +02:00
parent 4f6c0a00be
commit 0d83e9d75e
10 changed files with 43 additions and 106 deletions

View File

@@ -4,6 +4,7 @@ using System.Text;
using Aspose.Email.Clients.Imap;
using BetterIServ.Backend.Entities;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace BetterIServ.Backend.Controllers;
@@ -92,8 +93,11 @@ public class MailController : ControllerBase {
return new SingleResult<ImapFolderInfo[]> { Value = results.ToArray() };
}
[HttpPost("download/{id}/{attachment}")]
public async Task<FileStreamResult> DownloadAttachment([FromBody] Credentials credentials, [FromRoute] int id, [FromRoute] string attachment) {
[HttpGet("download/{id}/{attachment}")]
public async Task<FileStreamResult> DownloadAttachment([FromQuery] string credentialString, [FromRoute] int id, [FromRoute] string attachment) {
var credentials = JsonConvert.DeserializeObject<Credentials>(credentialString);
if (credentials == null) return new FileStreamResult(Stream.Null, "");
using var client = new ImapClient($"imap.{credentials.Domain}", credentials.Username, credentials.Password);
var data = await client.FetchAttachmentAsync(id, attachment);

View File

@@ -1,6 +1,7 @@
using System.Net;
using BetterIServ.Backend.Entities;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WebDav;
namespace BetterIServ.Backend.Controllers;
@@ -40,8 +41,11 @@ public class WebDavController : ControllerBase {
return contents.OrderBy(item => item.Type).ToArray();
}
[HttpPost("download")]
public async Task<FileStreamResult> DonwloadFile([FromBody] Credentials credentials, [FromQuery] string url) {
[HttpGet("download")]
public async Task<FileStreamResult> DonwloadFile([FromQuery] string url, [FromQuery] string credentialString) {
var credentials = JsonConvert.DeserializeObject<Credentials>(credentialString);
if (credentials == null) return new FileStreamResult(Stream.Null, "");
var baseAddress = new Uri($"https://webdav.{credentials.Domain}");
using var client = new WebDavClient(new WebDavClientParams {
BaseAddress = baseAddress,