class WarpEngine::FileService
Serves the file container under /file/: a file through the access policy, a directory as a redirect to its index.html.
Public Instance Methods
Source
# File app/services/warp_engine/file_service.rb, line 16 def show(input, subject: nil) relative = input.path.to_s if storage.directory?(relative) index = File.join(relative.chomp("/"), "index.html") return FileResultDto.not_found unless storage.file?(index) return FileResultDto.redirect("/file/#{index}") end return FileResultDto.not_found unless storage.file?(relative) authorize!(relative, subject) to_result(storage.locate(relative, filename: File.basename(relative))) end
Answers the path of input (an object with path, relative to the storage) for subject (nil when anonymous).
Returns a WarpEngine::FileResultDto: a redirect to /file/<dir>/index.html for a directory that has one, the file (a local path or a storage redirect) for a file, not found otherwise. Raises WarpEngine::AccessDenied when the access policy refuses the file.