This commit is contained in:
parent
3e9426ebd0
commit
e7d4292d82
Binary file not shown.
Before Width: | Height: | Size: 324 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.3 MiB |
BIN
Buffer/lvy.png
BIN
Buffer/lvy.png
Binary file not shown.
Before Width: | Height: | Size: 494 KiB |
@ -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("Неверный тип файла");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
14
MinIOchat.cs
14
MinIOchat.cs
@ -7,14 +7,14 @@ namespace NeDvachAPI
|
||||
{
|
||||
public class MinIOchat
|
||||
{
|
||||
public static async Task<string> PictureUpload(string fileroute, string filename)
|
||||
public static async Task<JsonResult> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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("*");
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user