forked from sch/Blasta
Fix importing of bookmarks from TOML.
This commit is contained in:
parent
3024f57466
commit
6934b77bd8
2 changed files with 132 additions and 111 deletions
64
blasta.py
64
blasta.py
|
@ -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,33 +1463,45 @@ 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
|
||||||
url_hash = item_id = Utilities.hash_url_to_md5(entry['link'])
|
|
||||||
instances = SQLite.get_entry_instances_by_url_hash(db_file, url_hash)
|
for entry_type in entries:
|
||||||
entry = {'title' : entry['title'],
|
for entry in entries[entry_type]:
|
||||||
'link' : entry['link'],
|
url_hash = item_id = Utilities.hash_url_to_md5(entry['link'])
|
||||||
'summary' : entry['summary'],
|
instances = SQLite.get_entry_instances_by_url_hash(db_file, url_hash)
|
||||||
'published' : entry['published'],
|
entry_new = {
|
||||||
'updated' : entry['published'],
|
'title' : entry['title'],
|
||||||
#'updated' : entry['updated'],
|
'link' : entry['link'],
|
||||||
'tags' : entry['tags'],
|
'summary' : entry['summary'],
|
||||||
'url_hash' : url_hash,
|
'published' : entry['published'],
|
||||||
'jid' : jabber_id,
|
'updated' : entry['published'],
|
||||||
'name' : name,
|
#'updated' : entry['updated'],
|
||||||
'instances' : instances}
|
'tags' : entry['tags'],
|
||||||
#message = 'Discover new links and see who shares them'
|
'url_hash' : url_hash,
|
||||||
xmpp_instance = accounts[jabber_id]
|
'jid' : jabber_id,
|
||||||
payload = Syndication.create_rfc4287_entry(entry)
|
'name' : name,
|
||||||
iq = await XmppPubsub.publish_node_item(
|
'instances' : instances}
|
||||||
xmpp_instance, jabber_id, node_id, item_id, payload)
|
#message = 'Discover new links and see who shares them'
|
||||||
#await iq.send(timeout=15)
|
xmpp_instance = accounts[jabber_id]
|
||||||
message = 'Blasta system message » Imported {} items.'.format(len(entries))
|
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'
|
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)
|
||||||
|
|
|
@ -117,10 +117,10 @@
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a download="{{jabber_id}}_private.json"
|
<a download="{{jabber_id}}_private.json"
|
||||||
href="/profile/export/private/json">
|
href="/profile/export/private/json">
|
||||||
JSON</a>,
|
JSON</a>,
|
||||||
<a download="{{jabber_id}}_private.toml"
|
<a download="{{jabber_id}}_private.toml"
|
||||||
href="/profile/export/private/toml">
|
href="/profile/export/private/toml">
|
||||||
TOML</a>.
|
TOML</a>.
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
|
@ -128,10 +128,10 @@
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a download="{{jabber_id}}_public.json"
|
<a download="{{jabber_id}}_public.json"
|
||||||
href="/profile/export/public/json">
|
href="/profile/export/public/json">
|
||||||
JSON</a>,
|
JSON</a>,
|
||||||
<a download="{{jabber_id}}_public.toml"
|
<a download="{{jabber_id}}_public.toml"
|
||||||
href="/profile/export/public/toml">
|
href="/profile/export/public/toml">
|
||||||
TOML</a>.
|
TOML</a>.
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
|
@ -139,10 +139,10 @@
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a download="{{jabber_id}}_read.json"
|
<a download="{{jabber_id}}_read.json"
|
||||||
href="/profile/export/read/json">
|
href="/profile/export/read/json">
|
||||||
JSON</a>,
|
JSON</a>,
|
||||||
<a download="{{jabber_id}}_read.toml"
|
<a download="{{jabber_id}}_read.toml"
|
||||||
href="/profile/export/read/toml">
|
href="/profile/export/read/toml">
|
||||||
TOML</a>.
|
TOML</a>.
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -153,9 +153,9 @@
|
||||||
your bookmarks to.
|
your bookmarks to.
|
||||||
</p>
|
</p>
|
||||||
<form action="/profile/import"
|
<form action="/profile/import"
|
||||||
enctype="multipart/form-data"
|
enctype="multipart/form-data"
|
||||||
id="import"
|
id="import"
|
||||||
method="post">
|
method="post">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
@ -165,10 +165,10 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="file"
|
<input id="file"
|
||||||
name="file"
|
name="file"
|
||||||
placeholder="Select a file to import."
|
placeholder="Select a file to import."
|
||||||
required=""
|
required=""
|
||||||
type="file" />
|
type="file" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -179,20 +179,20 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="node-private"
|
<input id="node-private"
|
||||||
name="node"
|
name="node"
|
||||||
required=""
|
required=""
|
||||||
type="radio"
|
type="radio"
|
||||||
value="private"/>
|
value="private"/>
|
||||||
<label for="node-private">Private</label>
|
<label for="node-private">Private</label>
|
||||||
<input id="node-public"
|
<input id="node-public"
|
||||||
name="node"
|
name="node"
|
||||||
type="radio"
|
type="radio"
|
||||||
value="public"/>
|
value="public"/>
|
||||||
<label for="node-public">Public</label>
|
<label for="node-public">Public</label>
|
||||||
<input id="node-read"
|
<input id="node-read"
|
||||||
name="node"
|
name="node"
|
||||||
type="radio"
|
type="radio"
|
||||||
value="read"/>
|
value="read"/>
|
||||||
<label for="node-read">Read</label>
|
<label for="node-read">Read</label>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -204,19 +204,20 @@
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="merge"
|
<input id="merge"
|
||||||
disabled=""
|
disabled=""
|
||||||
name="merge"
|
name="merge"
|
||||||
type="checkbox"/>
|
type="checkbox"/>
|
||||||
<label for="merge"
|
<label for="merge"
|
||||||
title="Merge tags.">
|
title="Merge tags.">
|
||||||
Merge
|
Merge
|
||||||
</label>
|
</label>
|
||||||
<input id="override"
|
<input id="override"
|
||||||
disabled=""
|
checked=""
|
||||||
name="override"
|
disabled=""
|
||||||
type="checkbox"/>
|
name="override"
|
||||||
|
type="checkbox"/>
|
||||||
<label for="override"
|
<label for="override"
|
||||||
title="Replace properties by the
|
title="Replace properties by the
|
||||||
properties of the imported entries.">
|
properties of the imported entries.">
|
||||||
Override
|
Override
|
||||||
</label>
|
</label>
|
||||||
|
@ -229,10 +230,12 @@ merge tags.">
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input class="submit"
|
<input class="submit"
|
||||||
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">
|
||||||
|
@ -250,25 +253,24 @@ merge tags.">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="private-authorize"
|
<input id="private-authorize"
|
||||||
{% if access_models['private'] == 'authorize' %}checked=""{% endif %}
|
{% if access_models['private'] == 'authorize' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
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>
|
||||||
<td>
|
<td>
|
||||||
<input id="private-whitelist"
|
<input id="private-whitelist"
|
||||||
{% if access_models['private'] == 'whitelist' %}checked=""{% endif %}
|
{% if access_models['private'] == 'whitelist' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
name="private"
|
name="private"
|
||||||
type="radio"/>
|
type="radio"/>
|
||||||
<label for="private-whitelist"
|
<label for="private-whitelist"
|
||||||
title="An entity may subscribe or
|
title="An entity may subscribe or
|
||||||
retrieve items only if on a whitelist managed by the node owner.">
|
retrieve items only if on a whitelist managed by the node owner.">
|
||||||
Whitelist
|
Whitelist
|
||||||
</label>
|
</label>
|
||||||
|
@ -282,14 +284,14 @@ retrieve items only if on a whitelist managed by the node owner.">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="public-open"
|
<input id="public-open"
|
||||||
{% if access_models['public'] == 'open' %}checked=""{% endif %}
|
{% if access_models['public'] == 'open' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
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
|
||||||
|
@ -309,14 +311,14 @@ node; this access model applies mainly to instant messaging systems (see RFC
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="public-roster"
|
<input id="public-roster"
|
||||||
{% if access_models['public'] == 'roster' %}checked=""{% endif %}
|
{% if access_models['public'] == 'roster' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
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>
|
||||||
|
@ -329,25 +331,24 @@ access model applies mainly to instant messaging systems (see RFC 3921).">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input id="read-authorize"
|
<input id="read-authorize"
|
||||||
{% if access_models['read'] == 'authorize' %}checked=""{% endif %}
|
{% if access_models['read'] == 'authorize' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
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>
|
||||||
<td>
|
<td>
|
||||||
<input id="read-whitelist"
|
<input id="read-whitelist"
|
||||||
{% if access_models['read'] == 'whitelist' %}checked=""{% endif %}
|
{% if access_models['read'] == 'whitelist' %}checked=""{% endif %}
|
||||||
disabled=""
|
disabled=""
|
||||||
name="read"
|
name="read"
|
||||||
type="radio"/>
|
type="radio"/>
|
||||||
<label for="read-whitelist"
|
<label for="read-whitelist"
|
||||||
title="An entity may subscribe or
|
title="An entity may subscribe or
|
||||||
retrieve items only if on a whitelist managed by the node owner.">
|
retrieve items only if on a whitelist managed by the node owner.">
|
||||||
Whitelist
|
Whitelist
|
||||||
</label>
|
</label>
|
||||||
|
@ -355,39 +356,47 @@ retrieve items only if on a whitelist managed by the node owner.">
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<input class="submit"
|
<input class="submit"
|
||||||
disabled=""
|
disabled=""
|
||||||
type="submit"
|
type="submit"
|
||||||
value="Save Permissions"/>
|
value="Save Permissions"/>
|
||||||
<input class="submit"
|
<input class="submit"
|
||||||
disabled=""
|
disabled=""
|
||||||
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>
|
||||||
<form action="/profile"
|
<form action="/profile"
|
||||||
method="post">
|
method="post">
|
||||||
<input id="routine-private"
|
<input id="routine-private"
|
||||||
{% if routine == 'private' %}checked=""{% endif %}
|
{% if routine == 'private' %}checked=""{% endif %}
|
||||||
name="routine"
|
name="routine"
|
||||||
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"
|
||||||
|
|
Loading…
Reference in a new issue