diff --git a/app/middleware/api_token_registrator.rb b/app/middleware/api_token_registrator.rb deleted file mode 100644 index 5650c55..0000000 --- a/app/middleware/api_token_registrator.rb +++ /dev/null @@ -1,31 +0,0 @@ -class ApiTokenRegistrator - - def initialize(app) - @app = app - end - - def call(env) - request = Rack::Request.new(env) - auth = Rack::Auth::Basic::Request.new(env) - - if request.post? && request.path == '/api/asciicasts' - if auth.provided? && auth.basic? && auth.credentials - ensure_user_with_token(*auth.credentials) - end - end - - @app.call(env) - - rescue ActiveRecord::RecordInvalid - [401, { 'Content-Type' => 'text/plain' }, 'Invalid token'] - end - - private - - def ensure_user_with_token(username, token) - unless ApiToken.where(token: token).exists? - ApiToken.create_with_tmp_user!(token, username) - end - end - -end diff --git a/app/middleware/metadata_parser.rb b/app/middleware/metadata_parser.rb deleted file mode 100644 index e3f834b..0000000 --- a/app/middleware/metadata_parser.rb +++ /dev/null @@ -1,26 +0,0 @@ -class MetadataParser - - def initialize(app) - @app = app - end - - def call(env) - request = Rack::Request.new(env) - auth = Rack::Auth::Basic::Request.new(env) - - if request.post? && request.path == '/api/asciicasts' - if request.params['asciicast']['meta'] # pre "format 1" client - meta = JSON.parse(request.params['asciicast']['meta'][:tempfile].read) - request.params['asciicast']['meta'] = meta - - username, token = meta.delete('username'), meta.delete('user_token') - if token.present? && !auth.provided? || !auth.basic? - env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(username, token) - end - end - end - - @app.call(env) - end - -end diff --git a/config/application.rb b/config/application.rb index f347db9..42f702a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -48,9 +48,6 @@ module Asciinema rewrite /%7E(.+)/i, '/~$1' end - config.middleware.use 'MetadataParser' - config.middleware.use 'ApiTokenRegistrator' - config.middleware.use 'Warden::Manager' do |manager| manager.failure_app = ApplicationController manager.scope_defaults(