debian-mirror-gitlab/app/models/packages/npm/metadata_cache.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

2023-06-20 00:43:36 +05:30
# frozen_string_literal: true
module Packages
module Npm
class MetadataCache < ApplicationRecord
2023-07-09 08:55:56 +05:30
include FileStoreMounter
2023-06-20 00:43:36 +05:30
belongs_to :project, inverse_of: :npm_metadata_caches
2023-07-09 08:55:56 +05:30
validates :file, :object_storage_key, :package_name, :project, :size, presence: true
2023-06-20 00:43:36 +05:30
validates :package_name, uniqueness: { scope: :project_id }
validates :package_name, format: { with: Gitlab::Regex.package_name_regex }
validates :package_name, format: { with: Gitlab::Regex.npm_package_name_regex }
2023-07-09 08:55:56 +05:30
mount_file_store_uploader MetadataCacheUploader
before_validation :set_object_storage_key
attr_readonly :object_storage_key
def self.find_or_build(package_name:, project_id:)
find_or_initialize_by(
package_name: package_name,
project_id: project_id
)
end
private
def set_object_storage_key
return unless package_name && project_id
self.object_storage_key = Gitlab::HashedPath.new(
'packages', 'metadata_caches', 'npm', OpenSSL::Digest::SHA256.hexdigest(package_name),
root_hash: project_id
).to_s
end
2023-06-20 00:43:36 +05:30
end
end
end