From 49dfe58391568d6ab7afa32522ab43e8b32bc49e Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 4 May 2024 20:46:42 +1200 Subject: [PATCH] refactor storage to be based on the loaded identity --- web.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web.py b/web.py index 71ac8ec..4ef03c6 100644 --- a/web.py +++ b/web.py @@ -26,12 +26,26 @@ class ReticulumWebChat: # default values before loading config self.display_name = "Anonymous Peer" + # create storage path based on identity being used + # ./storage/identities// + # ./storage/identities//config.json + # ./storage/identities//database.db + # ./storage/identities//lxmf + storage_path = os.path.join("storage", "identities", identity.hash.hex()) + print("Using Storage Path: {}".format(storage_path)) + os.makedirs(storage_path, exist_ok=True) + + # define path to files based on storage path + config_path = os.path.join(storage_path, "config.json") + database_path = os.path.join(storage_path, "database.db") + lxmf_router_path = os.path.join(storage_path, "lxmf_router") + # load config - self.config_file = webchat_config_file or "storage/config.json" + self.config_file = webchat_config_file or config_path self.load_config() # init database - database.database.initialize(SqliteDatabase('storage/reticulum-webchat.db')) + database.database.initialize(SqliteDatabase(database_path)) self.db = database.database self.db.connect() self.db.create_tables([ @@ -43,7 +57,7 @@ class ReticulumWebChat: self.identity = identity # init lxmf router - self.message_router = LXMF.LXMRouter(identity=self.identity, storagepath="storage/lxmf") + self.message_router = LXMF.LXMRouter(identity=self.identity, storagepath=lxmf_router_path) # register lxmf identity self.local_lxmf_destination = self.message_router.register_delivery_identity(self.identity)