From 9aa23ff6201c380c9ef992ba4bc63d889e0b4fb8 Mon Sep 17 00:00:00 2001 From: Kosh Date: Sun, 15 Oct 2023 13:05:44 +0530 Subject: [PATCH] Handle First Launch --- backend/api-docs.txt | 4 ---- backend/rest_api.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/api-docs.txt b/backend/api-docs.txt index aba2f79..bb38c4c 100644 --- a/backend/api-docs.txt +++ b/backend/api-docs.txt @@ -1,7 +1,3 @@ -WARNING:- - This api is not yet capable of handling any exceptions that may arise when opened for the first time - - _____________________ Login:- URL:- /login diff --git a/backend/rest_api.py b/backend/rest_api.py index b8764b5..1187cf9 100644 --- a/backend/rest_api.py +++ b/backend/rest_api.py @@ -1,18 +1,27 @@ -from os import path +from os import mkdir, path from flask import Flask, request, send_file, abort, Response from werkzeug.datastructures import ImmutableMultiDict from data_handler import DataHandler +import appdirs app: Flask = Flask(__name__) + +def handle_first_launched(): + folder_path: str = appdirs.user_data_dir(appname="Unnamed_Password_Manager") + if not path.exists(folder_path): + mkdir(folder_path) + + @app.get("/") @app.get("/") def handle_get(url_path: str = "index.html") -> Response: """ Handle all get requests that are made. """ + handle_first_launched() requested_file_path: str = \ path.abspath(path.join(path.curdir, "..", "frontend", url_path)) response: Response = send_file(requested_file_path)