autogestione_controller.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # frozen_string_literal: true
  2. class Api::V1::Timelines::AutogestioneController < Api::BaseController
  3. before_action :require_user!, only: [:show], if: :require_auth?
  4. after_action :insert_pagination_headers, unless: -> { @statuses.empty? }
  5. def show
  6. @statuses = load_statuses
  7. render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
  8. end
  9. private
  10. def call_api
  11. #bida = URI('https://mastodon.bida.im/api/v1/timelines/public?local=true&only_media=false')
  12. #bida_res = Net::HTTP.get_response(bida)
  13. #json_bida_res=bida_res.body
  14. cisti = URI('https://mastodon.cisti.org/api/v1/timelines/public?local=true&only_media=false')
  15. cisti_res = Net::HTTP.get_response(cisti)
  16. json_cisti_res=cisti_res.body
  17. nebbia = URI('https://nebbia.fail/api/v1/timelines/public?local=true&only_media=false')
  18. nebbia_res = Net::HTTP.get_response(nebbia)
  19. json_cisti_res=cisti_res.body
  20. #bida_arr = JSON.parse(json_bida_res)
  21. cisti_arr = JSON.parse(json_cisti_res)
  22. nebbia_arr = JSON.parse(json_cisti_res)
  23. union = cisti_arr + nebbia_arr
  24. union.sort_by{ |e| e['created_at'] }.to_json
  25. end
  26. def require_auth?
  27. !Setting.timeline_preview
  28. end
  29. def load_statuses
  30. cached_public_statuses_page
  31. end
  32. def cached_public_statuses_page
  33. cache_collection(public_statuses, Status)
  34. end
  35. def public_statuses
  36. public_feed.get(
  37. limit_param(DEFAULT_STATUSES_LIMIT),
  38. params[:max_id],
  39. params[:since_id],
  40. params[:min_id]
  41. )
  42. end
  43. def public_feed
  44. PublicFeed.new(
  45. current_account,
  46. autogestione: true,
  47. local: truthy_param?(:local),
  48. remote: truthy_param?(:remote),
  49. only_media: truthy_param?(:only_media)
  50. )
  51. end
  52. def insert_pagination_headers
  53. set_pagination_headers(next_path, prev_path)
  54. end
  55. def pagination_params(core_params)
  56. params.slice(:local, :remote, :limit, :only_media).permit(:local, :remote, :limit, :only_media).merge(core_params)
  57. end
  58. def next_path
  59. api_v1_timelines_public_url pagination_params(max_id: pagination_max_id)
  60. end
  61. def prev_path
  62. api_v1_timelines_autogestione_url pagination_params(min_id: pagination_since_id)
  63. end
  64. def pagination_max_id
  65. @statuses.last.id
  66. end
  67. def pagination_since_id
  68. @statuses.first.id
  69. end
  70. end