From 07e35c9db55c76d9d52538c7670130480fabb028 Mon Sep 17 00:00:00 2001 From: mystieneko Date: Wed, 28 Aug 2024 12:20:25 +0300 Subject: [PATCH] 0.1.1 - small fixes + installation instructions --- .env.example | 6 ++ README.md | 24 ++++++- app.py | 3 +- constants.py | 2 +- requirements.txt | 1 + templates/admin/login.html | 2 +- templates/base.html | 69 ++++++++++----------- templates/inbox.html | 36 +++++------ templates/index.html | 117 +++++++++++++++++------------------ templates/view_question.html | 40 ++++++------ 10 files changed, 164 insertions(+), 136 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..3295d31 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +DB_HOST = 127.0.0.1 +DB_NAME = catask +DB_USER = +DB_PASS = +ADMIN_PASSWORD = +APP_SECRET = \ No newline at end of file diff --git a/README.md b/README.md index 83447fb..31cda5a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -# catask-server +# CatAsk +## Installation +Clone this repository: `git clone https://git.gay/mst/catask.git` +### VPS-specific +Go into the cloned repository, create a virtual environment and activate it: +```python -m venv venv && . venv/bin/activate``` +Install required packages: +```pip install -r requirements.txt``` +### Shared hosting-specific +If your shared hosting provider supports [WSGI](https://w.wiki/_vTN2), [FastCGI](https://w.wiki/9EeQ), or something similar, use it (technically any CGI protocol could work) + +## Post-installation +Create a MySQL/MariaDB database and connect MDFlare to it (in `.env` file) +Then init the database: `flask init-db` +If that doesn't work, try importing schema.sql into the created database manually + +Rename `.env.example` to `.env`, configure all values there, and edit variable `fullBaseUrl` in `config.py` file +Then run it: +`flask run` or `gunicorn -w 4 app:app` (if you have gunicorn installed) or `python3 app.py` +If you want it to be accessible on a specific host address, specify a `--host` option (e.g. `--host 0.0.0.0`) to `flask run` + +## Usage +Works on `127.0.0.1:5000` (`flask run` or `python app.py`) or `127.0.0.1:8000` (`gunicorn -w 4 app:app`), may work in a production environment \ No newline at end of file diff --git a/app.py b/app.py index ecc623f..f19014e 100644 --- a/app.py +++ b/app.py @@ -15,7 +15,8 @@ logged_in = False load_dotenv() app = Flask(cfg.appName) -app.config["SECRET_KEY"] = os.environ.get("APP_SECRET") +print(os.environ.get("APP_SECRET")) +app.secret_key = os.environ.get("APP_SECRET") # -- blueprints -- api_bp = Blueprint('api', cfg.appName) diff --git a/constants.py b/constants.py index 418de18..269c8a5 100644 --- a/constants.py +++ b/constants.py @@ -1,3 +1,3 @@ antiSpamFile = 'wordlist.txt' blacklistFile = 'word_blacklist.txt' -version = '0.1.0' +version = '0.1.1' diff --git a/requirements.txt b/requirements.txt index 62cb824..bf78b03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ flask python-dotenv mysql-connector-python==8.2.0 +humanize \ No newline at end of file diff --git a/templates/admin/login.html b/templates/admin/login.html index dcebafa..65cae07 100644 --- a/templates/admin/login.html +++ b/templates/admin/login.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} - +{% block title %}Admin Login{% endblock %} {% block content %}
diff --git a/templates/base.html b/templates/base.html index 1c9be72..04441f6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -12,41 +12,40 @@ {% block title %}{% endblock %} - {{ cfg.appName }} -
-{% if logged_in %} -
-{% endif %} - -{% if logged_in %} - -
-{% endif %} -{% with messages = get_flashed_messages(with_categories=True) %} - {% if messages %} - {% for category, message in messages %} - + + + {% block scripts %}{% endblock %} +
+

CatAsk v{{ version }}

+
diff --git a/templates/inbox.html b/templates/inbox.html index 10bac7d..7f0ed25 100644 --- a/templates/inbox.html +++ b/templates/inbox.html @@ -5,20 +5,20 @@ {% if questions != [] %} {% for question in questions %}
-
-
-
{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}
-
{{ formatRelativeTime(str(question.creation_date)) }}
-
-

{{ question.content }} -

-
- - - -
-
-
+
+
+
{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}
+
{{ formatRelativeTime(str(question.creation_date)) }}
+
+

{{ question.content }}

+
+
+ + + +
+
+
{% endfor %} {% else %} @@ -30,10 +30,10 @@ const appendAlert = (elementId, message, type) => { const alertPlaceholder = document.getElementById(elementId); const alertHtml = ` - + `; alertPlaceholder.outerHTML = alertHtml; diff --git a/templates/index.html b/templates/index.html index 70a5504..d2140cc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,52 +3,51 @@ {% set homeLink = 'active' %} {% block content %}
-

Ask a question

-
-
- - - - - -
-
-
+

Ask a question

+
+
+ + + + + +
+
+
{% for item in combined %}
-
-
-
{% if item.question.from_who %}{{ item.question.from_who }}{% else %}Anonymous{% endif %}
-
{{ formatRelativeTime(str(item.question.creation_date)) }}
-
-

{{ item.question.content }}

-
- - - +
+
+
{% if item.question.from_who %}{{ item.question.from_who }}{% else %}Anonymous{% endif %}
+
{{ formatRelativeTime(str(item.question.creation_date)) }}
+
+

{{ item.question.content }}

+
+ + +
{% endfor %} {% endblock %} {% block scripts %} {% endblock %} diff --git a/templates/view_question.html b/templates/view_question.html index 12a9804..d665635 100644 --- a/templates/view_question.html +++ b/templates/view_question.html @@ -2,25 +2,25 @@ {% block content %}
-
-
-
{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}
-
{{ formatRelativeTime(str(question.creation_date)) }}
-
-

{{ question.content }}

-

{{ answer.content }}

-
- +
+
+
{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}
+
{{ formatRelativeTime(str(question.creation_date)) }}
+
+

{{ question.content }}

+

{{ answer.content }}

+
+
{% endblock %}