This commit is contained in:
18
APIControllers/DeletePost.cs
Normal file
18
APIControllers/DeletePost.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NeDvachAPI.DBControllers;
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class DeletePostController : ControllerBase
|
||||
{
|
||||
[HttpDelete("{id}")]
|
||||
public JsonResult Get(string id)
|
||||
{
|
||||
DBchat.DeletePost(id);
|
||||
return new JsonResult("Deleted Successfully!");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
21
APIControllers/GetPosts.cs
Normal file
21
APIControllers/GetPosts.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NeDvachAPI.BufferControllers;
|
||||
using System.Text.Json;
|
||||
using System.Web.Http;
|
||||
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
||||
using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute;
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ListController : ControllerBase
|
||||
{
|
||||
[HttpGet(Name = "GetPosts")]
|
||||
public string Get([FromUri] string board, int thread)
|
||||
{
|
||||
string postsJson = JsonSerializer.Serialize(APIThreadBuffer.GetThread(thread));
|
||||
return postsJson ;
|
||||
}
|
||||
}
|
||||
}
|
39
APIControllers/PictureUpload.cs
Normal file
39
APIControllers/PictureUpload.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NeDvachAPI.DBControllers;
|
||||
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class UploadPic : ControllerBase
|
||||
{
|
||||
|
||||
|
||||
[HttpPost(Name = "UploadPicture")]
|
||||
public async Task<JsonResult> ReceivePost([FromForm] IFormFile PostPicture)
|
||||
{
|
||||
var supportedTypes = new[] { "jpg", "png" };
|
||||
string receivedFileName = PostPicture.FileName;
|
||||
string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3);
|
||||
if (supportedTypes.Contains(fileExt)) //file type check
|
||||
{
|
||||
///Local Buffer File Part
|
||||
string filePath;
|
||||
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
|
||||
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||
PostPicture.CopyTo(picBuffer);
|
||||
picBuffer.Close();
|
||||
///MinIo part
|
||||
JsonResult picAdress = new(await MinIOchat.PictureUpload(filePath, receivedFileName));
|
||||
Console.WriteLine("Загружен файл:" + "http://static.vdk2ch.ru:15555/thread-pics/" + receivedFileName);
|
||||
return picAdress;
|
||||
}
|
||||
|
||||
else return new JsonResult("Неверный тип файла");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
30
APIControllers/PostPost.cs
Normal file
30
APIControllers/PostPost.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NeDvachAPI.BufferControllers;
|
||||
using NeDvachAPI.DBControllers;
|
||||
using NeDvachAPI.Models;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class PostToController : ControllerBase
|
||||
{
|
||||
[HttpPost(Name = "PostPosts")]
|
||||
public JsonResult ReceivePost([FromBody] Post ReceivedPost)
|
||||
{
|
||||
string ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
|
||||
ReceivedPost.Ip = ipAddress;
|
||||
try
|
||||
{
|
||||
DBchat.SendPost(ReceivedPost);
|
||||
APIThreadBuffer.RefreshThread(ReceivedPost.Thread_Id);
|
||||
return new JsonResult("Сообщение успешно добавлено.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new JsonResult("Произошла ошибка постинга");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
APIControllers/ShowThreads.cs
Normal file
21
APIControllers/ShowThreads.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NeDvachAPI.BufferControllers;
|
||||
using System.Text.Json;
|
||||
using System.Web.Http;
|
||||
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
||||
using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute;
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class ThreadsController : ControllerBase
|
||||
{
|
||||
[HttpGet(Name = "GetThreads")]
|
||||
public string Get([FromUri] string board)
|
||||
{
|
||||
string postsJson = JsonSerializer.Serialize(APIThreadBuffer.GetThreadPreviews());
|
||||
return postsJson;
|
||||
}
|
||||
}
|
||||
}
|
19
APIControllers/TestPosting.cs
Normal file
19
APIControllers/TestPosting.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NeDvachAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class TestPostingController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public int Area([FromForm] int height , int altitude)
|
||||
{
|
||||
//DBchat.SendPost(ReceivedPost);
|
||||
Console.WriteLine("Received! " + height + " " + altitude );
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user