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

View file

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