kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
2c19a5a3af
commit
e217419747
|
@ -14,7 +14,7 @@ import cachetools
|
|||
from Crypto.PublicKey import RSA
|
||||
from flask import g, request
|
||||
from google.cloud import ndb
|
||||
from granary import as1, as2, bluesky, microformats2
|
||||
from granary import as1, as2, atom, bluesky, microformats2
|
||||
from granary.source import html_to_text
|
||||
from oauth_dropins.webutil import util
|
||||
from oauth_dropins.webutil.appengine_info import DEBUG
|
||||
|
@ -537,6 +537,7 @@ class Object(StringIdModel):
|
|||
# TODO: switch back to ndb.JsonProperty if/when they fix it for the web console
|
||||
# https://github.com/googleapis/python-ndb/issues/874
|
||||
as2 = JsonProperty() # only one of the rest will be populated...
|
||||
atom = ndb.TextProperty() # Atom XML, usually from Superfeedr
|
||||
bsky = JsonProperty() # Bluesky / AT Protocol
|
||||
mf2 = JsonProperty() # HTML microformats2 item (ie _not_ the top level
|
||||
# parse object with items inside an 'items' field)
|
||||
|
@ -596,6 +597,9 @@ class Object(StringIdModel):
|
|||
if url := util.get_url(obj, field):
|
||||
as1.get_object(obj, field).setdefault('id', url)
|
||||
|
||||
elif self.atom:
|
||||
obj = atom.atom_to_activity(self.atom)
|
||||
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
|
@ -574,6 +574,28 @@ class ObjectTest(TestCase):
|
|||
self.assertEqual({'id': 'x', 'foo': 'bar'},
|
||||
Object(id='x', our_as1={'foo': 'bar'}).as1)
|
||||
|
||||
def test_as1_from_atom(self):
|
||||
self.assert_equals({
|
||||
'objectType': 'activity',
|
||||
'id': 'reply-url',
|
||||
'url': 'reply-url',
|
||||
'object': {
|
||||
'id': 'reply-url',
|
||||
'url': 'reply-url',
|
||||
'content': 'I hereby ☕ reply.',
|
||||
},
|
||||
}, Object(atom="""\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<entry xmlns="http://www.w3.org/2005/Atom">
|
||||
<uri>reply-url</uri>
|
||||
<content>I hereby ☕ reply.</content>
|
||||
</entry>
|
||||
""").as1)
|
||||
|
||||
self.assertEqual({'foo': 'bar'}, Object(our_as1={'foo': 'bar'}).as1)
|
||||
self.assertEqual({'id': 'x', 'foo': 'bar'},
|
||||
Object(id='x', our_as1={'foo': 'bar'}).as1)
|
||||
|
||||
@patch('requests.get', return_value=requests_response(DID_DOC))
|
||||
def test_as1_from_bsky(self, mock_get):
|
||||
like_bsky = {
|
||||
|
|
Ładowanie…
Reference in New Issue