Don't forget to lycansubscribe

added endpoint to check import status

Changed files
+43 -1
app
+23
app/models/user.rb
··· 78 78 [:likes, :reposts, :quotes, :pins].map { |x| self.send(x).in_queue(queue).to_a }.reduce(&:+) 79 79 end 80 80 81 + def imported_until 82 + return nil unless self.imports.exists? 83 + 84 + oldest_imported_items = [] 85 + started = false 86 + 87 + [:likes, :reposts, :pins, :quotes].each do |group| 88 + if self.send(group).where(queue: :import).exists? 89 + oldest_imported_items << self.send(group).where(queue: nil).order(:time).first 90 + end 91 + end 92 + 93 + earliest_oldest = oldest_imported_items.compact.sort_by(&:time).last 94 + 95 + if earliest_oldest 96 + earliest_oldest.time 97 + elsif self.imports.merge(Import.unfinished).exists? 98 + nil 99 + else 100 + :end 101 + end 102 + end 103 + 81 104 def delete_posts_cascading 82 105 posts_subquery = self.posts.select(:id) 83 106
+20 -1
app/server.rb
··· 38 38 end 39 39 40 40 begin 41 - did = @authenticator.decode_user_from_jwt(auth_header, 'blue.feeds.lycan.searchPosts') 41 + method = request.path.split('/')[2] 42 + did = @authenticator.decode_user_from_jwt(auth_header, method) 42 43 rescue StandardError => e 43 44 halt json_error('InvalidToken', e.message, status: 401) 44 45 end ··· 110 111 end 111 112 112 113 json_response(terms: query.terms, posts: post_uris, cursor: items.last&.cursor) 114 + end 115 + 116 + get '/xrpc/blue.feeds.lycan.getImportStatus' do 117 + headers['access-control-allow-origin'] = '*' 118 + 119 + did = get_user_did 120 + user = User.find_by(did: did) 121 + until_date = user&.imported_until 122 + 123 + case until_date 124 + when nil 125 + json_response(status: 'not_started') 126 + when :end 127 + json_response(status: 'finished') 128 + else 129 + progress = 1 - (until_date - user.registered_at) / (Time.now - user.registered_at) 130 + json_response(status: 'in_progress', position: until_date.iso8601, progress: progress) 131 + end 113 132 end 114 133 115 134 get '/.well-known/did.json' do