tangled
alpha
login
or
join now
mackuba.eu
/
lycan
35
fork
atom
Don't forget to lycansubscribe
35
fork
atom
overview
issues
1
pulls
pipelines
indentation
mackuba.eu
5 months ago
a0b7bb49
2656e0bf
+26
-28
1 changed file
expand all
collapse all
unified
split
app
post_downloader.rb
+26
-28
app/post_downloader.rb
···
36
36
end
37
37
38
38
def process_items(items)
39
39
-
#
40
40
-
existing_posts = Post.where(rkey: items.map { |x| AT_URI(x.post_uri).rkey }).to_a
39
39
+
existing_posts = Post.where(rkey: items.map { |x| AT_URI(x.post_uri).rkey }).to_a
41
40
42
42
-
items.dup.each do |item|
43
43
-
if post = existing_posts.detect { |post| post.at_uri == item.post_uri }
44
44
-
update_item(item, post)
45
45
-
items.delete(item)
46
46
-
end
41
41
+
items.dup.each do |item|
42
42
+
if post = existing_posts.detect { |post| post.at_uri == item.post_uri }
43
43
+
update_item(item, post)
44
44
+
items.delete(item)
47
45
end
46
46
+
end
48
47
49
49
-
return if items.empty?
48
48
+
return if items.empty?
50
49
51
51
-
begin
52
52
-
response = @sky.get_request('app.bsky.feed.getPosts', { uris: items.map(&:post_uri).uniq })
50
50
+
begin
51
51
+
response = @sky.get_request('app.bsky.feed.getPosts', { uris: items.map(&:post_uri).uniq })
53
52
54
54
-
response['posts'].each do |data|
55
55
-
begin
56
56
-
item = items.detect { |x| x.post_uri == data['uri'] }
57
57
-
items.delete(item)
53
53
+
response['posts'].each do |data|
54
54
+
begin
55
55
+
item = items.detect { |x| x.post_uri == data['uri'] }
56
56
+
items.delete(item)
58
57
59
59
-
post = save_post(data['uri'], data['record'])
58
58
+
post = save_post(data['uri'], data['record'])
60
59
61
61
-
if post.valid?
62
62
-
update_item(item, post)
63
63
-
else
64
64
-
puts "Invalid post #{item.post_uri}: #{post.errors.full_messages.join("; ")}"
65
65
-
invalidate_item(item)
66
66
-
end
67
67
-
rescue StandardError => e
68
68
-
puts "Error in PostDownloader: #{item.post_uri}: #{e.class}: #{e}"
60
60
+
if post.valid?
61
61
+
update_item(item, post)
62
62
+
else
63
63
+
puts "Invalid post #{item.post_uri}: #{post.errors.full_messages.join("; ")}"
64
64
+
invalidate_item(item)
69
65
end
66
66
+
rescue StandardError => e
67
67
+
puts "Error in PostDownloader: #{item.post_uri}: #{e.class}: #{e}"
70
68
end
69
69
+
end
71
70
72
72
-
check_missing_items(items)
73
73
-
rescue StandardError => e
74
74
-
puts "Error in PostDownloader: #{e.class}: #{e}"
75
75
-
end
76
76
-
#
71
71
+
check_missing_items(items)
72
72
+
rescue StandardError => e
73
73
+
puts "Error in PostDownloader: #{e.class}: #{e}"
74
74
+
end
77
75
end
78
76
79
77
def save_post(post_uri, record)