Remove unused middleware
parent
7fc377f38e
commit
f45cce4f81
@ -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
|
|
@ -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
|
|
Loading…
Reference in New Issue