jekyll-activity-pub 0.1.0rc1 → 0.1.0rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77756fcc84da5788d84a8d2719177e87c7a6113bac9783e3542b116a03e2bc75
4
- data.tar.gz: e2722d852839f02c6af42e742bc3a13d2618ecd4b091dd218c5cd5d6f1af3016
3
+ metadata.gz: b11d1c8910e7b917bc7dbb039eaac2ded7907e5b1ada47dfd163f8aa9e2d0673
4
+ data.tar.gz: f0396377184e52144764a6fcb94c952c1ce99f174fcb5716762dd21aee45e6f1
5
5
  SHA512:
6
- metadata.gz: 777fd56a8128d654ebcd19344c1872144c8e553abd42960b95973d208241e25326171f38fb7af019f769f7fd6929b41de8b84421481567f3420020562005310d
7
- data.tar.gz: 4194053ad320923b07bd822acfd78adc902d54000577c899f61c305b2d6a8dfba458458508f8e5cb54029952b9863b7b9a3d015858892642156b9c4266840b89
6
+ metadata.gz: 83f87b84b22d33e5d2c0b1b7d4efb3bfc0ba5aafd1e6e35dcf54c6469992b46288956676f5024f6e277c6880d568507f22abdcdd6bfadefe92a33e95c78e4fb9
7
+ data.tar.gz: cc268a2c2a7d00daaa2222744713a61407384d696c95af74c8be5a5dd4cea41beccb22bfa69297ba7bc3aab82ca519135517ee48a03487c99b45798d22b467f1
@@ -3,6 +3,7 @@
3
3
  require 'jekyll/page'
4
4
  require_relative 'helper'
5
5
  require_relative 'document'
6
+ require_relative 'notifier'
6
7
 
7
8
  module Jekyll
8
9
  module ActivityPub
@@ -52,7 +53,7 @@ module Jekyll
52
53
  'to' => [
53
54
  'https://www.w3.org/ns/activitystreams#Public'
54
55
  ],
55
- 'cc' => [],
56
+ 'cc' => [ Notifier.followers_url ],
56
57
  'inReplyTo' => doc.data['in_reply_to'],
57
58
  'sensitive' => sensitive?,
58
59
  'content' => doc.content,
@@ -24,6 +24,10 @@ module Jekyll
24
24
  super
25
25
 
26
26
  Notifier.actor_url = data['id']
27
+ Notifier.actor = "@#{username}@#{hostname}"
28
+
29
+ data['following'] = Notifier.following_url
30
+ data['followers'] = Notifier.followers_url
27
31
 
28
32
  trigger_hooks :post_init
29
33
  end
@@ -95,13 +99,14 @@ module Jekyll
95
99
 
96
100
  def inbox
97
101
  @inbox ||=
98
- site.config.dig('activity_pub', 'url').tap do |inbox|
102
+ site.config.dig('activity_pub', 'url').dup.tap do |inbox|
99
103
  value_is_required! inbox, MissingInboxError
100
104
 
101
105
  inbox << '/v1/@'
102
106
  inbox << username
103
107
  inbox << '@'
104
108
  inbox << hostname
109
+ inbox << '/inbox'
105
110
  end
106
111
  end
107
112
  end
@@ -14,9 +14,8 @@ module Jekyll
14
14
  #
15
15
  # @param :site [Jekyll::Site]
16
16
  # @param :actor [Jekyll::ActivityPub::Actor]
17
- # @param :followers [Jekyll::ActivityPub::Followers]
18
17
  # @param :object [Jekyll::ActivityPub::Activity]
19
- def initialize(site, actor, followers, object)
18
+ def initialize(site, actor, object)
20
19
  @context = StubContext.new(registers: { site: site })
21
20
 
