mirror of
				https://github.com/ivanch/tcc.git
				synced 2025-10-31 01:17:37 +00:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
			2390f8fb8d
			...
			FlaskAPI
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 8d9c1598a2 | ||
|  | 84df834b82 | ||
|  | 74a1a8458e | ||
| 6f93461ed9 | |||
| 09c7345e68 | |||
| 258f3a0243 | |||
| 6f6a77f897 | 
							
								
								
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| # Default ignored files | ||||
| /shelf/ | ||||
| /workspace.xml | ||||
| # Editor-based HTTP Client requests | ||||
| /httpRequests/ | ||||
| # Datasource local storage ignored files | ||||
| /dataSources/ | ||||
| /dataSources.local.xml | ||||
							
								
								
									
										6
									
								
								.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| <component name="InspectionProjectProfileManager"> | ||||
|   <settings> | ||||
|     <option name="USE_PROJECT_PROFILE" value="false" /> | ||||
|     <version value="1.0" /> | ||||
|   </settings> | ||||
| </component> | ||||
							
								
								
									
										4
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" /> | ||||
| </project> | ||||
							
								
								
									
										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/tcc.iml" filepath="$PROJECT_DIR$/.idea/tcc.iml" /> | ||||
|     </modules> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										8
									
								
								.idea/tcc.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/tcc.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <module type="PYTHON_MODULE" version="4"> | ||||
|   <component name="NewModuleRootManager"> | ||||
|     <content url="file://$MODULE_DIR$" /> | ||||
|     <orderEntry type="inheritedJdk" /> | ||||
|     <orderEntry type="sourceFolder" forTests="false" /> | ||||
|   </component> | ||||
| </module> | ||||
							
								
								
									
										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="" vcs="Git" /> | ||||
|   </component> | ||||
| </project> | ||||
| @@ -3,7 +3,7 @@ | ||||
| namespace TCC.Controllers | ||||
| { | ||||
|     [ApiController] | ||||
|     [Route("")] | ||||
|     [Route("status")] | ||||
|     public class StatusController : ControllerBase | ||||
|     { | ||||
|         public StatusController() { } | ||||
							
								
								
									
										24
									
								
								ASP.NET/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								ASP.NET/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build-env | ||||
| WORKDIR /App | ||||
|  | ||||
| # Copy everything | ||||
| COPY * . | ||||
|  | ||||
| # Restore as distinct layers | ||||
| RUN dotnet restore | ||||
|  | ||||
| # Build a release | ||||
| RUN dotnet build -c Release -o out | ||||
|  | ||||
| # Build runtime image | ||||
| FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim | ||||
|  | ||||
| WORKDIR /App | ||||
|  | ||||
| RUN wget https://files.ivanch.me/api/public/dl/QFCLgtrG/simpleimage.png && \ | ||||
|     wget https://files.ivanch.me/api/public/dl/E0VLgWbx/bigimage.png && \ | ||||
|     rm -rf runtimes | ||||
|  | ||||
| COPY --from=build-env /App/out . | ||||
|  | ||||
| ENTRYPOINT ["dotnet", "/App/TCC.APP.dll"] | ||||
| @@ -1,4 +1,3 @@ | ||||
| using Microsoft.AspNetCore.Http.Features; | ||||
| using Microsoft.AspNetCore.Server.Kestrel.Core; | ||||
| using TCC.Services; | ||||
| 
 | ||||
| @@ -14,7 +14,7 @@ | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": false, | ||||
|       "launchUrl": "weatherforecast", | ||||
|       "applicationUrl": "http://localhost:5100", | ||||
|       "applicationUrl": "http://0.0.0.0:5100", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Development" | ||||
|       } | ||||
| @@ -7,6 +7,7 @@ | ||||
|     <RootNamespace>tcc_app</RootNamespace> | ||||
|     <PlatformTarget>AnyCPU</PlatformTarget> | ||||
|     <AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||||
|     <MagickCopyNativeLinux>true</MagickCopyNativeLinux> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
							
								
								
									
										9
									
								
								ASP.NET/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								ASP.NET/appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Trace", | ||||
|       "Microsoft.AspNetCore": "Trace" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*" | ||||
| } | ||||
							
								
								
									
										34
									
								
								FlaskAPI/.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								FlaskAPI/.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| # Include any files or directories that you don't want to be copied to your | ||||
| # container here (e.g., local build artifacts, temporary files, etc.). | ||||
| # | ||||
| # For more help, visit the .dockerignore file reference guide at | ||||
| # https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||||
|  | ||||
| **/.DS_Store | ||||
| **/__pycache__ | ||||
| **/.venv | ||||
| **/.classpath | ||||
| **/.dockerignore | ||||
| **/.env | ||||
| **/.git | ||||
| **/.gitignore | ||||
| **/.project | ||||
| **/.settings | ||||
| **/.toolstarget | ||||
| **/.vs | ||||
| **/.vscode | ||||
| **/*.*proj.user | ||||
| **/*.dbmdl | ||||
| **/*.jfm | ||||
| **/bin | ||||
| **/charts | ||||
| **/docker-compose* | ||||
| **/compose* | ||||
| **/Dockerfile* | ||||
| **/node_modules | ||||
| **/npm-debug.log | ||||
| **/obj | ||||
| **/secrets.dev.yaml | ||||
| **/values.dev.yaml | ||||
| LICENSE | ||||
| README.md | ||||
							
								
								
									
										8
									
								
								FlaskAPI/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								FlaskAPI/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| # Default ignored files | ||||
| /shelf/ | ||||
| /workspace.xml | ||||
| # Editor-based HTTP Client requests | ||||
| /httpRequests/ | ||||
| # Datasource local storage ignored files | ||||
| /dataSources/ | ||||
| /dataSources.local.xml | ||||
							
								
								
									
										19
									
								
								FlaskAPI/.idea/FlaskAPI.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								FlaskAPI/.idea/FlaskAPI.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <module type="PYTHON_MODULE" version="4"> | ||||
|   <component name="Flask"> | ||||
|     <option name="enabled" value="true" /> | ||||
|   </component> | ||||
|   <component name="NewModuleRootManager"> | ||||
|     <content url="file://$MODULE_DIR$" /> | ||||
|     <orderEntry type="inheritedJdk" /> | ||||
|     <orderEntry type="sourceFolder" forTests="false" /> | ||||
|   </component> | ||||
|   <component name="TemplatesService"> | ||||
|     <option name="TEMPLATE_CONFIGURATION" value="Jinja2" /> | ||||
|     <option name="TEMPLATE_FOLDERS"> | ||||
|       <list> | ||||
|         <option value="$MODULE_DIR$/../FlaskAPI\templates" /> | ||||
|       </list> | ||||
|     </option> | ||||
|   </component> | ||||
| </module> | ||||
							
								
								
									
										6
									
								
								FlaskAPI/.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								FlaskAPI/.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| <component name="InspectionProjectProfileManager"> | ||||
|   <settings> | ||||
|     <option name="USE_PROJECT_PROFILE" value="false" /> | ||||
|     <version value="1.0" /> | ||||
|   </settings> | ||||
| </component> | ||||
							
								
								
									
										4
									
								
								FlaskAPI/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								FlaskAPI/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (FlaskAPI)" project-jdk-type="Python SDK" /> | ||||
| </project> | ||||
							
								
								
									
										8
									
								
								FlaskAPI/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								FlaskAPI/.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/FlaskAPI.iml" filepath="$PROJECT_DIR$/.idea/FlaskAPI.iml" /> | ||||
