routes.rb 9.92 KB
Newer Older
Eugen Rochko's avatar
Eugen Rochko committed
1 2
# frozen_string_literal: true

3
require 'sidekiq/web'
alpaca-tc's avatar
alpaca-tc committed
4
require 'sidekiq-scheduler/web'
5

6 7
Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]

Eugen Rochko's avatar
Eugen Rochko committed
8
Rails.application.routes.draw do
Eugen Rochko's avatar
Eugen Rochko committed
9
  mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
10

11
  authenticate :user, lambda { |u| u.admin? } do
Eugen Rochko's avatar
Eugen Rochko committed
12 13
    mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
    mount PgHero::Engine, at: 'pghero', as: :pghero
14 15
  end

16
  use_doorkeeper do
17
    controllers authorizations: 'oauth/authorizations', authorized_applications: 'oauth/authorized_applications'
18
  end
19

20
  get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
21
  get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
22
  get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
23
  get 'intent', to: 'intents#show'
Eugen Rochko's avatar
Eugen Rochko committed
24

Eugen Rochko's avatar
Eugen Rochko committed
25 26
  devise_scope :user do
    get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
27
    match '/auth/finish_signup' => 'auth/confirmations#finish_signup', via: [:get, :patch], as: :finish_signup
Eugen Rochko's avatar
Eugen Rochko committed
28 29
  end

30
  devise_for :users, path: 'auth', controllers: {
31
    omniauth_callbacks: 'auth/omniauth_callbacks',
32 33
    sessions:           'auth/sessions',
    registrations:      'auth/registrations',
Eugen Rochko's avatar
Eugen Rochko committed
34
    passwords:          'auth/passwords',
Eugen Rochko's avatar
Eugen Rochko committed
35
    confirmations:      'auth/confirmations',
36
  }
37

