diff --git a/api-collection-bruno/Convert file.bru b/api-collection-bruno/Convert file.bru deleted file mode 100644 index 3c61aa5..0000000 --- a/api-collection-bruno/Convert file.bru +++ /dev/null @@ -1,15 +0,0 @@ -meta { - name: Convert file - type: http - seq: 2 -} - -post { - url: http://127.0.0.1:5000/convert - body: multipartForm - auth: none -} - -body:multipart-form { - file: @file(D:\projects\python\pdf-from-templates\latex-to-pdf\extra\test-files\sample.tex) -} diff --git a/api-testing/local-testing/Convert file.bru b/api-testing/local-testing/Convert file.bru new file mode 100644 index 0000000..21c30f4 --- /dev/null +++ b/api-testing/local-testing/Convert file.bru @@ -0,0 +1,19 @@ +meta { + name: Convert file + type: http + seq: 4 +} + +post { + url: {{base_url}}/convert + body: multipartForm + auth: bearer +} + +auth:bearer { + token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Imd1ZXN0QHRlc3QuY29tIiwiZXhwaXJhdGlvbiI6MTcyNzU5NjQ4NC4zOTQ4LCJpYXQiOjE3Mjc1MTAwODQuMzk0ODE0LCJhZG1pbiI6dHJ1ZX0.V__wCE86tsTKD4-xx3y267Rn0QDcQrGJd_ed6rCkz58 +} + +body:multipart-form { + file: @file(D:\projects\python\pdf-from-templates\latex-to-pdf\extra\test-files\sample.tex) +} diff --git a/api-collection-bruno/bruno.json b/api-testing/local-testing/bruno.json similarity index 77% rename from api-collection-bruno/bruno.json rename to api-testing/local-testing/bruno.json index c881309..f4a182e 100644 --- a/api-collection-bruno/bruno.json +++ b/api-testing/local-testing/bruno.json @@ -1,6 +1,6 @@ { "version": "1", - "name": "bruno-api", + "name": "local-testing", "type": "collection", "ignore": [ "node_modules", diff --git a/api-collection-bruno/get version.bru b/api-testing/local-testing/get version.bru similarity index 62% rename from api-collection-bruno/get version.bru rename to api-testing/local-testing/get version.bru index a94aca4..7721581 100644 --- a/api-collection-bruno/get version.bru +++ b/api-testing/local-testing/get version.bru @@ -1,11 +1,11 @@ meta { name: get version type: http - seq: 3 + seq: 1 } get { - url: http://127.0.0.1:5000/version + url: {{base_url}}/version body: none auth: none } diff --git a/src/Dockerfile b/src/Dockerfile index 89e56b2..2a6d2fd 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,10 +1,6 @@ # Use an official Python runtime as a parent image FROM python:3.11-slim-bookworm -# Set version label -LABEL version="3.0" -# Custom image name: latex-pdf-converter - # Install necessary dependencies for Tectonic RUN apt-get update && apt-get install -y \ default-libmysqlclient-dev \ diff --git a/src/docker-compose.yml b/src/docker-compose.yml index bf7f544..a2ab629 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -1,28 +1,30 @@ services: - mysql01: - container_name: mysql01 - image: mysql - environment: - MYSQL_ROOT_PASSWORD: "root" - ports: - - "3306:3306" - volumes: - - "./init.sql:/docker-entrypoint-initdb.d/1.sql" +# use in case of local testing +# db: +# container_name: postgres +# image: postgres:16 +# restart: always +# shm_size: 128mb +# expose: +# - "5432" +# environment: +# POSTGRES_PASSWORD: root latex-to-pdf: container_name: backend image: laxman6811/latex-to-pdf:latest - links: - - mysql01 +# links: +# - db build: . - depends_on: - - mysql01 +# depends_on: +# - db env_file: - .env.dev ports: - "5000:5000" volumes: - .:/app + # TODO: research on ports left # rabbitmq: # image: rabbitmq:4-management diff --git a/src/latex/process.py b/src/latex/process.py index 942bc40..dc1071d 100644 --- a/src/latex/process.py +++ b/src/latex/process.py @@ -13,7 +13,6 @@ def compile_latex(file_path): # chdir to execute command os.chdir(fdir) - # app.logger.info(f"changed directory to {os.getcwd()} and running file {output_filename+'.tex'}") # Run Tectonic result = subprocess.run(['tectonic', output_filename+".tex"], capture_output=True, text=True) diff --git a/src/latex/unzip.py b/src/latex/unzip.py index 9896172..03ee7c8 100644 --- a/src/latex/unzip.py +++ b/src/latex/unzip.py @@ -18,7 +18,6 @@ def unzip(zip_file_path): with ZipFile(zip_file_path, 'r') as fzip: fzip.extractall(path=zip_container_dir) except Exception as ex: - # app.logger.error(ex) return None, ("Error while unzipping.", 500) tex_file = None diff --git a/src/requirements.txt b/src/requirements.txt index f66248d..fef668b 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -2,8 +2,8 @@ Flask==3.0.0 # auth -Flask-MySQLdb==2.0.0 +psycopg2-binary PyJWT # handling queue -pika \ No newline at end of file +# pika \ No newline at end of file diff --git a/src/server.py b/src/server.py index 37a9478..73924ae 100644 --- a/src/server.py +++ b/src/server.py @@ -2,7 +2,7 @@ from flask import Flask, request, send_file import os -from flask_mysqldb import MySQL +import psycopg2 from latex import process, unzip from auth.core import create_jwt @@ -10,29 +10,32 @@ app = Flask(__name__) -mysql = MySQL(app) - -app.config["MYSQL_HOST"] = os.environ.get("MYSQL_HOST") -app.config["MYSQL_USER"] = os.environ.get("MYSQL_USER") -app.config["MYSQL_PASSWORD"] = os.environ.get("MYSQL_PASSWORD") -app.config["MYSQL_DB"] = os.environ.get("MYSQL_DB") -app.config["MYSQL_PORT"] = int(os.environ.get("MYSQL_PORT")) - API_VERSION = os.environ.get("API_VERSION", "UNSET") +def _db(): + app.logger.info(os.environ.get("DB_HOST")) + conn = psycopg2.connect(host=os.environ.get("DB_HOST"), + database=os.environ.get("DB_DB"), + user=os.environ.get("DB_USER"), + password=os.environ.get("DB_PASSWORD")) + return conn + @app.route("/login", methods=["POST"]) def login(): auth = request.authorization if not auth: return "missing credentials", 401 - cur = mysql.connection.cursor() - res = cur.execute("SELECT email, password FROM user WHERE email=%s", (auth.username,)) + cur = _db().cursor() + cur.execute("SELECT email, password FROM \"user\" WHERE email=%s", (auth.username,)) + res = cur.fetchall() + cur.close() + _db().close() - if res > 0: + if len(res) > 0: # at least one row returned - user_row = cur.fetchone() + user_row = res[0] email = user_row[0] password = user_row[1]