feat: option to turn the app private (fix #2)

This commit is contained in:
Mylloon 2023-12-22 14:45:56 +01:00
parent ac1854bf3a
commit d3bcb3f63e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 18 additions and 7 deletions

View file

@ -7,9 +7,10 @@ personal diary with txt style, can be private!
## environment variables ## environment variables
| name | description | required | | name | description | required |
| :-----------: | :-----------: | :------: | | :-----------: | :-----------: | :-------------: |
| `TD_USERNAME` | user name | no | | `TD_USERNAME` | user name | no |
| `TD_USERPASS` | user password | yes | | `TD_USERPASS` | user password | yes |
| `TD_PRIVATE` | user password | empty = `false` |
## volumes (docker) ## volumes (docker)

View file

@ -10,11 +10,15 @@ router = Blueprint(name, __name__)
@router.route("/") @router.route("/")
def index() -> str: def index() -> str:
"""index page""" """index page"""
posts = []
if not Config.private or (Config.private and Config.is_logged()):
posts = [p.split("/")[-1][:-4] for p in get_posts()]
return render_template( return render_template(
"index.html", "index.html",
config=Config, config=Config,
page_name=name, page_name=name,
posts=[p.split("/")[-1][:-4] for p in get_posts()], posts=posts,
) )

View file

@ -10,6 +10,8 @@ router = Blueprint(name, __name__)
@router.route(f"/{name}/<int:file>") @router.route(f"/{name}/<int:file>")
def read(file: int) -> str: def read(file: int) -> str:
"""read page""" """read page"""
content = None
if not Config.private or (Config.private and Config.is_logged()):
filename = post_filename(file) filename = post_filename(file)
content = get_post(filename) content = get_post(filename)

View file

@ -4,6 +4,7 @@ from flask import session
VAR_USERNAME = "TD_USERNAME" VAR_USERNAME = "TD_USERNAME"
VAR_USERPASS = "TD_USERPASS" VAR_USERPASS = "TD_USERPASS"
VAR_PRIVATE = "TD_PRIVATE"
class User: class User:
@ -34,6 +35,9 @@ class Config:
# data location # data location
data_dir = "data" data_dir = "data"
# turn posts private
private = True if VAR_PRIVATE in envar else False
@staticmethod @staticmethod
def is_logged() -> bool: def is_logged() -> bool:
"""where the info about connection is stored""" """where the info about connection is stored"""