0.1.1 - small fixes + installation instructions
This commit is contained in:
parent
046bcf740e
commit
07e35c9db5
10 changed files with 164 additions and 136 deletions
6
.env.example
Normal file
6
.env.example
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
DB_HOST = 127.0.0.1
|
||||||
|
DB_NAME = catask
|
||||||
|
DB_USER =
|
||||||
|
DB_PASS =
|
||||||
|
ADMIN_PASSWORD =
|
||||||
|
APP_SECRET =
|
24
README.md
24
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
|
3
app.py
3
app.py
|
@ -15,7 +15,8 @@ logged_in = False
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
app = Flask(cfg.appName)
|
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 --
|
# -- blueprints --
|
||||||
api_bp = Blueprint('api', cfg.appName)
|
api_bp = Blueprint('api', cfg.appName)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
antiSpamFile = 'wordlist.txt'
|
antiSpamFile = 'wordlist.txt'
|
||||||
blacklistFile = 'word_blacklist.txt'
|
blacklistFile = 'word_blacklist.txt'
|
||||||
version = '0.1.0'
|
version = '0.1.1'
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
flask
|
flask
|
||||||
python-dotenv
|
python-dotenv
|
||||||
mysql-connector-python==8.2.0
|
mysql-connector-python==8.2.0
|
||||||
|
humanize
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
{% block title %}Admin Login{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
|
@ -12,24 +12,24 @@
|
||||||
<title>{% block title %}{% endblock %} - {{ cfg.appName }}</title>
|
<title>{% block title %}{% endblock %} - {{ cfg.appName }}</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="m-2">
|
<body class="m-2">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
{% if logged_in %}
|
{% if logged_in %}
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul class="nav nav-underline mt-2 mb-2">
|
<ul class="nav nav-underline mt-2 mb-2">
|
||||||
<li class="nav-item"><a class="nav-link {{ homeLink }}" id="home-link" href="{{ url_for('index') }}">Home</a>
|
<li class="nav-item"><a class="nav-link {{ homeLink }}" id="home-link" href="{{ url_for('index') }}">Home</a>
|
||||||
{%- if logged_in -%}
|
{%- if logged_in -%}
|
||||||
<li class="nav-item"><a class="nav-link {{ inboxLink }}" id="inbox-link" href="{{ url_for('inbox') }}">Inbox</a>
|
<li class="nav-item"><a class="nav-link {{ inboxLink }}" id="inbox-link" href="{{ url_for('inbox') }}">Inbox</a>
|
||||||
<li class="nav-item"><a class="nav-link {{ adminLink }}" id="admin-link" href="{{ url_for('admin.index') }}">Admin</a></li>
|
<li class="nav-item"><a class="nav-link {{ adminLink }}" id="admin-link" href="{{ url_for('admin.index') }}">Admin</a></li>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</ul>
|
</ul>
|
||||||
{% if logged_in %}
|
{% if logged_in %}
|
||||||
<ul class="nav nav-underline mt-2 mb-2">
|
<ul class="nav nav-underline mt-2 mb-2">
|
||||||
<li><a class="nav-link" href="{{ url_for('admin.logout') }}">Logout</a></li>
|
<li><a class="nav-link" href="{{ url_for('admin.logout') }}">Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% with messages = get_flashed_messages(with_categories=True) %}
|
{% with messages = get_flashed_messages(with_categories=True) %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
{% for category, message in messages %}
|
{% for category, message in messages %}
|
||||||
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
|
<div class="alert alert-{{ category }} alert-dismissible" role="alert">
|
||||||
|
@ -38,15 +38,14 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
<script src="{{ url_for('static', filename='js/htmx.min.js') }}"></script>
|
</div>
|
||||||
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/htmx.min.js') }}"></script>
|
||||||
{% block scripts %}
|
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
||||||
{% endblock %}
|
{% block scripts %}{% endblock %}
|
||||||
</div>
|
<footer class="py-3 my-4">
|
||||||
<footer class="py-3 my-4">
|
|
||||||
<p class="text-center text-body-secondary">CatAsk v{{ version }}</p>
|
<p class="text-center text-body-secondary">CatAsk v{{ version }}</p>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -5,20 +5,20 @@
|
||||||
{% if questions != [] %}
|
{% if questions != [] %}
|
||||||
{% for question in questions %}
|
{% for question in questions %}
|
||||||
<div class="card mb-2 mt-2 alert-placeholder" id="question-{{ question.id }}">
|
<div class="card mb-2 mt-2 alert-placeholder" id="question-{{ question.id }}">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<h5 class="card-title mt-0">{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
<h5 class="card-title mt-0">{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
||||||
<h6 class="card-subtitle fw-light text-body-secondary">{{ formatRelativeTime(str(question.creation_date)) }}</h6>
|
<h6 class="card-subtitle fw-light text-body-secondary">{{ formatRelativeTime(str(question.creation_date)) }}</h6>
|
||||||
</div>
|
</div>
|
||||||
<p>{{ question.content }}</span>
|
<p>{{ question.content }}</p>
|
||||||
<form hx-post="{{ url_for('api.addAnswer', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">
|
<form hx-post="{{ url_for('api.addAnswer', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">
|
||||||
<div class="form-group d-grid gap-2">
|
<div class="form-group d-grid gap-2">
|
||||||
<textarea class="form-control" required name="answer" id="answer-{{ question.id }}" placeholder="Write your answer..."></textarea>
|
<textarea class="form-control" required name="answer" id="answer-{{ question.id }}" placeholder="Write your answer..."></textarea>
|
||||||
<button type="submit" class="btn btn-primary">Answer</button>
|
<button type="submit" class="btn btn-primary">Answer</button>
|
||||||
<button type="button" class="btn btn-outline-danger" hx-delete="{{ url_for('api.deleteQuestion', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">Delete</button>
|
<button type="button" class="btn btn-outline-danger" hx-delete="{{ url_for('api.deleteQuestion', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -3,52 +3,51 @@
|
||||||
{% set homeLink = 'active' %}
|
{% set homeLink = 'active' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="mt-3 mb-5">
|
<div class="mt-3 mb-5">
|
||||||
<h2>Ask a question</h2>
|
<h2>Ask a question</h2>
|
||||||
<form hx-post="{{ url_for('api.addQuestion') }}" id="question-form" hx-target="#response-container" hx-swap="none">
|
<form hx-post="{{ url_for('api.addQuestion') }}" id="question-form" hx-target="#response-container" hx-swap="none">
|
||||||
<div class="form-group d-grid gap-2">
|
<div class="form-group d-grid gap-2">
|
||||||
<input class="form-control" type="text" name="from_who" id="from_who" placeholder="Name (optional)">
|
<input class="form-control" type="text" name="from_who" id="from_who" placeholder="Name (optional)">
|
||||||
<textarea class="form-control" required name="question" id="question" placeholder="Write your question..."></textarea>
|
<textarea class="form-control" required name="question" id="question" placeholder="Write your question..."></textarea>
|
||||||
<label for="antispam">Anti-spam: please enter the word <code>{{ getRandomWord().upper() }}</code> in lowercase</label>
|
<label for="antispam">Anti-spam: please enter the word <code>{{ getRandomWord().upper() }}</code> in lowercase</label>
|
||||||
<input class="form-control" type="text" required name="antispam" id="antispam">
|
<input class="form-control" type="text" required name="antispam" id="antispam">
|
||||||
<button type="submit" class="btn btn-primary">Ask</button>
|
<button type="submit" class="btn btn-primary">Ask</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div id="response-container" class="mt-3"></div>
|
<div id="response-container" class="mt-3"></div>
|
||||||
</div>
|
</div>
|
||||||
{% for item in combined %}
|
{% for item in combined %}
|
||||||
<div class="card mt-2 mb-2" id="question-{{ item.question.id }}">
|
<div class="card mt-2 mb-2" id="question-{{ item.question.id }}">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<h5 class="card-title mt-1 mb-1">{% if item.question.from_who %}{{ item.question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
<h5 class="card-title mt-1 mb-1">{% if item.question.from_who %}{{ item.question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
||||||
<h6 class="card-subtitle fw-light text-body-secondary" data-bs-toggle="tooltip" data-bs-title="{{ item.question.creation_date }}" data-bs-placement="top">{{ formatRelativeTime(str(item.question.creation_date)) }}</h6>
|
<h6 class="card-subtitle fw-light text-body-secondary" data-bs-toggle="tooltip" data-bs-title="{{ item.question.creation_date }}" data-bs-placement="top">{{ formatRelativeTime(str(item.question.creation_date)) }}</h6>
|
||||||
</div>
|
</div>
|
||||||
<p class="card-text">{{ item.question.content }}</p>
|
<p class="card-text">{{ item.question.content }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<a href="{{ url_for('viewQuestion', question_id=item.question.id) }}" class="text-decoration-none text-reset">
|
<a href="{{ url_for('viewQuestion', question_id=item.question.id) }}" class="text-decoration-none text-reset">
|
||||||
{% for answer in item.answers %}
|
{% for answer in item.answers %}
|
||||||
<p class="mb-0">{{ answer.content }}</p>
|
<p class="mb-0">{{ answer.content }}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="card-footer text-body-secondary d-flex justify-content-between align-items-center">
|
<div class="card-footer text-body-secondary d-flex justify-content-between align-items-center">
|
||||||
<span class="fs-6">answered {{ formatRelativeTime(str(answer.creation_date)) }}</span>
|
<span class="fs-6">answered {{ formatRelativeTime(str(answer.creation_date)) }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a class="text-reset btn-sm icon-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i style="font-size: 1.2rem;" class="bi bi-three-dots"></i></a>
|
<a class="text-reset btn-sm icon-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i style="font-size: 1.2rem;" class="bi bi-three-dots"></i></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><button class="dropdown-item" onclick="copy({{ item.question.id }})">Copy link</button></li>
|
<li><button class="dropdown-item" onclick="copy({{ item.question.id }})">Copy link</button></li>
|
||||||
{% if logged_in %}
|
{% if logged_in %}
|
||||||
<li><button class="dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=item.question.id) }}" hx-target="#question-{{ item.question.id }}" hx-swap="none">Return to inbox</button></li>
|
<li><button class="dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=item.question.id) }}" hx-target="#question-{{ item.question.id }}" hx-swap="none">Return to inbox</button></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
console.log(navigator.clipboard);
|
|
||||||
function copy(questionId) {
|
function copy(questionId) {
|
||||||
navigator.clipboard.writeText("{{ cfg.fullBaseUrl }}/q/" + questionId + "/")
|
navigator.clipboard.writeText("{{ cfg.fullBaseUrl }}/q/" + questionId + "/")
|
||||||
}
|
}
|
||||||
|
@ -71,7 +70,7 @@
|
||||||
alertPlaceholder.outerHTML = alertHtml;
|
alertPlaceholder.outerHTML = alertHtml;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('htmx:afterRequest', function(event) {
|
document.addEventListener('htmx:afterRequest', function(event) {
|
||||||
const jsonResponse = event.detail.xhr.response;
|
const jsonResponse = event.detail.xhr.response;
|
||||||
if (jsonResponse) {
|
if (jsonResponse) {
|
||||||
const parsed = JSON.parse(jsonResponse);
|
const parsed = JSON.parse(jsonResponse);
|
||||||
|
|
|
@ -2,25 +2,25 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="card mt-2 mb-2">
|
<div class="card mt-2 mb-2">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<h5 class="card-title mt-0">{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
<h5 class="card-title mt-0">{% if question.from_who %}{{ question.from_who }}{% else %}Anonymous{% endif %}</h5>
|
||||||
<h6 class="card-subtitle fw-light text-body-secondary">{{ formatRelativeTime(str(question.creation_date)) }}</h6>
|
<h6 class="card-subtitle fw-light text-body-secondary">{{ formatRelativeTime(str(question.creation_date)) }}</h6>
|
||||||
</div>
|
</div>
|
||||||
<p class="card-text">{{ question.content }}</p>
|
<p class="card-text">{{ question.content }}</p>
|
||||||
<p class="mb-0">{{ answer.content }}</p>
|
<p class="mb-0">{{ answer.content }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-body-secondary d-flex justify-content-between align--center">
|
<div class="card-footer text-body-secondary d-flex justify-content-between align--center">
|
||||||
<span class="fs-6">answered {{ formatRelativeTime(str(answer.creation_date)) }}</span>
|
<span class="fs-6">answered {{ formatRelativeTime(str(answer.creation_date)) }}</span>
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a class="text-reset btn-sm icon-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i style="font-size: 1.2rem;" class="bi bi-three-dots"></i></a>
|
<a class="text-reset btn-sm icon-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i style="font-size: 1.2rem;" class="bi bi-three-dots"></i></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><button class="dropdown-item" onclick="copy({{ question.id }})">Copy link</button></li>
|
<li><button class="dropdown-item" onclick="copy({{ question.id }})">Copy link</button></li>
|
||||||
{% if logged_in %}
|
{% if logged_in %}
|
||||||
<li><button class="dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">Return to inbox</button></li>
|
<li><button class="dropdown-item" hx-post="{{ url_for('api.returnToInbox', question_id=question.id) }}" hx-target="#question-{{ question.id }}" hx-swap="none">Return to inbox</button></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue