From 304a187c77252619cbdf2ab8b85a202691e5651f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 12 Oct 2024 13:09:23 +0100 Subject: [PATCH] Load default searchable_by from file --- daemon.py | 4 ++-- utils.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index be086c36c..a80e6a102 100644 --- a/daemon.py +++ b/daemon.py @@ -46,6 +46,7 @@ from shares import expire_shares from categories import load_city_hashtags from categories import update_hashtag_categories from languages import load_default_post_languages +from utils import load_searchable_by_default from utils import set_accounts_data_dir from utils import data_dir from utils import check_bad_path @@ -703,8 +704,7 @@ def run_daemon(accounts_data_dir: str, httpd.last_llm_time = None # default "searchable by" for new posts for each account - # TODO load - httpd.searchable_by_default = {} + httpd.searchable_by_default = load_searchable_by_default(base_dir) # if a custom robots.txt exists then read it robots_txt_filename = data_dir(base_dir) + '/robots.txt' diff --git a/utils.py b/utils.py index dc7df1ac7..db00a3315 100644 --- a/utils.py +++ b/utils.py @@ -5132,3 +5132,24 @@ def account_is_indexable(actor_json: {}) -> bool: if '#Public' in actor_json['indexable']: return True return False + + +def load_searchable_by_default(base_dir: str) -> {}: + """loads the searchable_by states for each account + """ + result = {} + dir_str = data_dir(base_dir) + for _, dirs, _ in os.walk(dir_str): + for account in dirs: + if not is_account_dir(account): + continue + nickname = account.split('@')[0] + filename = os.path.join(dir_str, account) + '/.searchableByDefault' + if os.path.isfile(filename): + try: + with open(filename, 'r', encoding='utf-8') as fp_search: + result[nickname] = fp_search.read().strip() + except OSError: + print('EX: unable to load searchableByDefault ' + filename) + break + return result