22
21
  @data = {
@@ -24,12 +23,8 @@ module Jekyll
24
23
  'type' => 'Create',
25
24
  'actor' => absolute_url(actor.url),
26
25
  'published' => object.data['published'],
27
- 'to' => [
28
- 'https://www.w3.org/ns/activitystreams#Public'
29
- ],
30
- 'cc' => [
31
- absolute_url(followers.url)
32
- ],
26
+ 'to' => object.data['to'],
27
+ 'cc' => object.data['cc'],
33
28
  'object' => absolute_url(object.url),
34
29
  'inReplyTo' => object.data['in_reply_to']
35
30
  }
@@ -8,9 +8,8 @@ module Jekyll
8
8
  #
9
9
  # @param :site [Jekyll::Site]
10
10
  # @param :actor [Jekyll::ActivityPub::Actor]
11
- # @param :followers [Jekyll::ActivityPub::Followers]
12
11
  # @param :object [Jekyll::ActivityPub::Activity]
13
- def initialize(site, actor, _followers, object)
12
+ def initialize(site, actor, object)
14
13
  @context = StubContext.new(registers: { site: site })
15
14
 
16
15
  @data = {
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'pathname'
4
4
  require 'httparty'
5
+ require 'distributed_press/version'
5
6
  require 'distributed_press/v1/social/client'
6
7
  require_relative 'errors'
7
8
  require_relative 'create'
@@ -16,7 +17,7 @@ module Jekyll
16
17
  # Jekyll's build process.
17
18
  class Notifier
18
19
  # An struct that responds to a #url method
19
- PseudoObject = Struct.new(:url, keyword_init: true)
20
+ PseudoObject = Struct.new(:url, :data, keyword_init: true)
20
21
 
21
22
  class << self
22
23
  # Set the site and initialize data
@@ -30,6 +31,16 @@ module Jekyll
30
31
  end
31
32
  end
32
33
 
34
+ # @return [String]
35
+ def followers_url
36
+ "#{config['url']}/v1/#{actor}/followers"
37
+ end
38
+
39
+ # @return [String]
40
+ def following_url
41
+ "#{config['url']}/v1/#{actor}/following"
42
+ end
43
+
33
44
  # Save the public key URL for later
34
45
  #
35
46
  # @param :url [String]
@@ -74,23 +85,34 @@ module Jekyll
74
85
  "Could't fetch public key (#{response.code}: #{response.message})"
75
86
  end
76
87
 
77
- unless client.private_key.compare? OpenSSL::Pkey::RSA.new(response.body)
88
+ unless client.private_key.compare? OpenSSL::PKey::RSA.new(response.body)
78
89
  raise NotificationError, "Public key at #{public_key_url} differs from local version"
79
90
  end
80
91
 
81
- base_endpoint = "/v1/#{actor}/"
82
- outbox_endpoint = "#{base_endpoint}/outbox/"
92
+ base_endpoint = "/v1/#{actor}"
93
+ outbox_endpoint = "#{base_endpoint}/outbox"
83
94
  actor_object = PseudoObject.new(url: actor_url)
95
+ # TODO: Move to API client
96
+ inbox_body = {
97
+ 'actorUrl' => actor_url,
98
+ 'publicKeyId' => public_key_url,
99
+ 'keypair' => {
100
+ 'publicKeyPem' => client.public_key.public_to_pem,
101
+ 'privateKeyPem' => client.private_key.export
102
+ }
103
+ }
84
104
 
85
105
  # Create inbox
86
- # TODO: Send keypair
87
- client.post(endpoint: base_endpoint, body: {})
106
+ unless (response = client.post(endpoint: base_endpoint, body: inbox_body)).ok?
107
+ raise NotificationError, "Couldn't create inbox (#{response.code}: #{response.message})"
108
+ end
88
109
 
89
110
  # Remove notifications already performed and notify
90
111
  data['notifications'].reject do |object_url, status|
91
112
  done? object_url, status
92
113
  end.each do |object_url, status|
93
- process_object(outbox_endpoint, actor_object, PseudoObject.new(url: object_url), status)
114
+ object = PseudoObject.new(url: object_url, data: JSON.parse(File.read(site.in_dest_dir(object_url))))
115
+ process_object(outbox_endpoint, actor_object, object, status)
94
116
  end
95
117
 
96
118
  # Store everything for later
@@ -117,12 +139,13 @@ module Jekyll
117
139
  action(path, 'delete') if exist? path
118
140
  end
119
141
 
120
- # Updates an activity if it was previously created
142
+ # Updates an activity if it was previously created, otherwise
143
+ # create it
121
144
  #
122
145
  # @param :path [String]
123
146
  # @return [Hash]
124
147
  def update(path)
125
- action(path, 'update') if exist? path
148
+ action(path, exist?(path) ? 'update' : 'create')
126
149
  end
127
150
 
128
151
  # Creates an activity
@@ -208,7 +231,8 @@ module Jekyll
208
231
  @@client ||= DistributedPress::V1::Social::Client.new(
209
232
  private_key_pem: private_key,
210
233
  url: config['url'],
211
- public_key_url: public_key_url
234
+ public_key_url: public_key_url,
235
+ logger: Jekyll.logger
212
236
  )
213
237
  end
214
238
 
@@ -248,19 +272,19 @@ module Jekyll
248
272
  # @return [nil]
249
273
  def process_object(endpoint, actor, object, status)
250
274
  action = status['action']
251
- activity = Object.const_get(action.capitalize).new(site, actor, object)
275
+ activity = Object.const_get("Jekyll::ActivityPub::#{action.capitalize}").new(site, actor, object)
252
276
 
253
277
  if (response = client.post(endpoint: endpoint, body: activity)).ok?
254
278
  status['action'] = 'done'
255
279
  status["#{action}d_at"] = Time.now.to_i
256
280
  else
257
281
  Jekyll.logger.warn 'ActivityPub:',
258
- "Couldn't perform #{action} for #{object_url} (#{response.code}: #{response.message})"
282
+ "Couldn't perform #{action} for #{object.url} (#{response.code}: #{response.message})"
259
283
  end
260
284
 
261
285
  nil
262
286
  rescue NameError
263
- Jekyll.logger.warn 'ActivityPub:', "Action \"#{action}\" for #{url} unrecognized, ignoring."
287
+ Jekyll.logger.warn 'ActivityPub:', "Action \"#{action}\" for #{object.url} unrecognized, ignoring."
264
288
  end
265
289
  end
266
290
  end
@@ -10,9 +10,8 @@ module Jekyll
10
10
  #
11
11
  # @param :site [Jekyll::Site]
12
12
  # @param :actor [Jekyll::ActivityPub::Actor]
13
- # @param :followers [Jekyll::ActivityPub::Followers]
14
13
  # @param :object [Jekyll::ActivityPub::Activity]
15
- def initialize(site, actor, followers, object)
14
+ def initialize(site, actor, object)
16
15
  super
17
16
 
18
17
  data['type'] = 'Update'
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'jekyll/page'
4
4
  require_relative 'helper'
5
- require_relative 'notifier'
6
5
 
7
6
  module Jekyll
8
7
  module ActivityPub
@@ -23,8 +22,6 @@ module Jekyll
23
22
 
24
23
  super(site, base, dir, name)
25
24
 
26
- Notifier.actor = "@#{username}@#{hostname}"
27
-
28
25
  # Set the actor profile in yet another format (no leading @)
29
26
  site.config['activity_pub_profile'] = "#{username}@#{hostname}"
30
27
 
@@ -4,8 +4,6 @@ require_relative 'activity_pub/webfinger'
4
4
  require_relative 'activity_pub/actor'
5
5
  require_relative 'activity_pub/activity'
6
6
  require_relative 'activity_pub/outbox'
7
- require_relative 'activity_pub/followers'
8
- require_relative 'activity_pub/following'
9
7
  require_relative 'activity_pub/host_meta'
10
8
  require_relative 'activity_pub/create'
11
9
  require_relative 'activity_pub/update'
@@ -27,8 +27,6 @@ Jekyll::Hooks.register :site, :post_read, priority: :low do |site|
27
27
  site.pages << site.config['webfinger'] = webfinger = Jekyll::ActivityPub::WebFinger.new(site, actor)
28
28
  site.pages << site.config['outbox'] = Jekyll::ActivityPub::Outbox.new(site, actor)
29
29
  site.pages << site.config['host-meta'] = Jekyll::ActivityPub::HostMeta.new(site, webfinger)
30
- site.pages << Jekyll::ActivityPub::Following.new(site, actor)
31
- site.pages << site.config['followers'] = Jekyll::ActivityPub::Followers.new(site, actor)
32
30
 
33
31
  # Add Actor to home page
34
32
  home = site.pages.find do |page|
@@ -53,7 +51,6 @@ Jekyll::Hooks.register(:documents, :post_convert, priority: :high) do |doc|
53
51
  name = "#{File.basename(doc.url, '.html')}.jsonld"
54
52
  actor = site.config['actor']
55
53
  outbox = site.config['outbox']
56
- followers = site.config['followers']
57
54
 
58
55
  Jekyll::ActivityPub::Activity.new(site, actor, doc, nil, dir, name).tap do |activity|
59
56
  doc.data['activity'] = activity
@@ -68,7 +65,7 @@ Jekyll::Hooks.register(:documents, :post_convert, priority: :high) do |doc|
68
65
  Jekyll::ActivityPub::Create
69
66
  end
70
67
 
71
- create_or_update.new(site, actor, followers, activity).tap do |action|
68
+ create_or_update.new(site, actor, activity).tap do |action|
72
69
  Jekyll::ActivityPub::Notifier.public_send action.data['type'].downcase.to_sym, activity.destination(site.dest)
73
70
 
74
71
  outbox.data['totalItems'] += 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-activity-pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0rc1
4
+ version: 0.1.0rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sutty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-30 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: distributed-press-api-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0rc0
19
+ version: 0.3.0rc3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.0rc0
26
+ version: 0.3.0rc3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jekyll
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -135,8 +135,6 @@ files:
135
135
  - lib/jekyll/activity_pub/delete.rb
136
136
  - lib/jekyll/activity_pub/document.rb
137
137
  - lib/jekyll/activity_pub/errors.rb
138
- - lib/jekyll/activity_pub/followers.rb
139
- - lib/jekyll/activity_pub/following.rb
140
138
  - lib/jekyll/activity_pub/helper.rb
141
139
  - lib/jekyll/activity_pub/host_meta.rb
142
140
  - lib/jekyll/activity_pub/image.rb
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'ordered_collection'
4
-
5
- module Jekyll
6
- module ActivityPub
7
- # An empty collection of followers
8
- class Followers < OrderedCollection
9
- # Initialize with default data
10
- #
11
- # @param :site [Jekyll::Site]
12
- # @param :actor [Jekyll::ActivityPub::Actor]
13
- # @param :base [String]
14
- # @param :dir [String]
15
- # @param :name [String]
16
- def initialize(site, actor, base = '', dir = '', name = 'followers.jsonld')
17
- super(site, base, dir, name)
18
-
19
- actor.data['followers'] = absolute_url(url)
20
-
21
- trigger_hooks :post_init
22
- end
23
- end
24
- end
25
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'ordered_collection'
4
-
5
- module Jekyll
6
- module ActivityPub
7
- # An empty collection of followed actors
8
- class Following < OrderedCollection
9
- # Initialize with default data
10
- #
11
- # @param :site [Jekyll::Site]
12
- # @param :actor [Jekyll::ActivityPub::Actor]
13
- # @param :base [String]
14
- # @param :dir [String]
15
- # @param :name [String]
16
- def initialize(site, actor, base = '', dir = '', name = 'following.jsonld')
17
- super(site, base, dir, name)
18
-
19
- actor.data['following'] = absolute_url(url)
20
-
21
- trigger_hooks :post_init
22
- end
23
- end
24
- end
25
- end