|     </modules> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										17
									
								
								FlaskAPI/.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								FlaskAPI/.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| { | ||||
|   "version": "0.0.1", | ||||
|   "configurations": [ | ||||
|      | ||||
|     { | ||||
|       "name": "Python: Flask", | ||||
|       "type": "python", | ||||
|       "request": "launch", | ||||
|       "module": "flask", | ||||
|       "env": { "FLASK_APP": "app.py", "FLASK_DEBUG": "1" }, | ||||
|       "args": ["run", "--no-debugger", "--no-reload"], | ||||
|       "jinja": true, | ||||
|       "justMyCode": true | ||||
|     } | ||||
|  | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										0
									
								
								FlaskAPI/.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								FlaskAPI/.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
								
								
									
										45
									
								
								FlaskAPI/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								FlaskAPI/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| # syntax=docker/dockerfile:1 | ||||
|  | ||||
| # Comments are provided throughout this file to help you get started. | ||||
| # If you need more help, visit the Dockerfile reference guide at | ||||
| # https://docs.docker.com/engine/reference/builder/ | ||||
|  | ||||
| ARG PYTHON_VERSION=3.10.12 | ||||
| FROM python:${PYTHON_VERSION}-slim as base | ||||
|  | ||||
| # Prevents Python from writing pyc files. | ||||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||||
|  | ||||
| # Keeps Python from buffering stdout and stderr to avoid situations where | ||||
| # the application crashes without emitting any logs due to buffering. | ||||
| ENV PYTHONUNBUFFERED=1 | ||||
|  | ||||
| WORKDIR /app | ||||
|  | ||||
| # Copy the source code into the container. | ||||
| COPY . . | ||||
|  | ||||
| RUN apt-get update && apt-get install -y imagemagick && apt-get install -y wget && ls | ||||
|  | ||||
| RUN wget https://files.ivanch.me/api/public/dl/iFuXSNhw/small-image.png && \ | ||||
|     wget https://files.ivanch.me/api/public/dl/81Bkht5C/big-image.png && \ | ||||
|     wget https://files.ivanch.me/api/public/dl/nAndfAjK/video.mp4 && \ | ||||
|     rm -rf runtimes && \ | ||||
|     mkdir -p ./static && \ | ||||
|     mv small-image.png ./static && \ | ||||
|     mv big-image.png ./static && \ | ||||
|     mv video.mp4 ./static | ||||
|  | ||||
| # Download dependencies as a separate step to take advantage of Docker's caching. | ||||
| # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. | ||||
| # Leverage a bind mount to requirements.txt to avoid having to copy them into | ||||
| # into this layer. | ||||
| RUN --mount=type=cache,target=/root/.cache/pip \ | ||||
|     --mount=type=bind,source=requirements.txt,target=requirements.txt \ | ||||
|     python -m pip install -r requirements.txt | ||||
|  | ||||
| # Expose the port that the application listens on. | ||||
| EXPOSE 5000 | ||||
|  | ||||
| # Run the application. | ||||
| CMD gunicorn 'app:app' --bind=0.0.0.0:5000 | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/__pycache__/app.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/__pycache__/app.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										12
									
								
								FlaskAPI/app.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								FlaskAPI/app.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| from flask import Flask | ||||
| from controllers.status import status_blueprint | ||||
| from controllers.image import image_blueprint | ||||
|  | ||||
| app = Flask(__name__) | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     app.run() | ||||
|  | ||||
| # | ||||
| app.register_blueprint(status_blueprint) | ||||
| app.register_blueprint(image_blueprint) | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/blurred_temp_image.jpeg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/blurred_temp_image.jpeg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 36 KiB | 
							
								
								
									
										49
									
								
								FlaskAPI/compose.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								FlaskAPI/compose.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| # Comments are provided throughout this file to help you get started. | ||||
| # If you need more help, visit the Docker compose reference guide at | ||||
| # https://docs.docker.com/compose/compose-file/ | ||||
|  | ||||
| # Here the instructions define your application as a service called "server". | ||||
| # This service is built from the Dockerfile in the current directory. | ||||
| # You can add other services your application may depend on here, such as a | ||||
| # database or a cache. For examples, see the Awesome Compose repository: | ||||
| # https://github.com/docker/awesome-compose | ||||
| services: | ||||
|   server: | ||||
|     build: | ||||
|       context: . | ||||
|     ports: | ||||
|       - 5000:5000 | ||||
|  | ||||
| # The commented out section below is an example of how to define a PostgreSQL | ||||
| # database that your application can use. `depends_on` tells Docker Compose to | ||||
| # start the database before your application. The `db-data` volume persists the | ||||
| # database data between container restarts. The `db-password` secret is used | ||||
| # to set the database password. You must create `db/password.txt` and add | ||||
| # a password of your choosing to it before running `docker compose up`. | ||||
| #     depends_on: | ||||
| #       db: | ||||
| #         condition: service_healthy | ||||
| #   db: | ||||
| #     image: postgres | ||||
| #     restart: always | ||||
| #     user: postgres | ||||
| #     secrets: | ||||
| #       - db-password | ||||
| #     volumes: | ||||
| #       - db-data:/var/lib/postgresql/data | ||||
| #     environment: | ||||
| #       - POSTGRES_DB=example | ||||
| #       - POSTGRES_PASSWORD_FILE=/run/secrets/db-password | ||||
| #     expose: | ||||
| #       - 5432 | ||||
| #     healthcheck: | ||||
| #       test: [ "CMD", "pg_isready" ] | ||||
| #       interval: 10s | ||||
| #       timeout: 5s | ||||
| #       retries: 5 | ||||
| # volumes: | ||||
| #   db-data: | ||||
| # secrets: | ||||
| #   db-password: | ||||
| #     file: db/password.txt | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/controllers/__pycache__/image.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/controllers/__pycache__/image.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/controllers/__pycache__/status.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/controllers/__pycache__/status.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										41
									
								
								FlaskAPI/controllers/image.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								FlaskAPI/controllers/image.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| from services.image import ImageService | ||||
| from static.image_helper import ImageHelper | ||||
| from flask import request, Response, Blueprint, jsonify, send_file | ||||
|  | ||||
| image_blueprint = Blueprint('image_blueprint', __name__) | ||||
| image_service = ImageService() | ||||
|  | ||||
|  | ||||
| @image_blueprint.route('/image/blur', methods=['POST']) | ||||
| def blur_image(): | ||||
|     radius = int(request.form.get('radius')) | ||||
|     image = request.files.get('file') | ||||
|  | ||||
|     if radius and image: | ||||
|         return send_file(image_service.box_blur_image(image, radius), | ||||
|                          mimetype='image/jpeg', | ||||
|                          as_attachment=True, | ||||
|                          download_name='blurred_image.jpeg') | ||||
|  | ||||
|     return "Bad request", 400 | ||||
|  | ||||
|  | ||||
| @image_blueprint.route('/image/load-small-image', methods=['GET']) | ||||
| def get_simple_image(): | ||||
|     return send_file(image_service.get_simple_image(), | ||||
|                      mimetype='image/png', | ||||
|                      as_attachment=True, | ||||
|                      download_name='small-image.png') | ||||
|  | ||||
|  | ||||
| @image_blueprint.route('/image/load-big-image', methods=['GET']) | ||||
| def get_big_image(): | ||||
|     return send_file(image_service.get_big_image(), | ||||
|                      mimetype='image/png', | ||||
|                      as_attachment=True, | ||||
|                      download_name='big-image.png') | ||||
|  | ||||
|  | ||||
| @image_blueprint.route('/image/save-big-image', methods=['POST']) | ||||
| def save_image(): | ||||
|     pass | ||||
							
								
								
									
										19
									
								
								FlaskAPI/controllers/status.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								FlaskAPI/controllers/status.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| from flask import jsonify, Blueprint | ||||
|  | ||||
| status_blueprint = Blueprint('status_blueprint', __name__) | ||||
|  | ||||
|  | ||||
| class StatusController: | ||||
|     def __init__(self): | ||||
|         pass | ||||
|  | ||||
|     def return_ok(self): | ||||
|         return jsonify(status=200) | ||||
|  | ||||
|  | ||||
| status_controller = StatusController() | ||||
|  | ||||
|  | ||||
| @status_blueprint.route('/status/ok', methods=['GET']) | ||||
| def return_ok(): | ||||
|     return jsonify(status=200) | ||||
							
								
								
									
										3
									
								
								FlaskAPI/requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								FlaskAPI/requirements.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| Flask>=1.0 | ||||
| gunicorn>=19.9.0 | ||||
| Wand | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/services/__pycache__/image.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/services/__pycache__/image.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										69
									
								
								FlaskAPI/services/image.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								FlaskAPI/services/image.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| from wand.image import Image | ||||
|  | ||||
| from static.image_helper import ImageHelper | ||||
|  | ||||
|  | ||||
| def box_blur_image_separable(image, blurred_image, radius_x, radius_y): | ||||
|     pixels = image.get_pixels() | ||||
|     blurred_pixels = blurred_image.get_pixels() | ||||
|  | ||||
|     for pixel in pixels: | ||||
|         x, y = pixel[0], pixel[1] | ||||
|  | ||||
|         r_total, g_total, b_total = 0, 0, 0 | ||||
|         pixel_count = 0 | ||||
|         for offset_y in range(-radius_y, radius_y + 1): | ||||
|             for offset_x in range(-radius_x, radius_x + 1): | ||||
|                 new_x = x + offset_x | ||||
|                 new_y = y + offset_y | ||||
|  | ||||
|                 if 0 <= new_x < image.width and 0 <= new_y < image.height: | ||||
|                     pixel_color = pixels[new_y * image.width + new_x] | ||||
|                     r_total += pixel_color.red | ||||
|                     g_total += pixel_color.green | ||||
|                     b_total += pixel_color.blue | ||||
|                     pixel_count += 1 | ||||
|  | ||||
|         blurred_pixel = blurred_pixels[y * image.width + x] | ||||
|         blurred_pixel.red = int(r_total / pixel_count) | ||||
|         blurred_pixel.green = int(g_total / pixel_count) | ||||
|         blurred_pixel.blue = int(b_total / pixel_count) | ||||
|  | ||||
|     return blurred_image | ||||
|  | ||||
|  | ||||
| def save_image(file_stream): | ||||
|     with open("image.png", "wb") as file: | ||||
|         file.write(file_stream.read()) | ||||
|         file.close() | ||||
|  | ||||
|  | ||||
| class ImageService: | ||||
|     def __init__(self): | ||||
|         pass | ||||
|  | ||||
|     def box_blur_image(self, img, radius): | ||||
|         temp_path = 'temp_image.png' | ||||
|         img.save(temp_path) | ||||
|  | ||||
|         with Image(filename=temp_path) as img: | ||||
|             img.blur(radius, 2) | ||||
|             blurred_temp_path = 'blurred_temp_image.png' | ||||
|             img.save(filename='blurred_temp_image.png') | ||||
|             return blurred_temp_path | ||||
|  | ||||
|  | ||||
|     def get_simple_image(self): | ||||
|         with ImageHelper.SimpleImage as img: | ||||
|             img = ImageHelper.SimpleImage | ||||
|             simple_image = 'simple_image.png' | ||||
|             img.save(filename='simple_image.png') | ||||
|             return simple_image | ||||
|  | ||||
|  | ||||
|     def get_big_image(self): | ||||
|         with ImageHelper.BigImage as img: | ||||
|             img = ImageHelper.BigImage | ||||
|             big_image = 'big_image.png' | ||||
|             img.save(filename='big_image.png') | ||||
|             return big_image | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/static/__pycache__/image_helper.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/static/__pycache__/image_helper.cpython-310.pyc
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										17
									
								
								FlaskAPI/static/image_helper.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								FlaskAPI/static/image_helper.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| from wand.image import Image | ||||
|  | ||||
|  | ||||
| class ImageHelper: | ||||
|     SimpleImage = None | ||||
|     BigImage = None | ||||
|  | ||||
|     @staticmethod | ||||
|     def load_images(): | ||||
|         ImageHelper.SimpleImage = Image(filename="./static/small-image.png") | ||||
|         #ImageHelper.SimpleImage.save(filename="./static/small-image.png") | ||||
|  | ||||
|         ImageHelper.BigImage = Image(filename="./static/big-image.png") | ||||
|         #ImageHelper.BigImage.save(filename="./static/big-image.png") | ||||
|         pass | ||||
|  | ||||
| ImageHelper.load_images() | ||||
							
								
								
									
										
											BIN
										
									
								
								FlaskAPI/temp_image.jpeg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								FlaskAPI/temp_image.jpeg
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 44 KiB | 
| @@ -1,9 +0,0 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*" | ||||
| } | ||||
							
								
								
									
										33
									
								
								scripts/testes.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								scripts/testes.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| import requests | ||||
| import concurrent.futures | ||||
| import time | ||||
|  | ||||
| URL_BASE = 'http://localhost:5100' | ||||
|  | ||||
| num_requests = [1000, 5000, 10_000, 50_000, 100_000, 500_000, 1_000_000] | ||||
|  | ||||
| def send_request(session, url): | ||||
|     response = session.get(url) | ||||
|     return response.status_code | ||||
|  | ||||
| def main(): | ||||
|     for num_request in num_requests: | ||||
|         with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: | ||||
|             url = f'{URL_BASE}/status/ok' | ||||
|  | ||||
|             start_time = time.time() | ||||
|  | ||||
|             futures = [] | ||||
|             with requests.Session() as session: | ||||
|                 futures = [executor.submit(send_request, session, url) for _ in range(num_request)] | ||||
|  | ||||
|             concurrent.futures.wait(futures) | ||||
|  | ||||
|             elapsed_time = time.time() - start_time | ||||
|  | ||||
|             successful_responses = sum(1 for future in futures if future.result() == 200) | ||||
|  | ||||
|         print(f"All requests completed in {elapsed_time:.2f} seconds. {elapsed_time/num_request:.4f} seconds per request. {num_request/elapsed_time:.2f} requests per second.") | ||||
|         print(f"Successful responses: {successful_responses}/{num_request}") | ||||
|  | ||||
| main() | ||||
		Reference in New Issue
	
	Block a user