Load default searchable_by from file

main
Bob Mottram 2024-10-12 13:09:23 +01:00
parent 7afbb3cfd1
commit 304a187c77
2 changed files with 23 additions and 2 deletions

View File

@ -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'

View File

@ -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