Compare commits

..

75 Commits

Author SHA1 Message Date
Simple_Not
3ac93279fb #VDK2CH-3 пробуем починку
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-30 20:41:52 +10:00
Simple_Not
764e625631 #VDK2CH-3 пробуем починку
Some checks reported errors
continuous-integration/drone/push Build was killed
2023-06-30 20:40:58 +10:00
Simple_Not
7c1c1c6824 cors?
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 13:30:52 +10:00
Simple_Not
ff72c9cd87 cors?
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 13:25:14 +10:00
Simple_Not
f7d00555c1 cors?
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 13:19:17 +10:00
Simple_Not
6849892075 cors?
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 13:05:22 +10:00
Simple_Not
820e2d31a9 cors?
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 12:59:09 +10:00
Simple_Not
2b1a229623 Merge branch 'master' of http://git.vdk2ch.ru:3000/RakVhalate/2chBackAPI
All checks were successful
continuous-integration/drone/push Build is passing
2023-06-20 12:21:05 +10:00
Simple_Not
7637a40eb6 cors? 2023-06-20 11:58:33 +10:00
33eb50146e 88
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-30 11:02:30 +10:00
5bc7cceb5b 148
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-29 22:58:53 +10:00
af0d4a29ee 228
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-29 22:49:17 +10:00
8267f83243 123
All checks were successful
continuous-integration/drone/push Build is passing
2023-01-29 22:40:06 +10:00
e16d6258c3 Previev Sorting Algorytm
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-21 12:06:10 +05:00
ecc3a4d321 123
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-20 18:45:22 +05:00
cccd45caa7 small changes
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-14 20:32:54 +05:00
2d853eaa02 Resize now keeps aspect ratio.
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-13 22:50:24 +05:00
35139d66a2 Refactoring
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-13 19:18:23 +05:00
34a625361e Изменил(а) на 'docker-compose.yml'
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-09 10:31:45 -05:00
884d994011 12345
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 23:52:08 +10:00
f76d894e4e Linux
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 21:16:42 +10:00
98e7b4e22e `1234
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 21:14:26 +10:00
0b4caa20d5 222
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 21:00:49 +10:00
2605b5d5a8 111
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 20:56:45 +10:00
1baac63e22 123
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 20:55:18 +10:00
557a74ca21 libconfig
Some checks failed
continuous-integration/drone/push Build is failing
2022-12-07 20:46:46 +10:00
388762f34f cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 20:35:52 +10:00
2f90c3fe40 Cors?
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 20:13:30 +10:00
d76a46a083 Cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 20:07:41 +10:00
32bb6d34e0 Thumbnail feature.
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-07 19:55:18 +10:00
10db158595 3456436
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-01 22:55:49 +10:00
d3a6161978 123
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-01 22:52:36 +10:00
67e43f4bc1 COЯS
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-01 22:08:11 +10:00
rak
c5063b8c04 did some
All checks were successful
continuous-integration/drone/push Build is passing
2022-12-01 21:40:53 +10:00
800a8ee1b9 Cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-25 22:42:57 +10:00
a4b72664fd Added some folders.
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-25 22:40:17 +10:00
50a3c94af8 added buffer and some error handling
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-25 12:37:26 +10:00
f791625102 Added threads listing controller
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-24 12:56:07 +10:00
f8038d9587 cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-22 18:05:34 +10:00
6da7a84cab added Ip logging
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-22 18:03:38 +10:00
31ca387339 cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-20 12:37:36 +10:00
2c984eaf0b new structure
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-18 14:46:31 +10:00
4aab13329f added board name parameter
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-12 03:10:57 +10:00
f3a5b28a99 no sec
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-03 20:23:56 +10:00
e7d4292d82 Image upload function
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-03 15:13:58 +10:00
3e9426ebd0 adding picture posting controller
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 17:42:11 +10:00
f83b76b2de adding picture posting controller
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 17:39:39 +10:00
b2cf921b9a fix
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-02 01:55:21 +10:00
3f580831a1 some scretches about file upload
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 01:46:58 +10:00
016e5803a9 some scretches about file upload 2022-11-02 01:46:07 +10:00
b9d7f50cc9 some scretches about file upload 2022-11-02 01:45:42 +10:00
Simple_Not
10b0890915 not getting ip addresses
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 01:00:29 +10:00
Simple_Not
0dc55aa9df getting ip addresses
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 00:58:07 +10:00
Simple_Not
5228f74c49 getting ip addresses
Some checks failed
continuous-integration/drone/push Build is failing
2022-11-02 00:56:19 +10:00
Simple_Not
86d3e2d9b5 timestamp type fix
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 14:11:01 +10:00
Simple_Not
b3768afb91 back to VDK
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:58:32 +10:00
Simple_Not
c1edc35c28 backing up my SKOBKA
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:56:11 +10:00
Simple_Not
2c485665b0 send date
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:51:57 +10:00
Simple_Not
218484a0f1 send date
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:51:09 +10:00
Simple_Not
be02399eb0 send date
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:48:50 +10:00
Simple_Not
07de4fa972 recieve date
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 13:40:06 +10:00
Simple_Not
26df236ae7 recieve date
Some checks failed
continuous-integration/drone/push Build is failing
2022-10-29 13:38:24 +10:00
Simple_Not
c4e266450d ff
Some checks failed
continuous-integration/drone/push Build is failing
2022-10-29 13:37:47 +10:00
Simple_Not
75b9958b97 asdf 2022-10-29 13:36:25 +10:00
7737725327 HotFix
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 04:34:35 +10:00
b04841fb1d Added Timestamp Feature
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-29 04:20:10 +10:00
8b0c988a7f _
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-20 22:35:08 +10:00
2a71885a85 some fix
Some checks failed
continuous-integration/drone/push Build is failing
2022-10-20 22:28:12 +10:00
06d9835406 some fix 2022-10-20 22:24:04 +10:00
Simple_Not
0efca3b0b5 cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-20 13:58:39 +10:00
Simple_Not
572c1c699f cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-20 13:57:11 +10:00
Simple_Not
8d3839b53d cors
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-20 13:55:34 +10:00
Simple_Not
99c0e0c410 post list
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-20 11:42:03 +10:00
Simple_Not
3d5c349288 post list
Some checks failed
continuous-integration/drone/push Build is failing
2022-10-20 11:41:05 +10:00
Simple_Not
1b60bf776f post list
Some checks failed
continuous-integration/drone/push Build is failing
2022-10-20 11:39:58 +10:00
40 changed files with 1776 additions and 247 deletions

View File

@@ -22,6 +22,7 @@ steps:
commands:
- cd /usr/share/$DRONE_REPO_NAME
- dotnet build
- name: recreate dist folder
commands:
- rm -rf /usr/share/$DRONE_REPO_NAME/dist

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
obj
bin
dist
dist

12
.idea/NeDvachAPI.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/NeDvachAPI.iml" filepath="$PROJECT_DIR$/.idea/NeDvachAPI.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

45
.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="afeb71ff-aaed-4a5b-8ece-55d4f78fc0c7" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2HppPxAx0SVc4HMyQfWgDlfmGn2" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="afeb71ff-aaed-4a5b-8ece-55d4f78fc0c7" name="Changes" comment="" />
<created>1668991859805</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1668991859805</updated>
<workItem from="1668991862249" duration="12000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

File diff suppressed because it is too large Load Diff

BIN
.vs/NeDvachAPI/v17/.suo Normal file

Binary file not shown.

BIN
.vs/NeDvachAPI/v17/.wsuo Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\appsettings.json",
"PreviewInSolutionExplorer": false
}

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

View 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!");
}
}
}

View 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 ;
}
}
}

View File

@@ -0,0 +1,50 @@
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)
{
string receivedFileName = PostPicture.FileName;
string fName = Path.GetFileNameWithoutExtension(receivedFileName);
string fExtention = Path.GetExtension(receivedFileName);
string previevFileName = fName + 's' + fExtention;
Console.WriteLine("Расширение файла: " + fExtention);
if (ImageController.CheckExtention(fExtention)) //file type check
{
///Local Buffer File Part
string filePath;
string previevPath;
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
previevPath = Directory.GetCurrentDirectory() + "\\Buffer\\" + previevFileName;
//creating original file buffer
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
PostPicture.CopyTo(picBuffer);
picBuffer.Close();
//resizing
ImageController.ResizeImage(filePath, previevPath, 300, 400);
///MinIo part
await MinIOchat.PictureUpload(previevPath, receivedFileName, "thread-pics-small"); //upload thumbnail
JsonResult picAdress = new(await MinIOchat.PictureUpload(filePath, receivedFileName, "thread-pics")); //upload fullsize
Console.WriteLine("Загружен файл:" + "http://static.vdk2ch.ru:15555/thread-pics/" + receivedFileName);
return picAdress;
}
else return new JsonResult("Неверный тип файла");
}
}
}

View File

@@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using NeDvachAPI.BufferControllers;
using NeDvachAPI.DBControllers;
using NeDvachAPI.Models;
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;
if(ReceivedPost.Text.Length == 0)
{
return new JsonResult("Вы отправили пустое сообщение!");
}
try
{
DBchat.SendPost(ReceivedPost);
APIThreadBuffer.RefreshThread(ReceivedPost.Thread_Id);
return new JsonResult("Сообщение успешно добавлено.");
}
catch
{
return new JsonResult("Произошла ошибка постинга");
}
}
}
}

View 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;
}
}
}

24
AuthInfo.cs Normal file
View File

@@ -0,0 +1,24 @@
namespace NeDvachAPI
{
public class AuthInfo
{
public class MinIo
{
public static string endpoint = "static.vdk2ch.ru:15555";
public static string bucketName = "thread-pics thread-pics-small";
public static string username = "admin";
public static string password = "password2ch";
}
public class DB
{
public static string Host = "postgres.vdk2ch.ru";
public static string User = "postgres";
public static string DBname = "dvaach";
public static string Password = "postgres";
public static string Port = "5432";
}
}
}

View File

@@ -0,0 +1,82 @@
using NeDvachAPI.DBControllers;
using NeDvachAPI.Models;
namespace NeDvachAPI.BufferControllers
{
public class APIThreadBuffer
{
private static List<Post>[] ThreadsPrewievs = new List<Post>[0];
private static List<Post>[] Threads = new List<Post>[0];
public static void WriteThreadPreviewsBuffer(List<Post> OPPostsToWrite) //add list of OP-posts and last post to buffer
{
for(int pos = 0; pos < OPPostsToWrite.Count; pos ++)
{
var deb = new List<Post>();
deb.Add(OPPostsToWrite[pos]);
ThreadsPrewievs = ThreadsPrewievs.Append(deb).ToArray();
}
}
public static void AppendToThreadPreviews(int index,Post toAppend)
{
ThreadsPrewievs[index].Add(toAppend);
}
public static List<Post>[] GetThreadPreviews()
{
return ThreadsPrewievs;
}
public static void UpdateThreadsPreviews(int threadId)
{
Console.WriteLine("Пытаюсь обновить превью треда " + threadId);
var newPreview = new List<Post>();
newPreview.Add(ThreadsPrewievs[threadId -1][0]);
int targetLength = APIThreadBuffer.GetThreadLength(threadId - 1);
for (int lastofthree = targetLength- 2; lastofthree <= targetLength; lastofthree ++)
{
newPreview.Add(GetSinglePost(threadId - 1,lastofthree));
}
ThreadsPrewievs[threadId -1] = newPreview;
}
public static void AppendThreadsBuffer(List<Post> ThreadToAdd) //add thread's posts from DB to buffer
{
Threads = Threads.Append(ThreadToAdd).ToArray();
}
public static int GetThreadLength(int threadId)
{
return Threads[threadId].Count;
}
public static List<Post> GetThread(int threadId)
{
if (threadId < Threads.Length + 1 & threadId != 0)
{
return Threads[threadId - 1];
}
else return null;
}
public static Post GetSinglePost(int thread, int postPosition)
{
List<Post> postsList = Threads[thread];
return postsList[postPosition-1];
}
public static void UpdateThreadPosts(int threadId)
{
Console.WriteLine("Пытаюсь обновить тред " + threadId);
Threads[threadId - 1] = DBchat.PostsList("b", threadId);
}
public static void RefreshThread(int threadId)
{
UpdateThreadPosts(threadId);
UpdateThreadsPreviews(threadId);
}
}
}

View File

@@ -0,0 +1,15 @@
using NeDvachAPI.Models;
using Npgsql;
namespace NeDvachAPI.DBControllers
{
public class BanList
{
public static string[] GetBanned()
{
string[] bannedIPs = new string[0];
//
return bannedIPs;
}
}
}

View File

@@ -0,0 +1,33 @@
using NeDvachAPI.DBControllers;
using NeDvachAPI.Models;
namespace NeDvachAPI.BufferControllers
{
public class BufferFill
{
public static bool FillBuffer(string board) //method to get buffer of information, which is being ran while API is started
{
List<Post> Previews = DBchat.ThreadsList(board);
APIThreadBuffer.WriteThreadPreviewsBuffer(Previews);
Console.WriteLine("Adding OP-posts to buffer");
for (int threadId = 1; threadId <= Previews.Count; threadId++)
{
APIThreadBuffer.AppendThreadsBuffer(DBchat.PostsList(board, threadId));
}
Console.WriteLine($@"Buffering threads {1} to {Previews.Count}.");
for (int preview = 0; preview < Previews.Count; preview++)
{
int targetLength = APIThreadBuffer.GetThreadLength(preview);
for (int lastofthree = targetLength- 2; lastofthree <= targetLength; lastofthree ++)
{
APIThreadBuffer.AppendToThreadPreviews(preview,APIThreadBuffer.GetSinglePost(preview,lastofthree));
}
}
return true;
}
}
}

View File

@@ -1,19 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace NeDvachAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class ListController : ControllerBase
{
[HttpGet(Name = "GetPosts")]
public string Get()
{
Post[] posts = DBchat.DbList();
string postsJson = JsonSerializer.Serialize(posts);
return postsJson ;
}
}
}

View File

@@ -1,16 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace NeDvachAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class PostToController : ControllerBase
{
[HttpPost(Name = "PostPosts")]
public void ReceivePost([FromBody] Post ReceivedPost)
{
DBchat.SendPost(ReceivedPost);
}
}
}

View File

@@ -1,17 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace NeDvachAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class TestPostingController : ControllerBase
{
[HttpPost]
public int Area(int altitude , int height)
{
//DBchat.SendPost(ReceivedPost);
return altitude+height;
}
}
}

211
DBControllers/DBchat.cs Normal file
View File

@@ -0,0 +1,211 @@
using NeDvachAPI.Models;
using Npgsql;
namespace NeDvachAPI.DBControllers
{
public class DBchat
{
public static List<Post> PostsList(string boardName, int thread)
{
List<Post> posts = new List<Post>();
string connString =
string.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
AuthInfo.DB.Host,
AuthInfo.DB.User,
AuthInfo.DB.DBname,
AuthInfo.DB.Port,
AuthInfo.DB.Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
using (var command = new NpgsqlCommand($@"
SELECT * FROM
(
SELECT post_id, post_text, content, post_timestamp
FROM posts
WHERE thread_id = {thread}
ORDER BY post_id DESC
) subquery
ORDER BY post_id ASC", conn))
{
var reader = command.ExecuteReader();
while (reader.Read())
{
Post receivedPost = new()
{
Id = reader.GetInt32(0),
Text = reader.GetString(1),
ImgURL = reader.IsDBNull(2) ? null : reader.GetFieldValue<string[]>(2),
Timestamp = reader.GetString(3)
};
posts.Add(receivedPost);
}
reader.Close();
}
}
return posts;
}
public static List<Post> ThreadsList(string boardName)
{
List<Post> posts = new List<Post>();
string connString =
string.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
AuthInfo.DB.Host,
AuthInfo.DB.User,
AuthInfo.DB.DBname,
AuthInfo.DB.Port,
AuthInfo.DB.Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
using (var command = new NpgsqlCommand($@"
SELECT * FROM
(
SELECT post_id, post_text, content, post_timestamp, is_op, thread_id
FROM posts
WHERE
is_op = {true}
ORDER BY thread_id DESC
) subquery
ORDER BY thread_id ASC", conn))
{
var reader = command.ExecuteReader();
while (reader.Read())
{
Post receivedPost = new()
{
Id = reader.GetInt32(0),
Text = reader.GetString(1),
ImgURL = reader.IsDBNull(2) ? null : reader.GetFieldValue<string[]>(2),
Timestamp = reader.GetString(3),
Is_OP = reader.GetBoolean(4),
Thread_Id = reader.GetInt32(5)
};
posts.Add(receivedPost);
}
reader.Close();
}
}
return posts;
}
public static void DbUpdate(string id, string text)
{
string connString =
string.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
AuthInfo.DB.Host,
AuthInfo.DB.User,
AuthInfo.DB.DBname,
AuthInfo.DB.Port,
AuthInfo.DB.Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
using (var command = new NpgsqlCommand("UPDATE dvach " +
"SET post = @postText WHERE post_id = @ID", conn))
{
command.Parameters.AddWithValue("ID", int.Parse(id));
command.Parameters.AddWithValue("postText", text);
int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine(string.Format("Number of rows updated={0}", nRows));
}
}
Console.WriteLine("Данные обновлены!");
Console.ReadLine();
}
public static void SendPost(Post postToSend) //sending post to database
{
string connString =
string.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
AuthInfo.DB.Host,
AuthInfo.DB.User,
AuthInfo.DB.DBname,
AuthInfo.DB.Port,
AuthInfo.DB.Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
int postNum = 14;
using (var command = new NpgsqlCommand(@"
INSERT INTO posts (post_id, post_text, post_number, content, thread_id, auth_ip, is_op, post_timestamp)
VALUES (
DEFAULT,
@postText,
@postNum,
@postImgUrl,
@threadId,
@ip,
false,
(
SELECT date_trunc(
'second',
(now()::timestamp(0) AT TIME ZONE 'UTC+10')::TIMESTAMP
)
) )", conn))
{
command.Parameters.AddWithValue("postText", postToSend.Text);
command.Parameters.AddWithValue("postNum", postNum);
command.Parameters.AddWithValue("postImgUrl", postToSend.ImgURL);
command.Parameters.AddWithValue("threadId", postToSend.Thread_Id);
command.Parameters.AddWithValue("ip", postToSend.Ip);
int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine("Добавлен пост с текстом " + postToSend.Text + " номером " + 22);
}
}
}
public static void DeletePost(string idToDel) //удалялка
{
string connString =
string.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
AuthInfo.DB.Host,
AuthInfo.DB.User,
AuthInfo.DB.DBname,
AuthInfo.DB.Port,
AuthInfo.DB.Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
using (var command = new NpgsqlCommand(@"
DELETE FROM dvach
WHERE post_id = @ID", conn))
{
command.Parameters.AddWithValue("ID", int.Parse(idToDel)); ;
int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine(string.Format("Number of rows updated={0}", nRows));
}
}
Console.WriteLine("Данные удалены!");
Console.ReadLine();
}
}
}

View File

@@ -0,0 +1,43 @@
using SkiaSharp;
namespace NeDvachAPI.DBControllers
{
public class ImageController
{
public static bool CheckExtention(string extentionToCheck)
{
var supportedTypes = new[] { ".jpg", ".png", ".jpeg" };
if (supportedTypes.Contains(extentionToCheck.ToLower()))
{
return true;
}
else return false;
}
public static bool ResizeImage(string picPath, string smallPath, int width, int height)
{
var bitmap = SKBitmap.Decode(picPath);
double ratio = Math.Max((double)bitmap.Width / (double)width , (double)bitmap.Height / (double)height);
int targetWidth = (int)(bitmap.Width/ ratio);
int targetHeight = (int)(bitmap.Height / ratio);
Console.WriteLine($"Ресайзим картинку до {targetWidth} ширины и {targetHeight} высоты.");
var dstInfo = new SKImageInfo(targetWidth , targetHeight);
var image = SKImage.FromBitmap(bitmap.Resize(dstInfo, SKFilterQuality.Medium));
var data = image.Encode(SKEncodedImageFormat.Jpeg, 90);
using (var stream = new FileStream(smallPath, FileMode.Create, FileAccess.Write))
data.SaveTo(stream);
data.Dispose();
image.Dispose();
bitmap.Dispose();
return true;
}
}
}

View File

@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Mvc;
using Minio.DataModel;
using Minio;
using System.Security.Cryptography;
namespace NeDvachAPI.DBControllers
{
public class MinIOchat
{
public static async Task<JsonResult> PictureUpload(string fileroute, string filename, string bucket)
{
MinioClient DvachIo = new MinioClient()
.WithEndpoint(AuthInfo.MinIo.endpoint)
.WithCredentials(AuthInfo.MinIo.username, AuthInfo.MinIo.password)
//.WithSSL()
.Build();
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
PutObjectArgs putObjectArgs = new PutObjectArgs()
.WithBucket(bucket)
.WithObject(filename)
.WithFileName(fileroute)
.WithContentType("image/png");
//.WithServerSideEncryption(ssec);
await DvachIo.PutObjectAsync(putObjectArgs);
GC.Collect();
GC.WaitForPendingFinalizers();
File.Delete(fileroute);
return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename);
}
}
}

146
DBchat.cs
View File

@@ -1,146 +0,0 @@
using Npgsql;
namespace NeDvachAPI
{
public class DBchat
{
// Obtain connection string information from the portal
private static string Host = "postgres.vdk2ch.ru";
private static string User = "postgres";
private static string DBname = "postgres";
private static string Password = "postgres";
private static string Port = "5432";
public static Post[] DbList()
{
// Build connection string using parameters from portal
//Post[] posts = new Post[10];
List<Post> posts = new List<Post>();
//int postCount = 0;
string received = "";
string connString =
String.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
Host,
User,
DBname,
Port,
Password);
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
// using ( var command = new NpgsqlCommand(@"
// SELECT * FROM
// (SELECT post_id, substring(post,1,200)
// FROM dvach
// ORDER BY post_id DESC
// limit 10
// )
subquery ORDER BY post_id ASC", conn) )
using ( var command = new NpgsqlCommand(@"
SELECT * FROM
(
SELECT post_id, post
FROM dvach
ORDER BY post_id DESC
) subquery
ORDER BY post_id ASC", conn) )
{
var reader = command.ExecuteReader();
while (reader.Read())
{
//received +=(
//string.Format(
//"#{0}: {1}" + "\n",
// reader.GetInt32(0).ToString(),
//reader.GetString(1)
//)
//);
Post receivedPost = new()
{
Date = DateTime.Now,
Id = reader.GetInt32(0),
Text = reader.GetString(1)
};
posts.Add(receivedPost);
//posts[postCount] = receivedPost;
//postCount++;
}
reader.Close();
}
}
return posts;
}
public static void DbUpdate(string id, string text)
{
// Build connection string using parameters from portal
string connString =
String.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
Host,
User,
DBname,
Port,
Password);
using (var conn = new NpgsqlConnection(connString))
{
//Console.Out.WriteLine("Opening connection");
conn.Open();
using (var command = new NpgsqlCommand("UPDATE dvach " +
"SET post = @postText WHERE post_id = @ID", conn))
{
command.Parameters.AddWithValue("ID", int.Parse(id));
command.Parameters.AddWithValue("postText", text);
int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows));
}
}
Console.WriteLine("Данные обновлены!");
Console.ReadLine();
}
public static void SendPost(Post postToSend)
{
// Build connection string using parameters from portal
//
string connString =
String.Format(
"Server={0}; User Id={1}; Database={2}; Port={3}; Password={4};SSLMode=Prefer",
Host,
User,
DBname,
Port,
Password);
using (var conn = new NpgsqlConnection(connString))
{
Console.Out.WriteLine("Opening connection");
conn.Open();
using (var command = new NpgsqlCommand(@"
INSERT INTO dvach " + @"(post_id, post)
VALUES (DEFAULT, @postText)", conn))
{
command.Parameters.AddWithValue("postText", postToSend.Text);
int nRows = command.ExecuteNonQuery();
Console.Out.WriteLine(String.Format("Number of rows updated={0}", nRows));
}
}
Console.WriteLine("С добавлением закончено");
}
}
}

View File

@@ -1,5 +1,7 @@
FROM mcr.microsoft.com/dotnet/aspnet:6.0
ADD dist /app
WORKDIR /app

14
Models/Post.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace NeDvachAPI.Models
{
public class Post
{
public string Timestamp { get; set; }
public int Id { get; set; }
public string Text { get; set; }
public string[]? ImgURL { get; set; }
public int Thread_Id { get; set; }
public bool Is_OP { get; set; }
public bool Is_Deleted { get; set; }
public string? Ip { get; set; }
}
}

View File

@@ -7,8 +7,17 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="6.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" />
<PackageReference Include="Minio" Version="4.0.6" />
<PackageReference Include="Npgsql" Version="7.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Buffer\" />
</ItemGroup>
</Project>

View File

@@ -3,5 +3,9 @@
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<ActiveDebugProfile>NeDvachAPI</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

11
Post.cs
View File

@@ -1,11 +0,0 @@
namespace NeDvachAPI
{
public class Post
{
public DateTime Date { get; set; }
public int Id { get; set; }
public string Text { get; set; }
}
}

View File

@@ -1,32 +1,31 @@
using NeDvachAPI.BufferControllers;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddCors(setup =>
{
setup.AddDefaultPolicy(policyBuilder =>
{
policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200");
});
policyBuilder.SetIsOriginAllowed(origin => new Uri(origin).Host == "localhost");
//policyBuilder.WithOrigins("http://www.vdk2ch.ru:4200").WithMethods("GET", "POST").WithHeaders("*");
policyBuilder.WithOrigins("https://www.vdk2ch.ru").WithMethods("GET", "POST").WithHeaders("*");
//policyBuilder.WithOrigins("http://localhost:4200").WithMethods("GET", "POST").WithHeaders("*");
});
});
//builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
//app.UseSwagger();
//app.UseSwaggerUI();
}
//app.UseHttpsRedirection();
}
app.UseCors();
@@ -34,4 +33,12 @@ app.UseAuthorization();
app.MapControllers();
app.Run();
app.UseHttpsRedirection();
if (BufferFill.FillBuffer("b"))
{
Console.WriteLine("Ready for work.");
app.Run();
}
else Console.WriteLine("Ошибка буферизации, проверьте доступность базы данных.");

View File

@@ -1,4 +1,22 @@
{
{
"profiles": {
"NeDvachAPI": {
"commandName": "Project",
"launchUrl": "Home",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "https://0.0.0.0:7141"
},
"IIS Express": {
"commandName": "IISExpress",
"launchUrl": "Home",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
},
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
@@ -7,25 +25,5 @@
"applicationUrl": "http://0.0.0.0:31551",
"sslPort": 44346
}
},
"profiles": {
"NeDvachAPI": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "Home",
"applicationUrl": "http://0.0.0.0:7141;http://0.0.0.0:5141",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "Home",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
}

View File

@@ -1,4 +1,5 @@
{
"https_port": 443,
"Logging": {
"LogLevel": {
"Default": "Debug",

View File

@@ -10,3 +10,8 @@ services:
restart: always
ports:
- "5000:80"
# logging:
# driver: "gelf"
# options:
# gelf-address: "udp://graylog.vdk2ch.ru:12201"
# tag: "backend-logs"

5
libman.json Normal file
View File

@@ -0,0 +1,5 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": []
}

0
newFile.txt Normal file
View File