activitypub 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/activitypub/base.rb +8 -4
- data/lib/activitypub/resolvers.rb +46 -0
- data/lib/activitypub/types.rb +3 -3
- data/lib/activitypub/uri.rb +6 -9
- data/lib/activitypub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d306bc2763af88f633f0645a032d1e0ed47e5a790b140ad566e6a53fdf9aeea
|
4
|
+
data.tar.gz: 2f12fc9aa91aa64fedd909b68b6182ae2ed352e2bb06e80e60a65ee0f6ad4e6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b154f2bcf3cb03386947ea1f137f55b53461c0dcaa0a6fde15c5098b276c809620fe3f94f90d110b416dd29b31a9ff75a5f5376d1cdaefaa98e5e9f713fd4c4c
|
7
|
+
data.tar.gz: 44ca4b68aa880bed6a62a92e757c4e48ead8afb5f4b71fb300c8156729062d79f9ac15333ba38e2e776c52c89dc03701070ef84040e8b5033ead9d7cac03eb25
|
data/lib/activitypub/base.rb
CHANGED
@@ -6,11 +6,11 @@ module ActivityPub
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
8
8
|
|
9
|
-
def self.from_json(json)
|
10
|
-
from_hash(JSON.parse(json))
|
9
|
+
def self.from_json(json, resolver: nil)
|
10
|
+
from_hash(JSON.parse(json), resolver:)
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.from_hash(h)
|
13
|
+
def self.from_hash(h, resolver: nil)
|
14
14
|
type = h&.dig("type")
|
15
15
|
|
16
16
|
raise Error, "'type' attribute is required" if !type
|
@@ -21,6 +21,7 @@ module ActivityPub
|
|
21
21
|
klass = ActivityPub.const_get(type)
|
22
22
|
|
23
23
|
ob = klass ? klass.new : nil
|
24
|
+
ob._resolver = resolver
|
24
25
|
|
25
26
|
# FIXME: Useful for debug. Add flag to allow enabling.
|
26
27
|
# ob.instance_variable_set("@_raw",h)
|
@@ -41,7 +42,8 @@ module ActivityPub
|
|
41
42
|
end
|
42
43
|
|
43
44
|
if t = klass.ap_types[attr]
|
44
|
-
v = t.new(v) if v
|
45
|
+
v = t.new(v) if v && !v.kind_of?(ActivityPub::Base)
|
46
|
+
v._resolver = ob._resolver if v
|
45
47
|
end
|
46
48
|
ob.instance_variable_set("@#{attr}", v) if !v.nil?
|
47
49
|
end
|
@@ -57,6 +59,8 @@ module ActivityPub
|
|
57
59
|
def _context = @_context || "https://www.w3.org/ns/activitystreams"
|
58
60
|
def _type = self.class.name.split("::").last
|
59
61
|
|
62
|
+
attr_accessor :_resolver
|
63
|
+
|
60
64
|
|
61
65
|
# FIXME: Allow specifying a type (e.g. URI)
|
62
66
|
def self.ap_attr(name, type=nil)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
require 'uri'
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
# Classes to resolve URI's into objects.
|
6
|
+
|
7
|
+
|
8
|
+
module ActivityPub
|
9
|
+
|
10
|
+
class WebResolver
|
11
|
+
def self.call(path)
|
12
|
+
response = Faraday.get(path, {}, {"Accept": "application/activity+json"})
|
13
|
+
if response.status == 200
|
14
|
+
ActivityPub.from_json(response.body)
|
15
|
+
else
|
16
|
+
response
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# UnsafeResolver supports filesystem references. It's named as it is to make
|
23
|
+
# you stop and think. If you load remote objects and allow the use of UnsafeResolver,
|
24
|
+
# it *will* try to load things from your filesystem. If you subsequently
|
25
|
+
# allow access to that data in ways that are not strictly controlled, you run
|
26
|
+
# the risk of a security hole.
|
27
|
+
#
|
28
|
+
# A future version will likely allow containing this to specific paths,
|
29
|
+
# but currently it makes *NO ATTEMPTS* to sanitise paths, so paths including
|
30
|
+
# ".." etc. will allow filesystem traversal.
|
31
|
+
#
|
32
|
+
class UnsafeResolver
|
33
|
+
def initialize(base)
|
34
|
+
@base = base
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(path)
|
38
|
+
path = File.expand_path(File.join(@base, path))
|
39
|
+
if File.exist?(path)
|
40
|
+
data = File.read(path)
|
41
|
+
return ActivityPub.from_json(data)
|
42
|
+
end
|
43
|
+
WebResolver.call(path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/activitypub/types.rb
CHANGED
@@ -25,7 +25,7 @@ module ActivityPub
|
|
25
25
|
class Object < Base
|
26
26
|
ap_attr :id
|
27
27
|
ap_attr :attachment
|
28
|
-
ap_attr :attributedTo
|
28
|
+
ap_attr :attributedTo, URI
|
29
29
|
ap_attr :audience
|
30
30
|
ap_attr :content
|
31
31
|
ap_attr :context
|
@@ -238,8 +238,8 @@ module ActivityPub
|
|
238
238
|
|
239
239
|
# Mastodon extension per
|
240
240
|
# https://docs-p.joinmastodon.org/spec/activitypub/#extensions
|
241
|
-
ap_attr :likes
|
242
|
-
ap_attr :bookmarks
|
241
|
+
ap_attr :likes, URI
|
242
|
+
ap_attr :bookmarks, URI
|
243
243
|
ap_attr :manuallyApprovesFollowers
|
244
244
|
end
|
245
245
|
|
data/lib/activitypub/uri.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
require 'faraday'
|
2
|
+
require_relative 'resolvers'
|
4
3
|
|
5
4
|
module ActivityPub
|
6
5
|
class URI
|
7
|
-
|
6
|
+
attr_accessor :_resolver
|
7
|
+
|
8
|
+
def initialize(href, resolver: nil)
|
8
9
|
@href = href
|
10
|
+
@_resolver = resolver || WebResolver
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_s = @href
|
12
14
|
def to_json(...) = @href
|
13
15
|
|
14
16
|
def get
|
15
|
-
|
16
|
-
if response.status == 200
|
17
|
-
ActivityPub.from_json(response.body)
|
18
|
-
else
|
19
|
-
response
|
20
|
-
end
|
17
|
+
@_resolver&.call(self.to_s)
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
data/lib/activitypub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activitypub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vidar Hokstad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webfinger
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- examples/get_actor.rb
|
41
41
|
- lib/activitypub.rb
|
42
42
|
- lib/activitypub/base.rb
|
43
|
+
- lib/activitypub/resolvers.rb
|
43
44
|
- lib/activitypub/types.rb
|
44
45
|
- lib/activitypub/uri.rb
|
45
46
|
- lib/activitypub/version.rb
|