class FileService
  BASE_PATH = Pathname.new(ENV.fetch("FILE_CONTAINER_PATH", "/softwares")).realpath

  def show(input)
    full_path = BASE_PATH.join(input.path.to_s)

    if File.directory?(full_path)
      index_path = full_path.join("index.html")
      return FileResultDto.not_found unless File.file?(index_path)
      return FileResultDto.redirect("/file/#{input.path.to_s.chomp("/")}/index.html")
    end

    if File.file?(full_path)
      FileResultDto.file(full_path)
    else
      FileResultDto.not_found
    end
  end
end
