mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
8486209f2b
commit
25b7e1f577
|
@ -1397,6 +1397,143 @@ def _receive_new_post_process_newreading(self, fields: {},
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
def _receive_new_post_process_newshare(self, fields: {},
|
||||||
|
post_type: str,
|
||||||
|
attachment_media_type: str,
|
||||||
|
city: str, base_dir: str,
|
||||||
|
nickname: str, domain: str,
|
||||||
|
http_prefix: str, port: int,
|
||||||
|
filename: str, debug: bool,
|
||||||
|
translate: {},
|
||||||
|
low_bandwidth: bool,
|
||||||
|
content_license_url: str,
|
||||||
|
block_federated: bool,
|
||||||
|
calling_domain: str,
|
||||||
|
domain_full: str,
|
||||||
|
onion_domain: str,
|
||||||
|
i2p_domain: str,
|
||||||
|
person_cache: {},
|
||||||
|
max_shares_on_profile: int,
|
||||||
|
project_version: str,
|
||||||
|
curr_session,
|
||||||
|
proxy_type: str) -> int:
|
||||||
|
"""Shared/Wanted item post has been received from New Post screen
|
||||||
|
and is then sent to the outbox
|
||||||
|
"""
|
||||||
|
if not fields.get('itemQty'):
|
||||||
|
print(post_type + ' no itemQty')
|
||||||
|
return -1
|
||||||
|
if not fields.get('itemType'):
|
||||||
|
print(post_type + ' no itemType')
|
||||||
|
return -1
|
||||||
|
if 'itemPrice' not in fields:
|
||||||
|
print(post_type + ' no itemPrice')
|
||||||
|
return -1
|
||||||
|
if 'itemCurrency' not in fields:
|
||||||
|
print(post_type + ' no itemCurrency')
|
||||||
|
return -1
|
||||||
|
if not fields.get('category'):
|
||||||
|
print(post_type + ' no category')
|
||||||
|
return -1
|
||||||
|
if not fields.get('duration'):
|
||||||
|
print(post_type + ' no duratio')
|
||||||
|
return -1
|
||||||
|
if attachment_media_type:
|
||||||
|
if attachment_media_type != 'image':
|
||||||
|
print('Attached media is not an image')
|
||||||
|
return -1
|
||||||
|
duration_str = fields['duration']
|
||||||
|
if duration_str:
|
||||||
|
if ' ' not in duration_str:
|
||||||
|
duration_str = duration_str + ' days'
|
||||||
|
city = get_spoofed_city(city, base_dir, nickname, domain)
|
||||||
|
item_qty = 1
|
||||||
|
if fields['itemQty']:
|
||||||
|
if is_float(fields['itemQty']):
|
||||||
|
item_qty = float(fields['itemQty'])
|
||||||
|
item_price = "0.00"
|
||||||
|
item_currency = "EUR"
|
||||||
|
if fields['itemPrice']:
|
||||||
|
item_price, item_currency = \
|
||||||
|
get_price_from_string(fields['itemPrice'])
|
||||||
|
if fields['itemCurrency']:
|
||||||
|
item_currency = fields['itemCurrency']
|
||||||
|
if post_type == 'newshare':
|
||||||
|
print('Adding shared item')
|
||||||
|
shares_file_type = 'shares'
|
||||||
|
else:
|
||||||
|
print('Adding wanted item')
|
||||||
|
shares_file_type = 'wanted'
|
||||||
|
share_on_profile = False
|
||||||
|
if fields.get('shareOnProfile'):
|
||||||
|
if fields['shareOnProfile'] == 'on':
|
||||||
|
share_on_profile = True
|
||||||
|
add_share(base_dir, http_prefix, nickname, domain, port,
|
||||||
|
fields['subject'],
|
||||||
|
fields['message'],
|
||||||
|
filename,
|
||||||
|
item_qty, fields['itemType'],
|
||||||
|
fields['category'],
|
||||||
|
fields['location'],
|
||||||
|
duration_str,
|
||||||
|
debug,
|
||||||
|
city, item_price, item_currency,
|
||||||
|
fields['languagesDropdown'],
|
||||||
|
translate, shares_file_type,
|
||||||
|
low_bandwidth,
|
||||||
|
content_license_url,
|
||||||
|
share_on_profile,
|
||||||
|
block_federated)
|
||||||
|
if post_type == 'newshare':
|
||||||
|
# add shareOnProfile items to the actor attachments
|
||||||
|
# https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
|
||||||
|
actor = \
|
||||||
|
get_instance_url(calling_domain,
|
||||||
|
http_prefix, domain_full,
|
||||||
|
onion_domain,
|
||||||
|
i2p_domain) + \
|
||||||
|
'/users/' + nickname
|
||||||
|
actor_json = get_person_from_cache(base_dir,
|
||||||
|
actor, person_cache)
|
||||||
|
if not actor_json:
|
||||||
|
actor_filename = \
|
||||||
|
acct_dir(base_dir, nickname, domain) + '.json'
|
||||||
|
if os.path.isfile(actor_filename):
|
||||||
|
actor_json = load_json(actor_filename, 1, 1)
|
||||||
|
if actor_json:
|
||||||
|
if add_shares_to_actor(base_dir, nickname, domain,
|
||||||
|
actor_json,
|
||||||
|
max_shares_on_profile):
|
||||||
|
remove_person_from_cache(base_dir,
|
||||||
|
actor, person_cache)
|
||||||
|
store_person_in_cache(base_dir, actor,
|
||||||
|
actor_json, person_cache,
|
||||||
|
True)
|
||||||
|
actor_filename = \
|
||||||
|
acct_dir(base_dir, nickname, domain) + '.json'
|
||||||
|
save_json(actor_json, actor_filename)
|
||||||
|
# send profile update to followers
|
||||||
|
update_actor_json = \
|
||||||
|
get_actor_update_json(actor_json)
|
||||||
|
print('Sending actor update ' +
|
||||||
|
'after change to attached shares: ' +
|
||||||
|
str(update_actor_json))
|
||||||
|
post_to_outbox(self, update_actor_json,
|
||||||
|
project_version,
|
||||||
|
nickname,
|
||||||
|
curr_session, proxy_type)
|
||||||
|
|
||||||
|
if filename:
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
try:
|
||||||
|
os.remove(filename)
|
||||||
|
except OSError:
|
||||||
|
print('EX: _receive_new_post_process ' +
|
||||||
|
'unable to delete ' + filename)
|
||||||
|
self.post_to_nickname = nickname
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
length: int, post_bytes, boundary: str,
|
length: int, post_bytes, boundary: str,
|
||||||
calling_domain: str, cookie: str,
|
calling_domain: str, cookie: str,
|
||||||
|
@ -1684,7 +1821,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type,
|
proxy_type,
|
||||||
max_replies)
|
max_replies)
|
||||||
elif post_type == 'newblog':
|
if post_type == 'newblog':
|
||||||
return _receive_new_post_process_newblog(
|
return _receive_new_post_process_newblog(
|
||||||
self, fields,
|
self, fields,
|
||||||
citations_button_press,
|
citations_button_press,
|
||||||
|
@ -1701,7 +1838,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
buy_url, chat_url,
|
buy_url, chat_url,
|
||||||
project_version, curr_session,
|
project_version, curr_session,
|
||||||
proxy_type, max_replies, debug)
|
proxy_type, max_replies, debug)
|
||||||
elif post_type == 'editblogpost':
|
if post_type == 'editblogpost':
|
||||||
return _receive_new_post_process_editblog(
|
return _receive_new_post_process_editblog(
|
||||||
self, fields, base_dir, nickname, domain,
|
self, fields, base_dir, nickname, domain,
|
||||||
recent_posts_cache,
|
recent_posts_cache,
|
||||||
|
@ -1714,7 +1851,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
low_bandwidth,
|
low_bandwidth,
|
||||||
yt_replace_domain,
|
yt_replace_domain,
|
||||||
twitter_replacement_domain)
|
twitter_replacement_domain)
|
||||||
elif post_type == 'newunlisted':
|
if post_type == 'newunlisted':
|
||||||
return _receive_new_post_process_newunlisted(
|
return _receive_new_post_process_newunlisted(
|
||||||
self, fields,
|
self, fields,
|
||||||
city, base_dir,
|
city, base_dir,
|
||||||
|
@ -1758,7 +1895,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type,
|
proxy_type,
|
||||||
max_replies)
|
max_replies)
|
||||||
elif post_type == 'newfollowers':
|
if post_type == 'newfollowers':
|
||||||
return _receive_new_post_process_newfollowers(
|
return _receive_new_post_process_newfollowers(
|
||||||
self, fields,
|
self, fields,
|
||||||
city, base_dir,
|
city, base_dir,
|
||||||
|
@ -1802,7 +1939,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type,
|
proxy_type,
|
||||||
max_replies)
|
max_replies)
|
||||||
elif post_type == 'newdm':
|
if post_type == 'newdm':
|
||||||
return _receive_new_post_process_newdm(
|
return _receive_new_post_process_newdm(
|
||||||
self, fields,
|
self, fields,
|
||||||
mentions_str,
|
mentions_str,
|
||||||
|
@ -1847,7 +1984,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type,
|
proxy_type,
|
||||||
max_replies)
|
max_replies)
|
||||||
elif post_type == 'newreminder':
|
if post_type == 'newreminder':
|
||||||
return _receive_new_post_process_newreminder(
|
return _receive_new_post_process_newreminder(
|
||||||
self, fields,
|
self, fields,
|
||||||
nickname,
|
nickname,
|
||||||
|
@ -1891,7 +2028,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
buy_sites,
|
buy_sites,
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type)
|
proxy_type)
|
||||||
elif post_type == 'newreport':
|
if post_type == 'newreport':
|
||||||
return _receive_new_post_process_newreport(
|
return _receive_new_post_process_newreport(
|
||||||
self, fields,
|
self, fields,
|
||||||
attachment_media_type,
|
attachment_media_type,
|
||||||
|
@ -1908,7 +2045,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
translate, auto_cw_cache,
|
translate, auto_cw_cache,
|
||||||
project_version,
|
project_version,
|
||||||
curr_session, proxy_type)
|
curr_session, proxy_type)
|
||||||
elif post_type == 'newquestion':
|
if post_type == 'newquestion':
|
||||||
return _receive_new_post_process_newquestion(
|
return _receive_new_post_process_newquestion(
|
||||||
self, fields, city, base_dir, nickname,
|
self, fields, city, base_dir, nickname,
|
||||||
domain, domain_full, http_prefix,
|
domain, domain_full, http_prefix,
|
||||||
|
@ -1918,7 +2055,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
low_bandwidth, translate, auto_cw_cache,
|
low_bandwidth, translate, auto_cw_cache,
|
||||||
debug, project_version, curr_session,
|
debug, project_version, curr_session,
|
||||||
proxy_type)
|
proxy_type)
|
||||||
elif post_type in ('newreadingstatus'):
|
if post_type == 'newreadingstatus':
|
||||||
return _receive_new_post_process_newreading(
|
return _receive_new_post_process_newreading(
|
||||||
self, fields,
|
self, fields,
|
||||||
post_type,
|
post_type,
|
||||||
|
@ -1963,119 +2100,28 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
|
||||||
project_version,
|
project_version,
|
||||||
proxy_type,
|
proxy_type,
|
||||||
max_replies)
|
max_replies)
|
||||||
elif post_type in ('newshare', 'newwanted'):
|
if post_type in ('newshare', 'newwanted'):
|
||||||
if not fields.get('itemQty'):
|
return _receive_new_post_process_newshare(
|
||||||
print(post_type + ' no itemQty')
|
self, fields,
|
||||||
return -1
|
post_type,
|
||||||
if not fields.get('itemType'):
|
attachment_media_type,
|
||||||
print(post_type + ' no itemType')
|
city, base_dir,
|
||||||
return -1
|
nickname, domain,
|
||||||
if 'itemPrice' not in fields:
|
http_prefix, port,
|
||||||
print(post_type + ' no itemPrice')
|
filename, debug,
|
||||||
return -1
|
translate,
|
||||||
if 'itemCurrency' not in fields:
|
|
||||||
print(post_type + ' no itemCurrency')
|
|
||||||
return -1
|
|
||||||
if not fields.get('category'):
|
|
||||||
print(post_type + ' no category')
|
|
||||||
return -1
|
|
||||||
if not fields.get('duration'):
|
|
||||||
print(post_type + ' no duratio')
|
|
||||||
return -1
|
|
||||||
if attachment_media_type:
|
|
||||||
if attachment_media_type != 'image':
|
|
||||||
print('Attached media is not an image')
|
|
||||||
return -1
|
|
||||||
duration_str = fields['duration']
|
|
||||||
if duration_str:
|
|
||||||
if ' ' not in duration_str:
|
|
||||||
duration_str = duration_str + ' days'
|
|
||||||
city = get_spoofed_city(city, base_dir, nickname, domain)
|
|
||||||
item_qty = 1
|
|
||||||
if fields['itemQty']:
|
|
||||||
if is_float(fields['itemQty']):
|
|
||||||
item_qty = float(fields['itemQty'])
|
|
||||||
item_price = "0.00"
|
|
||||||
item_currency = "EUR"
|
|
||||||
if fields['itemPrice']:
|
|
||||||
item_price, item_currency = \
|
|
||||||
get_price_from_string(fields['itemPrice'])
|
|
||||||
if fields['itemCurrency']:
|
|
||||||
item_currency = fields['itemCurrency']
|
|
||||||
if post_type == 'newshare':
|
|
||||||
print('Adding shared item')
|
|
||||||
shares_file_type = 'shares'
|
|
||||||
else:
|
|
||||||
print('Adding wanted item')
|
|
||||||
shares_file_type = 'wanted'
|
|
||||||
share_on_profile = False
|
|
||||||
if fields.get('shareOnProfile'):
|
|
||||||
if fields['shareOnProfile'] == 'on':
|
|
||||||
share_on_profile = True
|
|
||||||
add_share(base_dir, http_prefix, nickname, domain, port,
|
|
||||||
fields['subject'],
|
|
||||||
fields['message'],
|
|
||||||
filename,
|
|
||||||
item_qty, fields['itemType'],
|
|
||||||
fields['category'],
|
|
||||||
fields['location'],
|
|
||||||
duration_str,
|
|
||||||
debug,
|
|
||||||
city, item_price, item_currency,
|
|
||||||
fields['languagesDropdown'],
|
|
||||||
translate, shares_file_type,
|
|
||||||
low_bandwidth,
|
low_bandwidth,
|
||||||
content_license_url,
|
content_license_url,
|
||||||
share_on_profile,
|
block_federated,
|
||||||
block_federated)
|
calling_domain,
|
||||||
if post_type == 'newshare':
|
domain_full,
|
||||||
# add shareOnProfile items to the actor attachments
|
|
||||||
# https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md
|
|
||||||
actor = \
|
|
||||||
get_instance_url(calling_domain,
|
|
||||||
http_prefix, domain_full,
|
|
||||||
onion_domain,
|
onion_domain,
|
||||||
i2p_domain) + \
|
i2p_domain,
|
||||||
'/users/' + nickname
|
person_cache,
|
||||||
actor_json = get_person_from_cache(base_dir,
|
max_shares_on_profile,
|
||||||
actor, person_cache)
|
|
||||||
if not actor_json:
|
|
||||||
actor_filename = \
|
|
||||||
acct_dir(base_dir, nickname, domain) + '.json'
|
|
||||||
if os.path.isfile(actor_filename):
|
|
||||||
actor_json = load_json(actor_filename, 1, 1)
|
|
||||||
if actor_json:
|
|
||||||
if add_shares_to_actor(base_dir, nickname, domain,
|
|
||||||
actor_json,
|
|
||||||
max_shares_on_profile):
|
|
||||||
remove_person_from_cache(base_dir,
|
|
||||||
actor, person_cache)
|
|
||||||
store_person_in_cache(base_dir, actor,
|
|
||||||
actor_json, person_cache,
|
|
||||||
True)
|
|
||||||
actor_filename = \
|
|
||||||
acct_dir(base_dir, nickname, domain) + '.json'
|
|
||||||
save_json(actor_json, actor_filename)
|
|
||||||
# send profile update to followers
|
|
||||||
update_actor_json = \
|
|
||||||
get_actor_update_json(actor_json)
|
|
||||||
print('Sending actor update ' +
|
|
||||||
'after change to attached shares: ' +
|
|
||||||
str(update_actor_json))
|
|
||||||
post_to_outbox(self, update_actor_json,
|
|
||||||
project_version,
|
project_version,
|
||||||
nickname,
|
curr_session,
|
||||||
curr_session, proxy_type)
|
proxy_type)
|
||||||
|
|
||||||
if filename:
|
|
||||||
if os.path.isfile(filename):
|
|
||||||
try:
|
|
||||||
os.remove(filename)
|
|
||||||
except OSError:
|
|
||||||
print('EX: _receive_new_post_process ' +
|
|
||||||
'unable to delete ' + filename)
|
|
||||||
self.post_to_nickname = nickname
|
|
||||||
return 1
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue