returnrender_error(YiffyAPIErrorCodes::API_KEY_REQUIRED,error:"An API key is required to access this service.")ifrequest.headers["Authorization"].blank?
returnrender_error(YiffyAPIErrorCodes::INVALID_API_KEY,error:"Invalid api key.")unless@apikey
returnrender_error(YiffyAPIErrorCodes::INACTIVE_API_KEY,error:"Api key is inactive.")unless@apikey.active?
if@apikey.disabled?
extra={
reason:@apikey.disabled_reason,
support:"https://yiff.rest/support",
code:YiffyAPIErrorCodes::DISABLED_API_KEY.code,
}
render_error(YiffyAPIErrorCodes::DISABLED_API_KEY,error:"Your api key has been disabled by an administrator. See \"extra.reason\" for the reasoning.",extra:extra)
end
CurrentUser.user=@apikey.owner
end
defvalidate_images_access
@apikey=APIKey.from_request(request)
render_error(YiffyAPIErrorCodes::SERVICE_NO_ACCESS,error:"You do not have access to this service.")unless@apikey.images_access?
end
defvalidate_thumbs_access
@apikey=APIKey.from_request(request)
render_error(YiffyAPIErrorCodes::SERVICE_NO_ACCESS,error:"You do not have access to this service.")unless@apikey.thumbs_access?
end
defvalidate_shortener_access
@apikey=APIKey.from_request(request)
render_error(YiffyAPIErrorCodes::SERVICE_NO_ACCESS,error:"You do not have access to this service.")unless@apikey.shortener_access?
end
defvalidate_images_bulk_access
@apikey=APIKey.from_request(request)
render_error(YiffyAPIErrorCodes::SERVICE_NO_ACCESS,error:"You do not have access to this service.")unless@apikey.images_bulk_access?
end
defhandle_ratelimit
info,body,rlheaders=RateLimiter.process(request)
headers.merge!(rlheaders)
returnifinfo.nil?
# noinspection RubyCaseWithoutElseBlockInspection
caseinfo
when:INVALID_KEY
render_error(YiffyAPIErrorCodes::INVALID_API_KEY,error:"Invalid api key.")