class WarpEngine::DownloadService
Serves a download from the file container: checks the access policy, logs a WarpEngine::Download and locates the file in the storage adapter.
Constants
- Denied
-
Alias of
WarpEngine::AccessDenied, the error a refused download raises.
Public Instance Methods
# File app/services/warp_engine/download_service.rb, line 43 def create(path:, ip:, user_agent:, referer:, subject: nil, request: nil) location = locate(path: path, ip: ip, user_agent: user_agent, referer: referer, subject: subject, request: request) return nil if location.nil? location.file? ? location.path : nil end
Like locate, but returns the local file path, or nil when there is no such file or the storage answers with a redirect.
# File app/services/warp_engine/download_service.rb, line 27 def locate(path:, ip:, user_agent:, referer:, subject: nil, request: nil) relative = path.to_s return nil unless storage.file?(relative) asset = find_asset(relative) grant = authorize_download!(asset: asset, subject: subject, request: request) log_download(relative, asset: asset, ip: ip, user_agent: user_agent, referer: referer, subject: subject) storage.locate(relative, filename: grant.filename.presence || File.basename(relative), expires_in: grant.expires_in) end
Locates the file at path (relative to the storage) for download.
- path
-
the file path, relative to the storage root
- ip
-
the client IP, logged
- user_agent
-
the client user agent, logged (truncated to 500 characters)
- referer
-
the referer, logged (truncated to 500 characters)
- subject
-
the caller, or
nilwhen anonymous - request
-
the Rack request, passed to the access policy
Returns the WarpEngine::Storage::Location of the file (a local path or a redirect URL, named and expiring as the policyโs grant says), or nil when there is no such file. Writes a WarpEngine::Download and instruments warp_engine.download unless the user agent is ignored (WarpEngine.config.ignored_user_agent?). Raises Denied when the access policy refuses.