diff --git a/Buffer/15935082509663.jpg b/Buffer/15935082509663.jpg deleted file mode 100644 index fa1a466..0000000 Binary files a/Buffer/15935082509663.jpg and /dev/null differ diff --git a/Buffer/15973952325820.jpg b/Buffer/15973952325820.jpg deleted file mode 100644 index 927004c..0000000 Binary files a/Buffer/15973952325820.jpg and /dev/null differ diff --git a/Buffer/lvy.png b/Buffer/lvy.png deleted file mode 100644 index 6036ae1..0000000 Binary files a/Buffer/lvy.png and /dev/null differ diff --git a/Controllers/PictureUpload.cs b/Controllers/PictureUpload.cs index 1de4997..deceed6 100644 --- a/Controllers/PictureUpload.cs +++ b/Controllers/PictureUpload.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.VisualBasic; +using Microsoft.Win32.SafeHandles; using System.IO; @@ -18,18 +20,25 @@ namespace NeDvachAPI.Controllers var supportedTypes = new[] { "jpg", "png" }; string receivedFileName = PostPicture.FileName; string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3); - Console.WriteLine("Тип файла: " + fileExt); + //Console.WriteLine("Тип файла: " + fileExt); if (supportedTypes.Contains(fileExt)) //file type check { filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName; - Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.Write); - Console.WriteLine("Закидываю файл в " + filePath); + Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); + //Console.WriteLine("Закидываю файл в " + filePath); PostPicture.CopyTo(picBuffer); picBuffer.Close(); - return new JsonResult(await MinIOchat.PictureUpload(filePath, receivedFileName)); - } + ///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("Неверный тип файла"); } + + } + } diff --git a/DBchat.cs b/DBchat.cs index f762262..4c55f4b 100644 --- a/DBchat.cs +++ b/DBchat.cs @@ -125,8 +125,12 @@ namespace NeDvachAPI conn.Open(); using (var command = new NpgsqlCommand(@" - INSERT INTO dvach (post_id, post, post_timestamp) - VALUES ( DEFAULT, @postText, ( + INSERT INTO dvach (post_id, post, post_pic, post_timestamp) + VALUES ( + DEFAULT, + @postText, + @postImgUrl, + ( SELECT date_trunc( 'second', (now()::timestamp(0) AT TIME ZONE 'UTC+10')::TIMESTAMP @@ -134,6 +138,7 @@ namespace NeDvachAPI ) )", conn)) { command.Parameters.AddWithValue("postText", postToSend.Text); + command.Parameters.AddWithValue("postImgUrl", postToSend.ImgURL); //command.Parameters.AddWithValue("postTimeStamp", DateTime.Now.ToString("dd/MM/yyyy HH:mm")); int nRows = command.ExecuteNonQuery(); diff --git a/MinIOchat.cs b/MinIOchat.cs index 99b6053..0dd868c 100644 --- a/MinIOchat.cs +++ b/MinIOchat.cs @@ -7,14 +7,14 @@ namespace NeDvachAPI { public class MinIOchat { - public static async Task PictureUpload(string fileroute, string filename) + public static async Task PictureUpload(string fileroute, string filename) { MinioClient DvachIo = new MinioClient() .WithEndpoint(AuthInfo.MinIo.endpoint) .WithCredentials(AuthInfo.MinIo.username, AuthInfo.MinIo.password) //.WithSSL() .Build(); - Console.WriteLine(filename); + //Console.WriteLine(filename); Aes aesEncryption = Aes.Create(); aesEncryption.KeySize = 256; @@ -25,11 +25,15 @@ namespace NeDvachAPI .WithObject(filename) .WithFileName(fileroute) .WithContentType("image/png"); - //.WithServerSideEncryption(ssec); - Console.WriteLine("Кидаю в minio..."); + //.WithServerSideEncryption(ssec); + //Console.WriteLine("Кидаю в minio..."); await DvachIo.PutObjectAsync(putObjectArgs); + //await Task.Delay(5000); + System.GC.Collect(); + System.GC.WaitForPendingFinalizers(); + File.Delete(fileroute); - return "http://static.vdk2ch.ru:15555/thread-pics/" + filename; + return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename); } } } diff --git a/Program.cs b/Program.cs index 385a68e..baddff6 100644 --- a/Program.cs +++ b/Program.cs @@ -13,7 +13,7 @@ builder.Services.AddCors(setup => { 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("*"); }); });