This commit is contained in:
parent
50a3c94af8
commit
a4b72664fd
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Data;
|
using NeDvachAPI.DBControllers;
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
namespace NeDvachAPI.Controllers
|
namespace NeDvachAPI.Controllers
|
||||||
{
|
{
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NeDvachAPI.BufferControllers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
@ -1,7 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.VisualBasic;
|
using NeDvachAPI.DBControllers;
|
||||||
using Microsoft.Win32.SafeHandles;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
|
|
||||||
namespace NeDvachAPI.Controllers
|
namespace NeDvachAPI.Controllers
|
||||||
@ -10,9 +8,7 @@ namespace NeDvachAPI.Controllers
|
|||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class UploadPic : ControllerBase
|
public class UploadPic : ControllerBase
|
||||||
{
|
{
|
||||||
///Local Buffer File Part
|
|
||||||
|
|
||||||
string filePath;
|
|
||||||
|
|
||||||
[HttpPost(Name = "UploadPicture")]
|
[HttpPost(Name = "UploadPicture")]
|
||||||
public async Task<JsonResult> ReceivePost([FromForm] IFormFile PostPicture)
|
public async Task<JsonResult> ReceivePost([FromForm] IFormFile PostPicture)
|
||||||
@ -20,13 +16,12 @@ namespace NeDvachAPI.Controllers
|
|||||||
var supportedTypes = new[] { "jpg", "png" };
|
var supportedTypes = new[] { "jpg", "png" };
|
||||||
string receivedFileName = PostPicture.FileName;
|
string receivedFileName = PostPicture.FileName;
|
||||||
string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3);
|
string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3);
|
||||||
//Console.WriteLine("Тип файла: " + fileExt);
|
|
||||||
if (supportedTypes.Contains(fileExt)) //file type check
|
if (supportedTypes.Contains(fileExt)) //file type check
|
||||||
{
|
{
|
||||||
|
///Local Buffer File Part
|
||||||
|
string filePath;
|
||||||
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
|
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
|
||||||
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
|
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
|
||||||
//Console.WriteLine("Закидываю файл в " + filePath);
|
|
||||||
PostPicture.CopyTo(picBuffer);
|
PostPicture.CopyTo(picBuffer);
|
||||||
picBuffer.Close();
|
picBuffer.Close();
|
||||||
///MinIo part
|
///MinIo part
|
@ -1,4 +1,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NeDvachAPI.BufferControllers;
|
||||||
|
using NeDvachAPI.DBControllers;
|
||||||
|
using NeDvachAPI.Models;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace NeDvachAPI.Controllers
|
namespace NeDvachAPI.Controllers
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NeDvachAPI.BufferControllers;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
using HttpGetAttribute = Microsoft.AspNetCore.Mvc.HttpGetAttribute;
|
||||||
@ -13,7 +14,7 @@ namespace NeDvachAPI.Controllers
|
|||||||
[HttpGet(Name = "GetThreads")]
|
[HttpGet(Name = "GetThreads")]
|
||||||
public string Get([FromUri] string board)
|
public string Get([FromUri] string board)
|
||||||
{
|
{
|
||||||
string postsJson = JsonSerializer.Serialize(APIThreadBuffer.GetOPPosts());
|
string postsJson = JsonSerializer.Serialize(APIThreadBuffer.GetThreadPreviews());
|
||||||
return postsJson;
|
return postsJson;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace NeDvachAPI
|
using NeDvachAPI.DBControllers;
|
||||||
|
using NeDvachAPI.Models;
|
||||||
|
|
||||||
|
namespace NeDvachAPI.BufferControllers
|
||||||
{
|
{
|
||||||
public class APIThreadBuffer
|
public class APIThreadBuffer
|
||||||
{
|
{
|
||||||
@ -9,7 +12,7 @@
|
|||||||
ThreadsPrewievs = OPPostsToWrite;
|
ThreadsPrewievs = OPPostsToWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Post> GetOPPosts()
|
public static List<Post> GetThreadPreviews()
|
||||||
{
|
{
|
||||||
return ThreadsPrewievs;
|
return ThreadsPrewievs;
|
||||||
}
|
}
|
||||||
@ -33,5 +36,6 @@
|
|||||||
{
|
{
|
||||||
Threads[threadId - 1] = DBchat.PostsList("b", threadId);
|
Threads[threadId - 1] = DBchat.PostsList("b", threadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace NeDvachAPI
|
using NeDvachAPI.DBControllers;
|
||||||
|
using NeDvachAPI.Models;
|
||||||
|
|
||||||
|
namespace NeDvachAPI.BufferControllers
|
||||||
{
|
{
|
||||||
public class BufferFill
|
public class BufferFill
|
||||||
{
|
{
|
@ -1,7 +1,8 @@
|
|||||||
using Npgsql;
|
using NeDvachAPI.Models;
|
||||||
|
using Npgsql;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
namespace NeDvachAPI
|
namespace NeDvachAPI.DBControllers
|
||||||
{
|
{
|
||||||
public class DBchat
|
public class DBchat
|
||||||
{
|
{
|
||||||
@ -16,7 +17,7 @@ namespace NeDvachAPI
|
|||||||
//int postCount = 0;
|
//int postCount = 0;
|
||||||
string received = "";
|
string received = "";
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
string.Format(
|
||||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||||
AuthInfo.DB.Host,
|
AuthInfo.DB.Host,
|
||||||
AuthInfo.DB.User,
|
AuthInfo.DB.User,
|
||||||
@ -87,7 +88,7 @@ namespace NeDvachAPI
|
|||||||
//int postCount = 0;
|
//int postCount = 0;
|
||||||
string received = "";
|
string received = "";
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
string.Format(
|
||||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||||
AuthInfo.DB.Host,
|
AuthInfo.DB.Host,
|
||||||
AuthInfo.DB.User,
|
AuthInfo.DB.User,
|
||||||
@ -156,7 +157,7 @@ namespace NeDvachAPI
|
|||||||
public static void DbUpdate(string id, string text)
|
public static void DbUpdate(string id, string text)
|
||||||
{
|
{
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
string.Format(
|
||||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||||
AuthInfo.DB.Host,
|
AuthInfo.DB.Host,
|
||||||
AuthInfo.DB.User,
|
AuthInfo.DB.User,
|
||||||
@ -175,7 +176,7 @@ namespace NeDvachAPI
|
|||||||
command.Parameters.AddWithValue("postText", text);
|
command.Parameters.AddWithValue("postText", text);
|
||||||
|
|
||||||
int nRows = command.ExecuteNonQuery();
|
int nRows = command.ExecuteNonQuery();
|
||||||
Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows));
|
Console.Out.WriteLine(string.Format("Number of rows updated={0}", nRows));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +186,7 @@ namespace NeDvachAPI
|
|||||||
public static void SendPost(Post postToSend) //sending post to database
|
public static void SendPost(Post postToSend) //sending post to database
|
||||||
{
|
{
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
string.Format(
|
||||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||||
AuthInfo.DB.Host,
|
AuthInfo.DB.Host,
|
||||||
AuthInfo.DB.User,
|
AuthInfo.DB.User,
|
||||||
@ -232,7 +233,7 @@ namespace NeDvachAPI
|
|||||||
public static void DeletePost(string idToDel) //удалялка
|
public static void DeletePost(string idToDel) //удалялка
|
||||||
{
|
{
|
||||||
string connString =
|
string connString =
|
||||||
String.Format(
|
string.Format(
|
||||||
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
|
||||||
AuthInfo.DB.Host,
|
AuthInfo.DB.Host,
|
||||||
AuthInfo.DB.User,
|
AuthInfo.DB.User,
|
||||||
@ -253,7 +254,7 @@ namespace NeDvachAPI
|
|||||||
command.Parameters.AddWithValue("ID", int.Parse(idToDel)); ;
|
command.Parameters.AddWithValue("ID", int.Parse(idToDel)); ;
|
||||||
|
|
||||||
int nRows = command.ExecuteNonQuery();
|
int nRows = command.ExecuteNonQuery();
|
||||||
Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows));
|
Console.Out.WriteLine(string.Format("Number of rows updated={0}", nRows));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ using Minio.DataModel;
|
|||||||
using Minio;
|
using Minio;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace NeDvachAPI
|
namespace NeDvachAPI.DBControllers
|
||||||
{
|
{
|
||||||
public class MinIOchat
|
public class MinIOchat
|
||||||
{
|
{
|
||||||
@ -26,8 +26,8 @@ namespace NeDvachAPI
|
|||||||
.WithContentType("image/png");
|
.WithContentType("image/png");
|
||||||
//.WithServerSideEncryption(ssec);
|
//.WithServerSideEncryption(ssec);
|
||||||
await DvachIo.PutObjectAsync(putObjectArgs);
|
await DvachIo.PutObjectAsync(putObjectArgs);
|
||||||
System.GC.Collect();
|
GC.Collect();
|
||||||
System.GC.WaitForPendingFinalizers();
|
GC.WaitForPendingFinalizers();
|
||||||
File.Delete(fileroute);
|
File.Delete(fileroute);
|
||||||
|
|
||||||
return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename);
|
return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename);
|
@ -1,4 +1,4 @@
|
|||||||
namespace NeDvachAPI
|
namespace NeDvachAPI.Models
|
||||||
{
|
{
|
||||||
public class Post
|
public class Post
|
||||||
{
|
{
|
@ -13,8 +13,4 @@
|
|||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Buffer\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using NeDvachAPI;
|
using NeDvachAPI.BufferControllers;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -11,8 +11,8 @@ builder.Services.AddCors(setup =>
|
|||||||
setup.AddDefaultPolicy(policyBuilder =>
|
setup.AddDefaultPolicy(policyBuilder =>
|
||||||
{
|
{
|
||||||
|
|
||||||
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*");
|
//policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*");
|
||||||
//policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*");
|
policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user