38
  get '/users/:username', to: redirect('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
39

40
  resources :accounts, path: 'users', only: [:show], param: :username do
41 42 43 44 45
    resources :stream_entries, path: 'updates', only: [:show] do
      member do
        get :embed
      end
    end
46

Eugen Rochko's avatar
Eugen Rochko committed
47 48 49
    get :remote_follow,  to: 'remote_follow#new'
    post :remote_follow, to: 'remote_follow#create'

50 51 52
    resources :statuses, only: [:show] do
      member do
        get :activity
Eugen Rochko's avatar
Eugen Rochko committed
53
        get :embed
54 55 56
      end
    end

57 58
    resources :followers, only: [:index], controller: :follower_accounts
    resources :following, only: [:index], controller: :following_accounts
Eugen Rochko's avatar
Eugen Rochko committed
59
    resource :follow, only: [:create], controller: :account_follow
60
    resource :unfollow, only: [:create], controller: :account_unfollow
61

62
    resource :outbox, only: [:show], module: :activitypub
Eugen Rochko's avatar
Eugen Rochko committed
63
    resource :inbox, only: [:create], module: :activitypub
64
    resources :collections, only: [:show], module: :activitypub
65
  end
Eugen Rochko's avatar
Eugen Rochko committed
66

67 68
  resource :inbox, only: [:create], module: :activitypub

69
  get '/@:username', to: 'accounts#show', as: :short_account
70 71
  get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  get '/@:username/media', to: 'accounts#show', as: :short_account_media
72
  get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
Eugen Rochko's avatar
Eugen Rochko committed
73
  get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
74

Eugen Rochko's avatar
Eugen Rochko committed
75 76 77
  namespace :settings do
    resource :profile, only: [:show, :update]
    resource :preferences, only: [:show, :update]
78
    resource :notifications, only: [:show, :update]
79
    resource :import, only: [:show, :create]
80

81
    resource :export, only: [:show, :create]
82 83 84
    namespace :exports, constraints: { format: :csv } do
      resources :follows, only: :index, controller: :following_accounts
      resources :blocks, only: :index, controller: :blocked_accounts
85
      resources :mutes, only: :index, controller: :muted_accounts
86
    end
87

88 89 90 91
    resource :two_factor_authentication, only: [:show, :create, :destroy]
    namespace :two_factor_authentication do
      resources :recovery_codes, only: [:create]
      resource :confirmation, only: [:new, :create]
92
    end
Eugen's avatar
Eugen committed
93 94

    resource :follower_domains, only: [:show, :update]
95

96 97 98 99
    resources :applications, except: [:edit] do
      member do
        post :regenerate
      end
100 101
    end

Eugen Rochko's avatar
Eugen Rochko committed
102
    resource :delete, only: [:show, :destroy]
103
    resource :migration, only: [:show, :update]
104 105

    resources :sessions, only: [:destroy]
Eugen Rochko's avatar
Eugen Rochko committed
106 107
  end

108 109 110 111
  resources :media, only: [:show] do
    get :player
  end

112 113
  resources :tags,   only: [:show]
  resources :emojis, only: [:show]
Eugen Rochko's avatar
Eugen Rochko committed
114
  resources :invites, only: [:index, :create, :destroy]
115

116 117
  get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy

118
  # Remote follow
119
  resource :authorize_follow, only: [:show, :create]
120
  resource :share, only: [:show, :create]
121

122
  namespace :admin do
123
    resources :subscriptions, only: [:index]
124
    resources :domain_blocks, only: [:index, :new, :create, :show, :destroy]
utam0k's avatar
utam0k committed
125
    resources :email_domain_blocks, only: [:index, :new, :create, :destroy]
126
    resources :action_logs, only: [:index]
127
    resource :settings, only: [:edit, :update]
Eugen Rochko's avatar
Eugen Rochko committed
128
    resources :invites, only: [:index, :create, :destroy]
129

130 131 132 133 134
    resources :instances, only: [:index] do
      collection do
        post :resubscribe
      end
    end
135

136
    resources :reports, only: [:index, :show, :update] do
abcang's avatar
abcang committed
137
      resources :reported_statuses, only: [:create, :update, :destroy]
138
    end
139

140
    resources :accounts, only: [:index, :show] do
141 142 143
      member do
        post :subscribe
        post :unsubscribe
144 145
        post :enable
        post :disable
146
        post :redownload
147
        post :remove_avatar
148
        post :memorialize
149 150
      end

151
      resource :reset, only: [:create]
152 153
      resource :silence, only: [:create, :destroy]
      resource :suspension, only: [:create, :destroy]
154
      resource :confirmation, only: [:create]
abcang's avatar
abcang committed
155
      resources :statuses, only: [:index, :create, :update, :destroy]
156 157 158 159 160 161 162

      resource :role do
        member do
          post :promote
          post :demote
        end
      end
163
    end
164 165 166 167

    resources :users, only: [] do
      resource :two_factor_authentication, only: [:destroy]
    end
168

169
    resources :custom_emojis, only: [:index, :new, :create, :update, :destroy] do
170 171 172 173 174 175
      member do
        post :copy
        post :enable
        post :disable
      end
    end
nullkal's avatar
nullkal committed
176 177

    resources :account_moderation_notes, only: [:create, :destroy]
178 179
  end

180 181 182 183 184 185 186
  authenticate :user, lambda { |u| u.admin? } do
    get '/admin', to: redirect('/admin/settings/edit', status: 302)
  end

  authenticate :user, lambda { |u| u.moderator? } do
    get '/admin', to: redirect('/admin/reports', status: 302)
  end
187

188
  namespace :api do
Eugen Rochko's avatar
Eugen Rochko committed
189
    # PubSubHubbub outgoing subscriptions
190 191
    resources :subscriptions, only: [:show]
    post '/subscriptions/:id', to: 'subscriptions#update'
192

Eugen Rochko's avatar
Eugen Rochko committed
193 194 195
    # PubSubHubbub incoming subscriptions
    post '/push', to: 'push#update', as: :push

196
    # Salmon
197
    post '/salmon/:id', to: 'salmon#update', as: :salmon
198

199 200 201
    # OEmbed
    get '/oembed', to: 'oembed#show', as: :oembed

202
    # JSON / REST API
203 204
    namespace :v1 do
      resources :statuses, only: [:create, :show, :destroy] do
205
        scope module: :statuses do
206 207 208 209 210 211 212 213 214 215
          resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
          resources :favourited_by, controller: :favourited_by_accounts, only: :index
          resource :reblog, only: :create
          post :unreblog, to: 'reblogs#destroy'

          resource :favourite, only: :create
          post :unfavourite, to: 'favourites#destroy'

          resource :mute, only: :create
          post :unmute, to: 'mutes#destroy'
Eugen Rochko's avatar
Eugen Rochko committed
216 217 218

          resource :pin, only: :create
          post :unpin, to: 'pins#destroy'
219 220
        end

221 222
        member do
          get :context
223
          get :card
224
        end
225 226
      end

227 228 229 230
      namespace :timelines do
        resource :home, only: :show, controller: :home
        resource :public, only: :show, controller: :public
        resources :tag, only: :show
Eugen Rochko's avatar
Eugen Rochko committed
231
        resources :list, only: :show
232
      end
Eugen Rochko's avatar
Eugen Rochko committed
233 234

      resources :streaming, only: [:index]
235
      resources :custom_emojis, only: [:index]
236

Eugen Rochko's avatar
Eugen Rochko committed
237 238
      get '/search', to: 'search#index', as: :search

239
      resources :follows,    only: [:create]
240
      resources :media,      only: [:create, :update]
241
      resources :blocks,     only: [:index]
242
      resources :mutes,      only: [:index]
243
      resources :favourites, only: [:index]
244
      resources :reports,    only: [:index, :create]
245

246 247 248 249 250 251
      namespace :apps do
        get :verify_credentials, to: 'credentials#show'
      end

      resources :apps, only: [:create]

252 253 254 255 256
      resource :instance, only: [:show] do
        resources :peers, only: [:index], controller: 'instances/peers'
        resource :activity, only: [:show], controller: 'instances/activity'
      end

Eugen Rochko's avatar
Eugen Rochko committed
257
      resource :domain_blocks, only: [:show, :create, :destroy]
258

Eugen Rochko's avatar
Eugen Rochko committed
259 260 261 262 263 264 265
      resources :follow_requests, only: [:index] do
        member do
          post :authorize
          post :reject
        end
      end

266 267 268
      resources :notifications, only: [:index, :show] do
        collection do
          post :clear
269
          post :dismiss
270 271
        end
      end
272

273 274 275 276 277 278
      namespace :accounts do
        get :verify_credentials, to: 'credentials#show'
        patch :update_credentials, to: 'credentials#update'
        resource :search, only: :show, controller: :search
        resources :relationships, only: :index
      end
Eugen Rochko's avatar
Eugen Rochko committed
279

280
      resources :accounts, only: [:show] do
281 282 283
        resources :statuses, only: :index, controller: 'accounts/statuses'
        resources :followers, only: :index, controller: 'accounts/follower_accounts'
        resources :following, only: :index, controller: 'accounts/following_accounts'
284
        resources :lists, only: :index, controller: 'accounts/lists'
285 286 287 288

        member do
          post :follow
          post :unfollow
Eugen Rochko's avatar
Eugen Rochko committed
289 290
          post :block
          post :unblock
291 292
          post :mute
          post :unmute
293
        end
294
      end
Eugen Rochko's avatar
Eugen Rochko committed
295 296 297 298

      resources :lists, only: [:index, :create, :show, :update, :destroy] do
        resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
      end
299
    end
300 301 302

    namespace :web do
      resource :settings, only: [:update]
Eugen Rochko's avatar
Eugen Rochko committed
303
      resource :embed, only: [:create]
Sorin Davidoi's avatar
Sorin Davidoi committed
304 305 306 307 308
      resources :push_subscriptions, only: [:create] do
        member do
          put :update
        end
      end
309
    end
310
  end
Eugen Rochko's avatar
Eugen Rochko committed
311

312
  get '/web/(*any)', to: 'home#index', as: :web
313

Matt Jankowski's avatar
Matt Jankowski committed
314
  get '/about',      to: 'about#show'
Eugen Rochko's avatar
Eugen Rochko committed
315 316
  get '/about/more', to: 'about#more'
  get '/terms',      to: 'about#terms'
317

Eugen Rochko's avatar
Eugen Rochko committed
318
  root 'home#index'
Eugen Rochko's avatar
Eugen Rochko committed
319

320
  match '*unmatched_route',
Eugen Rochko's avatar
Eugen Rochko committed
321 322 323
        via: :all,
        to: 'application#raise_not_found',
        format: false
Eugen Rochko's avatar
Eugen Rochko committed
324
end