Commit f601ec54 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Introduce Projects::ArtifactsController#search:

So we redirect from ref and build_name to the particular build, namely:

* /u/r/artifacts/ref/build_name/* -> /u/r/builds/:build_id/artifacts/*

For:

* download
* browse
* file
parent 8f469c33
...@@ -35,14 +35,34 @@ class Projects::ArtifactsController < Projects::ApplicationController ...@@ -35,14 +35,34 @@ class Projects::ArtifactsController < Projects::ApplicationController
redirect_to namespace_project_build_path(project.namespace, project, build) redirect_to namespace_project_build_path(project.namespace, project, build)
end end
def search
url = namespace_project_build_url(project.namespace, project, build)
if params[:path]
redirect_to "#{url}/artifacts/#{params[:path]}"
else
render_404
end
end
private private
def validate_artifacts! def validate_artifacts!
render_404 unless build.artifacts? render_404 unless build && build.artifacts?
end end
def build def build
@build ||= project.builds.find_by!(id: params[:build_id]) @build ||= build_from_id || build_from_ref
end
def build_from_id
project.builds.find_by(id: params[:build_id]) if params[:build_id]
end
def build_from_ref
if params[:ref]
project.builds_for(params[:build_name], params[:ref]).latest.first
end
end end
def artifacts_file def artifacts_file
......
...@@ -733,6 +733,12 @@ Rails.application.routes.draw do ...@@ -733,6 +733,12 @@ Rails.application.routes.draw do
resources :environments, only: [:index, :show, :new, :create, :destroy] resources :environments, only: [:index, :show, :new, :create, :destroy]
resources :artifacts, only: [] do
collection do
get :search, path: ':ref/:build_name(/*path)', format: false
end
end
resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do collection do
post :cancel_all post :cancel_all
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment