From 797bf65d4e513d2bbdb3a3f2aeceff06084cbe4c Mon Sep 17 00:00:00 2001 From: hzhang Date: Mon, 9 Dec 2024 21:15:04 +0000 Subject: [PATCH] add: display home markdown --- .dockerignore | 8 ++++++++ Dockerfile | 17 ++++++----------- api/markdown.py | 11 +++++++++-- req2.txt | 9 +++++++++ 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 .dockerignore create mode 100644 req2.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ece6051 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +.git +.env +tests/ +docs/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d4930bc..b33c279 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,15 @@ FROM python:3.12-slim - ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 - WORKDIR /app - RUN apt-get update &&\ - apt-get install -y \ - default-mysql-client &&\ - apt-get clean - -COPY requirements.txt /app/ -RUN pip install --no-cache-dir -r requirements.txt + apt-get install -y default-mysql-client &&\ + apt-get clean &&\ + rm -rf /var/lib/apt/lists/* +COPY requirements.txt ./requirements.txt +RUN pip install --no-cache-dir -r ./requirements.txt COPY . /app/ - EXPOSE 5000 +CMD ["python", "app.py"] -CMD ["python", "app.py"] \ No newline at end of file diff --git a/api/markdown.py b/api/markdown.py index 8c09562..9449118 100644 --- a/api/markdown.py +++ b/api/markdown.py @@ -1,6 +1,4 @@ -#api/markdown.py from flask import Blueprint, request, jsonify - import api from api import require_auth, etag_response from contexts.RequestContext import RequestContext @@ -20,6 +18,15 @@ def get_markdowns(): mds = session.query(Markdown).all() return jsonify([md.to_dict() for md in mds]), 200 +@markdown_bp.route('/get_home', methods=['GET']) +@limiter.limit(api.get_rate_limit) +@etag_response +def get_home(): + with get_db() as session: + markdown = session.query(Markdown).filter(Markdown.path_id == 1).filter(Markdown.title == "index").first() + if markdown is None: + return jsonify({}), 204 + return jsonify(markdown.to_dict()), 200 @markdown_bp.route('/by_path/', methods=['GET']) @limiter.limit(api.get_rate_limit) @etag_response diff --git a/req2.txt b/req2.txt new file mode 100644 index 0000000..9034a53 --- /dev/null +++ b/req2.txt @@ -0,0 +1,9 @@ +cryptography==44.0.0 +Flask==3.1.0 +Flask_Cors==5.0.0 +Flask_Limiter==3.9.2 +PyJWT==2.10.1 +PyJWT==2.10.1 +python-dotenv==1.0.1 +Requests==2.32.3 +SQLAlchemy==2.0.36 \ No newline at end of file