From 6934b77bd833c4d0a5ac70f52bafe6ff8f1f6882 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Fri, 23 Aug 2024 03:56:10 +0300 Subject: [PATCH] Fix importing of bookmarks from TOML. --- blasta.py | 64 +++++++++------- xhtml/profile.xhtml | 179 +++++++++++++++++++++++--------------------- 2 files changed, 132 insertions(+), 111 deletions(-) diff --git a/blasta.py b/blasta.py index 1201ffa..885ed26 100644 --- a/blasta.py +++ b/blasta.py @@ -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,33 +1463,45 @@ 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: - 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'], - 'link' : entry['link'], - 'summary' : entry['summary'], - 'published' : entry['published'], - 'updated' : entry['published'], - #'updated' : entry['updated'], - 'tags' : entry['tags'], - 'url_hash' : url_hash, - 'jid' : jabber_id, - 'name' : name, - 'instances' : instances} - #message = 'Discover new links and see who shares them' - xmpp_instance = accounts[jabber_id] - payload = Syndication.create_rfc4287_entry(entry) - 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 = 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_new = { + 'title' : entry['title'], + 'link' : entry['link'], + 'summary' : entry['summary'], + 'published' : entry['published'], + 'updated' : entry['published'], + #'updated' : entry['updated'], + 'tags' : entry['tags'], + 'url_hash' : url_hash, + 'jid' : jabber_id, + 'name' : name, + 'instances' : instances} + #message = 'Discover new links and see who shares them' + xmpp_instance = accounts[jabber_id] + 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) + counter += 1 + + message = 'Blasta system message » Imported {} items.'.format(counter) description = 'Import successful' path = 'profile' return result_post(request, jabber_id, description, message, path) diff --git a/xhtml/profile.xhtml b/xhtml/profile.xhtml index 70f2a34..439e935 100644 --- a/xhtml/profile.xhtml +++ b/xhtml/profile.xhtml @@ -117,10 +117,10 @@
+ href="/profile/export/private/json"> JSON, + href="/profile/export/private/toml"> TOML.
@@ -128,10 +128,10 @@
+ href="/profile/export/public/json"> JSON, + href="/profile/export/public/toml"> TOML.
@@ -139,10 +139,10 @@
+ href="/profile/export/read/json"> JSON, + href="/profile/export/read/toml"> TOML.
@@ -153,9 +153,9 @@ your bookmarks to.

+ enctype="multipart/form-data" + id="import" + method="post"> @@ -179,20 +179,20 @@ @@ -204,19 +204,20 @@
@@ -165,10 +165,10 @@ + name="file" + placeholder="Select a file to import." + required="" + type="file" />
+ name="node" + required="" + type="radio" + value="private"/> + name="node" + type="radio" + value="public"/> + name="node" + type="radio" + value="read"/>
+ disabled="" + name="merge" + type="checkbox"/> + checked="" + disabled="" + name="override" + type="checkbox"/> @@ -229,10 +230,12 @@ merge tags.">
+ type="submit" + value="Import Bookmarks"/>
-

Permissions

+

+ Permissions +

Choose the desired @@ -250,25 +253,24 @@ merge tags."> + {% if access_models['private'] == 'authorize' %}checked=""{% endif %} + disabled="" + name="private" + type="radio"/> + {% if access_models['private'] == 'whitelist' %}checked=""{% endif %} + disabled="" + name="private" + type="radio"/> @@ -282,14 +284,14 @@ retrieve items only if on a whitelist managed by the node owner."> + {% if access_models['public'] == 'open' %}checked=""{% endif %} + disabled="" + name="public" + type="radio"/> @@ -300,8 +302,8 @@ may retrieve items from the node (i.e., without being subscribed)."> name="public" type="radio"/>

Routine

+

+ Routine +

Choose a routine (i.e. default) directory (i.e. node).

+ method="post"> - + - + - +