-
-
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
7 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'compact_index' | ||
|
||
module Api::V1::ReleaseEngines | ||
class Npm::PackageMetadataController < 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_package_tgz.order_by_version) | ||
.where_assoc_exists(:manifest) # must exist | ||
.preload(:manifest, | ||
release: %i[product entitlements constraints], | ||
) | ||
authorize! artifacts, | ||
to: :index? | ||
|
||
latest = artifacts.first | ||
metadata = artifacts.reduce(name: package.name, time: {}, 'dist-tags': { latest: latest.release.version }, versions: {}) do |metadata, artifact| | ||
package_json = artifact.manifest.as_package_json | ||
release = artifact.release | ||
|
||
metadata[:time][release.version] = artifact.created_at.iso8601 | ||
metadata[:'dist-tags'][release.tag] = release.version if release.tag? | ||
metadata[:versions][release.version] = package_json.merge( | ||
dist: { | ||
tarball: vanity_v1_account_release_artifact_url(current_account, artifact, filename: artifact.filename, host: request.host), | ||
}, | ||
) | ||
|
||
metadata | ||
end | ||
|
||
render json: metadata | ||
end | ||
|
||
private | ||
|
||
attr_reader :package | ||
|
||
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
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