-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/controllers/api/v1/release_engines/npm/package_metadata_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'compact_index' | ||
|
||
module Api::V1::ReleaseEngines | ||
class Npm::PackageMetadateController < Api::V1::BaseController | ||
before_action :scope_to_current_account! | ||
before_action :require_active_subscription! | ||
before_action :authenticate_with_token | ||
before_action :set_package | ||
|
||
def show | ||
authorize package, | ||
to: :show? | ||
|
||
artifacts = authorized_scope(package.artifacts.npm) | ||
.where_assoc_exists(:manifest) # must exist | ||
.preload(:manifest, | ||
release: %i[product entitlements constraints], | ||
) | ||
authorize! artifacts, | ||
to: :index? | ||
|
||
metadata = artifacts.reduce(name: package.name, time: {}, 'dist-tags': {}, versions: {}) do |metadata, artifact| | ||
manifest = artifact.manifest | ||
release = artifact.release | ||
package_json = manifest.as_package_json | ||
version = release.version | ||
tag = release.tag | ||
|
||
metadata[:time][version] = artifact.created_at.iso8601 | ||
metadata[:'dist-tags'][tag] = version | ||
metadata[:versions][version] = { | ||
...package_json, | ||
dist: { | ||
tarball: vanity_v1_account_release_artifact_url(current_account, artifact, filename: artifact, host: request.host), | ||
}, | ||
} | ||
end | ||
|
||
render json: metadata | ||
end | ||
|
||
def set_package | ||
scoped_packages = authorized_scope(current_account.release_packages.npm) | ||
.where_assoc_exists( | ||
%i[releases artifacts manifest], # must exist | ||
) | ||
|
||
Current.resource = @package = FindByAliasService.call( | ||
scoped_packages, | ||
id: params[:package], | ||
aliases: :key, | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters