# frozen_string_literal: true

module Projects
  # Handles requests to the legacy repository archive URL format:
  #   /{namespace}/{project}/repository/archive.{format}?ref={ref}
  #
  # This URL is generated by npm's `hosted-git-info` library for `gitlab:` shorthand
  # dependencies. The URL is not a valid GitLab route (the correct format uses `/-/archive/`),
  # and without this handler the catch-all route redirects unauthenticated users to the
  # sign-in page (302 -> 200 HTML), which breaks automated tooling that expects a proper
  # HTTP error or a valid tarball.
  #
  # See https://gitlab.com/gitlab-org/gitlab/-/issues/595699
  class LegacyArchiveController < ::ApplicationController
    skip_before_action :authenticate_user!

    feature_category :source_code_management

    def show
      if Feature.enabled?(:legacy_archive_not_found, :instance, type: :gitlab_com_derisk)
        render_404
      else
        route_not_found
      end
    end
  end
end
