Compare commits
	
		
			108 Commits
		
	
	
		
			3700aea681
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 3ac93279fb | ||
|  | 764e625631 | ||
|  | 7c1c1c6824 | ||
|  | ff72c9cd87 | ||
|  | f7d00555c1 | ||
|  | 6849892075 | ||
|  | 820e2d31a9 | ||
|  | 2b1a229623 | ||
|  | 7637a40eb6 | ||
| 33eb50146e | |||
| 5bc7cceb5b | |||
| af0d4a29ee | |||
| 8267f83243 | |||
| e16d6258c3 | |||
| ecc3a4d321 | |||
| cccd45caa7 | |||
| 2d853eaa02 | |||
| 35139d66a2 | |||
| 34a625361e | |||
| 884d994011 | |||
| f76d894e4e | |||
| 98e7b4e22e | |||
| 0b4caa20d5 | |||
| 2605b5d5a8 | |||
| 1baac63e22 | |||
| 557a74ca21 | |||
| 388762f34f | |||
| 2f90c3fe40 | |||
| d76a46a083 | |||
| 32bb6d34e0 | |||
| 10db158595 | |||
| d3a6161978 | |||
| 67e43f4bc1 | |||
|  | c5063b8c04 | ||
| 800a8ee1b9 | |||
| a4b72664fd | |||
| 50a3c94af8 | |||
| f791625102 | |||
| f8038d9587 | |||
| 6da7a84cab | |||
| 31ca387339 | |||
| 2c984eaf0b | |||
| 4aab13329f | |||
| f3a5b28a99 | |||
| e7d4292d82 | |||
| 3e9426ebd0 | |||
| f83b76b2de | |||
| b2cf921b9a | |||
| 3f580831a1 | |||
| 016e5803a9 | |||
| b9d7f50cc9 | |||
|  | 10b0890915 | ||
|  | 0dc55aa9df | ||
|  | 5228f74c49 | ||
|  | 86d3e2d9b5 | ||
|  | b3768afb91 | ||
|  | c1edc35c28 | ||
|  | 2c485665b0 | ||
|  | 218484a0f1 | ||
|  | be02399eb0 | ||
|  | 07de4fa972 | ||
|  | 26df236ae7 | ||
|  | c4e266450d | ||
|  | 75b9958b97 | ||
| 7737725327 | |||
| b04841fb1d | |||
| 8b0c988a7f | |||
| 2a71885a85 | |||
| 06d9835406 | |||
|  | 0efca3b0b5 | ||
|  | 572c1c699f | ||
|  | 8d3839b53d | ||
|  | 99c0e0c410 | ||
|  | 3d5c349288 | ||
|  | 1b60bf776f | ||
|  | e445c2bda1 | ||
|  | f5349db697 | ||
|  | 63330d5fc0 | ||
|  | 806c0eaf76 | ||
|  | 7dad7f6aae | ||
|  | 13acfdc7da | ||
|  | cd5d50f06b | ||
|  | 5fee059b51 | ||
|  | c661201812 | ||
|  | 52b36a98a7 | ||
|  | 30ecde0fbe | ||
|  | 87a0feb11b | ||
|  | ca5a38a522 | ||
|  | d008455c4c | ||
|  | 27793d764d | ||
|  | f7a3d9f065 | ||
|  | 7729cae185 | ||
| eac13fb2d3 | |||
| e73f0b04ec | |||
|  | 9f6b892831 | ||
|  | 8788809c5a | ||
| beb906a243 | |||
| b6b9f0500c | |||
| 142090c588 | |||
| 0924db0386 | |||
|  | da2899bd90 | ||
|  | 73c0df27dd | ||
| a5fcbaf4ea | |||
| e057b532de | |||
| 4a7929b8db | |||
| a5aef87f79 | |||
| b010d0c056 | |||
| 59928c5ebc | 
							
								
								
									
										38
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								.drone.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | --- | ||||||
|  | kind: pipeline | ||||||
|  | type: exec | ||||||
|  | name: default | ||||||
|  |  | ||||||
|  | platform: | ||||||
|  |   os: linux | ||||||
|  |   arch: amd64 | ||||||
|  |  | ||||||
|  | clone: | ||||||
|  |   # убрано так как сейчас не тестим ничего предварительно а сразу тянем в директорию  | ||||||
|  |   disable: true | ||||||
|  |  | ||||||
|  | steps: | ||||||
|  | - name: pull into the folduh | ||||||
|  |   commands: | ||||||
|  |   - cd /usr/share/$DRONE_REPO_NAME | ||||||
|  |   - git pull | ||||||
|  | - name: build | ||||||
|  |   environment: | ||||||
|  |     DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||||||
|  |   commands: | ||||||
|  |   - cd /usr/share/$DRONE_REPO_NAME | ||||||
|  |   - dotnet build | ||||||
|  |  | ||||||
|  | - name: recreate dist folder | ||||||
|  |   commands: | ||||||
|  |   - rm -rf /usr/share/$DRONE_REPO_NAME/dist | ||||||
|  |   - mkdir -p /usr/share/$DRONE_REPO_NAME/dist | ||||||
|  |   - mv -f /usr/share/$DRONE_REPO_NAME/bin/Debug/net6.0/* /usr/share/$DRONE_REPO_NAME/dist | ||||||
|  | - name: docker-compose-rebuild | ||||||
|  |   commands: | ||||||
|  |   - cd /usr/share/$DRONE_REPO_NAME | ||||||
|  |   - docker compose up -d --build | ||||||
|  | - name: cleanup | ||||||
|  |   commands: | ||||||
|  |   - rm -rf /usr/share/$DRONE_REPO_NAME/bin /usr/share/$DRONE_REPO_NAME/obj | ||||||
|  |  | ||||||
							
								
								
									
										0
									
								
								gitignore → .gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										0
									
								
								gitignore → .gitignore
									
									
									
									
										vendored
									
									
								
							
							
								
								
									
										12
									
								
								.idea/NeDvachAPI.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								.idea/NeDvachAPI.iml
									
									
									
										generated
									
									
									
										Normal 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
									
								
							
							
						
						
									
										8
									
								
								.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal 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
									
								
							
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal 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
									
								
							
							
						
						
									
										45
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
										Normal 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> | ||||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										0
									
								
								.vs/NeDvachAPI/FileContentIndex/read.lock
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								.vs/NeDvachAPI/FileContentIndex/read.lock
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1026
									
								
								.vs/NeDvachAPI/config/applicationhost.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1026
									
								
								.vs/NeDvachAPI/config/applicationhost.config
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								.vs/NeDvachAPI/v17/.suo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.vs/NeDvachAPI/v17/.suo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								.vs/NeDvachAPI/v17/.wsuo
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.vs/NeDvachAPI/v17/.wsuo
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										7
									
								
								.vs/VSWorkspaceState.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.vs/VSWorkspaceState.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | { | ||||||
|  |   "ExpandedNodes": [ | ||||||
|  |     "" | ||||||
|  |   ], | ||||||
|  |   "SelectedNode": "\\appsettings.json", | ||||||
|  |   "PreviewInSolutionExplorer": false | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								.vs/slnx.sqlite
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.vs/slnx.sqlite
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										35
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | { | ||||||
|  |     "version": "0.2.0", | ||||||
|  |     "configurations": [ | ||||||
|  |         { | ||||||
|  |             // Use IntelliSense to find out which attributes exist for C# debugging | ||||||
|  |             // Use hover for the description of the existing attributes | ||||||
|  |             // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md | ||||||
|  |             "name": ".NET Core Launch (web)", | ||||||
|  |             "type": "coreclr", | ||||||
|  |             "request": "launch", | ||||||
|  |             "preLaunchTask": "build", | ||||||
|  |             // If you have changed target frameworks, make sure to update the program path. | ||||||
|  |             "program": "${workspaceFolder}/bin/Debug/net6.0/NeDvachAPI.dll", | ||||||
|  |             "args": [], | ||||||
|  |             "cwd": "${workspaceFolder}", | ||||||
|  |             "stopAtEntry": false, | ||||||
|  |             // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser | ||||||
|  |             "serverReadyAction": { | ||||||
|  |                 "action": "openExternally", | ||||||
|  |                 "pattern": "\\bNow listening on:\\s+(https?://\\S+)" | ||||||
|  |             }, | ||||||
|  |             "env": { | ||||||
|  |                 "ASPNETCORE_ENVIRONMENT": "Development" | ||||||
|  |             }, | ||||||
|  |             "sourceFileMap": { | ||||||
|  |                 "/Views": "${workspaceFolder}/Views" | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "name": ".NET Core Attach", | ||||||
|  |             "type": "coreclr", | ||||||
|  |             "request": "attach" | ||||||
|  |         } | ||||||
|  |     ] | ||||||
|  | } | ||||||
							
								
								
									
										41
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | |||||||
|  | { | ||||||
|  |     "version": "2.0.0", | ||||||
|  |     "tasks": [ | ||||||
|  |         { | ||||||
|  |             "label": "build", | ||||||
|  |             "command": "dotnet", | ||||||
|  |             "type": "process", | ||||||
|  |             "args": [ | ||||||
|  |                 "build", | ||||||
|  |                 "${workspaceFolder}/NeDvachAPI.csproj", | ||||||
|  |                 "/property:GenerateFullPaths=true", | ||||||
|  |                 "/consoleloggerparameters:NoSummary" | ||||||
|  |             ], | ||||||
|  |             "problemMatcher": "$msCompile" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "label": "publish", | ||||||
|  |             "command": "dotnet", | ||||||
|  |             "type": "process", | ||||||
|  |             "args": [ | ||||||
|  |                 "publish", | ||||||
|  |                 "${workspaceFolder}/NeDvachAPI.csproj", | ||||||
|  |                 "/property:GenerateFullPaths=true", | ||||||
|  |                 "/consoleloggerparameters:NoSummary" | ||||||
|  |             ], | ||||||
|  |             "problemMatcher": "$msCompile" | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |             "label": "watch", | ||||||
|  |             "command": "dotnet", | ||||||
|  |             "type": "process", | ||||||
|  |             "args": [ | ||||||
|  |                 "watch", | ||||||
|  |                 "run", | ||||||
|  |                 "--project", | ||||||
|  |                 "${workspaceFolder}/NeDvachAPI.csproj" | ||||||
|  |             ], | ||||||
|  |             "problemMatcher": "$msCompile" | ||||||
|  |         } | ||||||
|  |     ] | ||||||
|  | } | ||||||
							
								
								
									
										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 ; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										50
									
								
								APIControllers/PictureUpload.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								APIControllers/PictureUpload.cs
									
									
									
									
									
										Normal 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("Неверный тип файла"); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |          | ||||||
|  |     } | ||||||
|  |      | ||||||
|  | } | ||||||
							
								
								
									
										34
									
								
								APIControllers/PostPost.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								APIControllers/PostPost.cs
									
									
									
									
									
										Normal 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("Произошла ошибка постинга"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										24
									
								
								AuthInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								AuthInfo.cs
									
									
									
									
									
										Normal 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"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										82
									
								
								BufferControllers/APIThreadBuffer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								BufferControllers/APIThreadBuffer.cs
									
									
									
									
									
										Normal 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); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								BufferControllers/AccessController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								BufferControllers/AccessController.cs
									
									
									
									
									
										Normal 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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										33
									
								
								BufferControllers/BufferFill.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								BufferControllers/BufferFill.cs
									
									
									
									
									
										Normal 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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -1,18 +0,0 @@ | |||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
| using System.Text.Json; |  | ||||||
|  |  | ||||||
| namespace NeDvachAPI.Controllers |  | ||||||
| { |  | ||||||
|     [ApiController] |  | ||||||
|     [Route("[controller]")] |  | ||||||
|     public class HomeController : ControllerBase |  | ||||||
|     { |  | ||||||
|         [HttpGet(Name = "GetPosts")] |  | ||||||
|         public string Get() |  | ||||||
|         { |  | ||||||
|             Post[] posts  = DBchat.DbList(); |  | ||||||
|             string postsJson = JsonSerializer.Serialize(posts); |  | ||||||
|             return postsJson ; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,17 +0,0 @@ | |||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
| using System.Text.Json; |  | ||||||
|  |  | ||||||
| namespace NeDvachAPI.Controllers |  | ||||||
| { |  | ||||||
|     [ApiController] |  | ||||||
|     [Route("[controller]")] |  | ||||||
|     public class PostToController : ControllerBase |  | ||||||
|     { |  | ||||||
|         [HttpGet(Name = "PostPosts")] |  | ||||||
|         public void ReceivePost(string postJson) |  | ||||||
|         { |  | ||||||
|             Post ReceivedPost = JsonSerializer.Deserialize<Post>(postJson); |  | ||||||
|             DBchat.SendPost(ReceivedPost); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										211
									
								
								DBControllers/DBchat.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										211
									
								
								DBControllers/DBchat.cs
									
									
									
									
									
										Normal 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(); | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										43
									
								
								DBControllers/ImageController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								DBControllers/ImageController.cs
									
									
									
									
									
										Normal 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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
							
								
								
									
										36
									
								
								DBControllers/MinIOchat.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								DBControllers/MinIOchat.cs
									
									
									
									
									
										Normal 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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										129
									
								
								DBchat.cs
									
									
									
									
									
								
							
							
						
						
									
										129
									
								
								DBchat.cs
									
									
									
									
									
								
							| @@ -1,129 +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]; |  | ||||||
|             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)) |  | ||||||
|                 { |  | ||||||
|  |  | ||||||
|                     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[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("С добавлением закончено"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										8
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | FROM mcr.microsoft.com/dotnet/aspnet:6.0 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ADD dist /app | ||||||
|  |  | ||||||
|  | WORKDIR /app | ||||||
|  | CMD ./NeDvachAPI | ||||||
							
								
								
									
										14
									
								
								Models/Post.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Models/Post.cs
									
									
									
									
									
										Normal 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; } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -7,8 +7,17 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Npgsql" Version="6.0.7" /> |     <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" /> | ||||||
|     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> |     <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> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -3,5 +3,9 @@ | |||||||
|   <PropertyGroup> |   <PropertyGroup> | ||||||
|     <Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID> |     <Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID> | ||||||
|     <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath> |     <Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath> | ||||||
|  |     <ActiveDebugProfile>NeDvachAPI</ActiveDebugProfile> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||||||
|  |     <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| </Project> | </Project> | ||||||
							
								
								
									
										11
									
								
								Post.cs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								Post.cs
									
									
									
									
									
								
							| @@ -1,11 +0,0 @@ | |||||||
| namespace NeDvachAPI |  | ||||||
| { |  | ||||||
|     public class Post |  | ||||||
|     { |  | ||||||
|         public DateTime Date { get; set; } |  | ||||||
|  |  | ||||||
|         public int Id { get; set; } |  | ||||||
|  |  | ||||||
|         public string Text { get; set; } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
							
								
								
									
										37
									
								
								Program.cs
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								Program.cs
									
									
									
									
									
								
							| @@ -1,25 +1,44 @@ | |||||||
|  | using NeDvachAPI.BufferControllers; | ||||||
|  |  | ||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
| // Add services to the container. |  | ||||||
|  |  | ||||||
| builder.Services.AddControllers(); | builder.Services.AddControllers(); | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); | builder.Services.AddEndpointsApiExplorer(); | ||||||
| builder.Services.AddSwaggerGen(); |  | ||||||
|  | builder.Services.AddCors(setup => | ||||||
|  | { | ||||||
|  |     setup.AddDefaultPolicy(policyBuilder => | ||||||
|  |     { | ||||||
|  |         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("*"); | ||||||
|  |     });  | ||||||
|  |  | ||||||
|  | }); | ||||||
|  |  | ||||||
| var app = builder.Build(); | var app = builder.Build(); | ||||||
|  |  | ||||||
| // Configure the HTTP request pipeline. |  | ||||||
| if (app.Environment.IsDevelopment()) | if (app.Environment.IsDevelopment()) | ||||||
| { | { | ||||||
|     app.UseSwagger(); |  | ||||||
|     app.UseSwaggerUI(); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| app.UseHttpsRedirection(); | app.UseCors(); | ||||||
|  |  | ||||||
| app.UseAuthorization(); | app.UseAuthorization(); | ||||||
|  |  | ||||||
| app.MapControllers(); | app.MapControllers(); | ||||||
|  |  | ||||||
| app.Run(); | app.UseHttpsRedirection(); | ||||||
|  |  | ||||||
|  | if (BufferFill.FillBuffer("b")) | ||||||
|  | { | ||||||
|  |     Console.WriteLine("Ready for work."); | ||||||
|  |     app.Run(); | ||||||
|  | } | ||||||
|  | else Console.WriteLine("Ошибка буферизации, проверьте доступность базы данных."); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,31 +1,29 @@ | |||||||
| { | { | ||||||
|  |   "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", |   "$schema": "https://json.schemastore.org/launchsettings.json", | ||||||
|   "iisSettings": { |   "iisSettings": { | ||||||
|     "windowsAuthentication": false, |     "windowsAuthentication": false, | ||||||
|     "anonymousAuthentication": true, |     "anonymousAuthentication": true, | ||||||
|     "iisExpress": { |     "iisExpress": { | ||||||
|       "applicationUrl": "http://localhost:31551", |       "applicationUrl": "http://0.0.0.0:31551", | ||||||
|       "sslPort": 44346 |       "sslPort": 44346 | ||||||
|     } |     } | ||||||
|   }, |  | ||||||
|   "profiles": { |  | ||||||
|     "NeDvachAPI": { |  | ||||||
|       "commandName": "Project", |  | ||||||
|       "dotnetRunMessages": true, |  | ||||||
|       "launchBrowser": true, |  | ||||||
|       "launchUrl": "Home", |  | ||||||
|       "applicationUrl": "https://localhost:7141;http://localhost:5141", |  | ||||||
|       "environmentVariables": { |  | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |  | ||||||
|       } |  | ||||||
|     }, |  | ||||||
|     "IIS Express": { |  | ||||||
|       "commandName": "IISExpress", |  | ||||||
|       "launchBrowser": true, |  | ||||||
|       "launchUrl": "Home", |  | ||||||
|       "environmentVariables": { |  | ||||||
|         "ASPNETCORE_ENVIRONMENT": "Development" |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
							
								
								
									
										3
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | [](http://drone.vdk2ch.ru:38080/RakVhalate/2chBackAPI) | ||||||
|  |  | ||||||
|  | fdasdfs | ||||||
| @@ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "Logging": { |   "Logging": { | ||||||
|     "LogLevel": { |     "LogLevel": { | ||||||
|       "Default": "Information", |       "Default": "Debug", | ||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -1,7 +1,8 @@ | |||||||
| { | { | ||||||
|  |   "https_port": 443, | ||||||
|   "Logging": { |   "Logging": { | ||||||
|     "LogLevel": { |     "LogLevel": { | ||||||
|       "Default": "Information", |       "Default": "Debug", | ||||||
|       "Microsoft.AspNetCore": "Warning" |       "Microsoft.AspNetCore": "Warning" | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | |||||||
|  | version: '3.1' | ||||||
|  |  | ||||||
|  | services: | ||||||
|  |   dvachBackAPI: | ||||||
|  |     image:          dvach-back-api:latest | ||||||
|  |     container_name: dvach-api | ||||||
|  |     build: | ||||||
|  |       context:    /usr/share/2chBackAPI | ||||||
|  |       dockerfile: Dockerfile | ||||||
|  |     restart: always | ||||||
|  |     ports: | ||||||
|  |     - "5000:80" | ||||||
|  |     # logging: | ||||||
|  |     #   driver: "gelf" | ||||||
|  |     #   options: | ||||||
|  |     #     gelf-address: "udp://graylog.vdk2ch.ru:12201" | ||||||
|  |     #     tag: "backend-logs" | ||||||
							
								
								
									
										5
									
								
								libman.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								libman.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | { | ||||||
|  |   "version": "1.0", | ||||||
|  |   "defaultProvider": "cdnjs", | ||||||
|  |   "libraries": [] | ||||||
|  | } | ||||||
							
								
								
									
										0
									
								
								newFile.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								newFile.txt
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user