File: npm.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (39 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module API
  module Helpers
    module Packages
      module Npm
        include Gitlab::Utils::StrongMemoize
        include ::API::Helpers::PackagesHelpers
        extend ::Gitlab::Utils::Override

        NPM_ENDPOINT_REQUIREMENTS = {
          package_name: API::NO_SLASH_URL_PART_REGEX
        }.freeze

        def project_or_nil
          # mainly used by the metadata endpoint where we need to get a project
          # and return nil if not found (no errors should be raised)
          return unless project_id_or_nil

          find_project(project_id_or_nil)
        end
        strong_memoize_attr :project_or_nil

        def enqueue_sync_metadata_cache_worker(project, package_name)
          ::Packages::Npm::CreateMetadataCacheWorker.perform_async(project.id, package_name)
        end

        private

        override :not_found!
        def not_found!(resource = nil)
          reason = "#{resource} not found"
          message = "404 #{reason}".titleize
          render_structured_api_error!({ message: message, error: reason }, 404)
        end
      end
    end
  end
end