Fix importing of bookmarks from TOML.

This commit is contained in:
Schimon Jehudah, Adv. 2024-08-23 03:56:10 +03:00
parent 3024f57466
commit 6934b77bd8
2 changed files with 132 additions and 111 deletions

View file

@ -1444,17 +1444,17 @@ class HttpInstance:
override: str = Form(None)):
jabber_id = Utilities.is_jid_matches_to_session(accounts, sessions, request)
if jabber_id:
xmpp_instance = accounts[jabber_id]
if file:
# TODO If node does not exist, redirect to result page with
# a message that bookmarks are empty.
# NOTE No.
# TODO match/case public, private, read
node_id = node[node]['name']
node_title = node[node]['title']
node_subtitle = node[node]['subtitle']
node_access_model = node[node]['access_model']
node_id = nodes[node]['name']
node_title = nodes[node]['title']
node_subtitle = nodes[node]['subtitle']
node_access_model = nodes[node]['access_model']
if not await XmppPubsub.is_node_exist(xmpp_instance, node_id):
iq = XmppPubsub.create_node_atom(
xmpp_instance, jabber_id, node_id, node_title,
@ -1463,16 +1463,26 @@ class HttpInstance:
#return {"filename": file.filename}
content = file.file.read().decode()
# TODO Add match/case for filetype.
entries = tomllib.loads(content)
# entries_node = entries[node]
#breakpoint()
#for entry in entries: print(entry)
name = jabber_id.split('@')[0]
# timestamp = datetime.now().isoformat()
db_file = 'main.sqlite'
for entry in entries:
counter = 0
for entry_type in entries:
for entry in entries[entry_type]:
url_hash = item_id = Utilities.hash_url_to_md5(entry['link'])
instances = SQLite.get_entry_instances_by_url_hash(db_file, url_hash)
entry = {'title' : entry['title'],
entry_new = {
'title' : entry['title'],
'link' : entry['link'],
'summary' : entry['summary'],
'published' : entry['published'],
@ -1485,11 +1495,13 @@ class HttpInstance:
'instances' : instances}
#message = 'Discover new links and see who shares them'
xmpp_instance = accounts[jabber_id]
payload = Syndication.create_rfc4287_entry(entry)
payload = Syndication.create_rfc4287_entry(entry_new)
iq = await XmppPubsub.publish_node_item(
xmpp_instance, jabber_id, node_id, item_id, payload)
#await iq.send(timeout=15)
message = 'Blasta system message » Imported {} items.'.format(len(entries))
counter += 1
message = 'Blasta system message » Imported {} items.'.format(counter)
description = 'Import successful'
path = 'profile'
return result_post(request, jabber_id, description, message, path)

View file

@ -212,6 +212,7 @@
Merge
</label>
<input id="override"
checked=""
disabled=""
name="override"
type="checkbox"/>
@ -232,7 +233,9 @@ merge tags.">
type="submit"
value="Import Bookmarks"/>
</form>
<h4 id="permissions">Permissions</h4>
<h4 id="permissions">
Permissions
</h4>
<p>
Choose the desired
<a href="https://xmpp.org/extensions/xep-0060.html#accessmodels">
@ -255,9 +258,8 @@ merge tags.">
name="private"
type="radio"/>
<label for="private-authorize"
title="The node owner must approve
all subscription requests, and only subscribers may retrieve items from the
node.">
title="The node owner must approve all
subscription requests, and only subscribers may retrieve items from the node.">
Authorize
</label>
</td>
@ -287,9 +289,9 @@ retrieve items only if on a whitelist managed by the node owner.">
name="public"
type="radio"/>
<label for="public-open"
title="Any entity may subscribe to
the node (i.e., without the necessity for subscription approval) and any entity
may retrieve items from the node (i.e., without being subscribed).">
title="Any entity may subscribe to the
node (i.e., without the necessity for subscription approval) and any entity may
retrieve items from the node (i.e., without being subscribed).">
Open
</label>
</td>
@ -300,8 +302,8 @@ may retrieve items from the node (i.e., without being subscribed).">
name="public"
type="radio"/>
<label for="public-presence"
title="Any entity with a subscription
of type 'from' or 'both' may subscribe to the node and retrieve items from the
title="Any entity with a subscription of
type 'from' or 'both' may subscribe to the node and retrieve items from the
node; this access model applies mainly to instant messaging systems (see RFC
3921).">
Presence
@ -314,9 +316,9 @@ node; this access model applies mainly to instant messaging systems (see RFC
name="public"
type="radio"/>
<label for="public-roster"
title="Any entity in the specified
roster group(s) may subscribe to the node and retrieve items from the node; this
access model applies mainly to instant messaging systems (see RFC 3921).">
title="Any entity in the specified roster
group(s) may subscribe to the node and retrieve items from the node; this access
model applies mainly to instant messaging systems (see RFC 3921).">
Roster
</label>
</td>
@ -334,9 +336,8 @@ access model applies mainly to instant messaging systems (see RFC 3921).">
name="read"
type="radio"/>
<label for="read-authorize"
title="The node owner must approve
all subscription requests, and only subscribers may retrieve items from the
node.">
title="The node owner must approve all
subscription requests, and only subscribers may retrieve items from the node.">
Authorize
</label>
</td>
@ -363,7 +364,9 @@ retrieve items only if on a whitelist managed by the node owner.">
type="reset"
value="Reset Permissions"/>
</form>
<h4 id="routine">Routine</h4>
<h4 id="routine">
Routine
</h4>
<p>
Choose a routine (i.e. default) directory (i.e. node).
</p>
@ -375,19 +378,25 @@ retrieve items only if on a whitelist managed by the node owner.">
required=""
type="radio"
value="private"/>
<label for="routine-private">Private</label>
<label for="routine-private">
Private
</label>
<input id="routine-public"
{% if not routine or routine == 'public' %}checked=""{% endif %}
name="routine"
type="radio"
value="public"/>
<label for="routine-public">Public</label>
<label for="routine-public">
Public
</label>
<input id="routine-read"
{% if routine == 'read' %}checked=""{% endif %}
name="routine"
type="radio"
value="read"/>
<label for="routine-read">Read</label>
<label for="routine-read">
Read
</label>
<br/>
<input class="submit"
type="submit"