From 2542b6862c2cd35d98ff3846a956dc8dba2801b1 Mon Sep 17 00:00:00 2001 From: 0x01fe Date: Mon, 1 Jul 2024 09:41:30 -0500 Subject: [PATCH] added some checks for user/comments files --- app/app.py | 6 +----- app/comment.py | 5 +++++ app/user.py | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/app.py b/app/app.py index b687b85..f9f3f6c 100644 --- a/app/app.py +++ b/app/app.py @@ -161,7 +161,7 @@ def post(post_name: str): flask.abort(404) -# Games Page +# Category's Endpoint @app.route('/category//') def category_filter(category: str): @@ -264,10 +264,6 @@ def writing(): return flask.render_template('writing.html', works=works) - - - - # About Page @app.route('/about/') def about(): diff --git a/app/comment.py b/app/comment.py index 0e27ea6..1aa046d 100644 --- a/app/comment.py +++ b/app/comment.py @@ -1,4 +1,5 @@ import json +import os import flask import flask_wtf.csrf @@ -53,4 +54,8 @@ def get_comments(post_title : int) -> list[dict]: else: return [] +# Check Comments file exists +if not os.path.exists(COMMENTS_PATH): + with open(COMMENTS_PATH, 'w+') as file: + file.write('{}') diff --git a/app/user.py b/app/user.py index e7ae060..198ff5d 100644 --- a/app/user.py +++ b/app/user.py @@ -1,5 +1,6 @@ import base64 import json +import os import flask import flask_wtf.csrf @@ -94,3 +95,8 @@ def logout_user(): flask.session.pop('username') return flask.redirect('/') + +# Check User file exists +if not os.path.exists(USERS_PATH): + with open(USERS_PATH, 'w+') as file: + file.write('{}')