tangled
alpha
login
or
join now
mackuba.eu
/
blue_factory
1
fork
atom
A simple Ruby server using Sinatra that serves Bluesky custom feeds
1
fork
atom
overview
issues
pulls
pipelines
add option of context and reason fields for posts
mackuba.eu
5 months ago
aa3ce734
5cd474cf
+44
-5
1 changed file
expand all
collapse all
unified
split
lib
blue_factory
server.rb
+44
-5
lib/blue_factory/server.rb
···
64
64
65
65
posts = response[:posts]
66
66
raise InvalidResponseError, ":posts key is missing" unless response.has_key?(:posts)
67
67
-
raise InvalidResponseError, ":posts should be an array of strings" unless posts.is_a?(Array)
68
68
-
raise InvalidResponseError, ":posts should be an array of strings" unless posts.all? { |x| x.is_a?(String) }
67
67
+
raise InvalidResponseError, ":posts should be an array" unless posts.is_a?(Array)
68
68
+
# raise InvalidResponseError, ":posts should be an array of strings" unless posts.all? { |x| x.is_a?(String) }
69
69
+
#
70
70
+
# if bad_uri = posts.detect { |x| x !~ AT_URI_REGEXP }
71
71
+
# raise InvalidResponseError, "Invalid post URI: #{bad_uri}"
72
72
+
# end
73
73
+
end
74
74
+
75
75
+
def process_post_object(object)
76
76
+
if object.is_a?(String)
77
77
+
return { post: object }
78
78
+
end
79
79
+
80
80
+
post = {}
81
81
+
82
82
+
if object[:post]
83
83
+
post[:post] = object[:post]
84
84
+
else
85
85
+
raise InvalidResponseError, "post hash is missing a :post key"
86
86
+
end
87
87
+
88
88
+
if object[:reason]
89
89
+
post[:reason] = process_post_reason(object[:reason])
90
90
+
end
91
91
+
92
92
+
if object[:context]
93
93
+
post[:feedContext] = object[:context]
94
94
+
end
95
95
+
96
96
+
post
97
97
+
end
69
98
70
70
-
if bad_uri = posts.detect { |x| x !~ AT_URI_REGEXP }
71
71
-
raise InvalidResponseError, "Invalid post URI: #{bad_uri}"
99
99
+
def process_post_reason(reason)
100
100
+
if reason[:repost]
101
101
+
{
102
102
+
"$type" => "app.bsky.feed.defs#skeletonReasonRepost",
103
103
+
"repost" => reason[:repost]
104
104
+
}
105
105
+
elsif reason[:pin]
106
106
+
{
107
107
+
"$type" => "app.bsky.feed.defs#skeletonReasonPin"
108
108
+
}
109
109
+
else
110
110
+
raise InvalidResponseError, "invalid post reason: #{reason.inspect}"
72
111
end
73
112
end
74
113
end
···
94
133
validate_response(response) if config.validate_responses
95
134
96
135
output = {}
97
97
-
output[:feed] = response[:posts].map { |s| { post: s }}
136
136
+
output[:feed] = response[:posts].map { |x| process_post_object(x) }
98
137
output[:cursor] = response[:cursor] if response[:cursor]
99
138
output[:reqId] = response[:req_id] if response[:req_id]
100
139