diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/downloads_controller.rb | 69 | ||||
-rw-r--r-- | app/views/downloads/_form.html.erb | 37 | ||||
-rw-r--r-- | app/views/downloads/edit.html.erb | 6 | ||||
-rw-r--r-- | app/views/downloads/new.html.erb | 5 | ||||
-rw-r--r-- | app/views/downloads/show.html.erb | 29 | ||||
-rw-r--r-- | app/views/downloads/show.json.jbuilder | 1 |
6 files changed, 5 insertions, 142 deletions
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb index 2681b0a..14e3b04 100644 --- a/app/controllers/downloads_controller.rb +++ b/app/controllers/downloads_controller.rb @@ -11,16 +11,16 @@ class DownloadsController < ApplicationController end # GET /downloads/:filename - def download - download = Download.find_by(filename: params[:filename]) or not_found + def show + not_found if @download.nil? s3client = Aws::S3::Client.new() - s3obj = Aws::S3::Object.new(ENV['S3_DOWNLOADS_BUCKET'], download.filename, client: s3client) + s3obj = Aws::S3::Object.new(ENV['S3_DOWNLOADS_BUCKET'], @download.filename, client: s3client) resp = s3obj.get FileUtils.mkdir_p(Rails.root.join('tmp', 'downloads')) - cached_filename = Rails.root.join('tmp', 'downloads', download.filename) + cached_filename = Rails.root.join('tmp', 'downloads', @download.filename) File.open(cached_filename, 'wb') do |file| file.write resp.body.read @@ -29,68 +29,9 @@ class DownloadsController < ApplicationController send_file cached_filename end - # GET /downloads/1 - # GET /downloads/1.json - def show - end - - # GET /downloads/new - def new - @download = Download.new - end - - # GET /downloads/1/edit - def edit - end - - # POST /downloads - # POST /downloads.json - def create - @download = Download.new(download_params) - - respond_to do |format| - if @download.save - format.html { redirect_to @download, notice: 'Download was successfully created.' } - format.json { render :show, status: :created, location: @download } - else - format.html { render :new } - format.json { render json: @download.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /downloads/1 - # PATCH/PUT /downloads/1.json - def update - respond_to do |format| - if @download.update(download_params) - format.html { redirect_to @download, notice: 'Download was successfully updated.' } - format.json { render :show, status: :ok, location: @download } - else - format.html { render :edit } - format.json { render json: @download.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /downloads/1 - # DELETE /downloads/1.json - def destroy - @download.destroy - respond_to do |format| - format.html { redirect_to downloads_url, notice: 'Download was successfully destroyed.' } - format.json { head :no_content } - end - end - private # Use callbacks to share common setup or constraints between actions. def set_download - @download = Download.find(params[:id]) - end - - # Never trust parameters from the scary internet, only allow the white list through. - def download_params - params.require(:download).permit(:name, :filename, :type, :description, :hits) + @download = Download.find_by(filename: params[:id]) end end diff --git a/app/views/downloads/_form.html.erb b/app/views/downloads/_form.html.erb deleted file mode 100644 index 1ab1879..0000000 --- a/app/views/downloads/_form.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<%= form_for(@download) do |f| %> - <% if @download.errors.any? %> - <div id="error_explanation"> - <h2><%= pluralize(@download.errors.count, "error") %> prohibited this download from being saved:</h2> - - <ul> - <% @download.errors.full_messages.each do |message| %> - <li><%= message %></li> - <% end %> - </ul> - </div> - <% end %> - - <div class="field"> - <%= f.label :name %><br> - <%= f.text_field :name %> - </div> - <div class="field"> - <%= f.label :filename %><br> - <%= f.text_field :filename %> - </div> - <div class="field"> - <%= f.label :type %><br> - <%= f.text_field :type %> - </div> - <div class="field"> - <%= f.label :description %><br> - <%= f.text_area :description %> - </div> - <div class="field"> - <%= f.label :hits %><br> - <%= f.number_field :hits %> - </div> - <div class="actions"> - <%= f.submit %> - </div> -<% end %> diff --git a/app/views/downloads/edit.html.erb b/app/views/downloads/edit.html.erb deleted file mode 100644 index 3b57a65..0000000 --- a/app/views/downloads/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<h1>Editing Download</h1> - -<%= render 'form' %> - -<%= link_to 'Show', @download %> | -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/new.html.erb b/app/views/downloads/new.html.erb deleted file mode 100644 index ac31df5..0000000 --- a/app/views/downloads/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<h1>New Download</h1> - -<%= render 'form' %> - -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.html.erb b/app/views/downloads/show.html.erb deleted file mode 100644 index 276888a..0000000 --- a/app/views/downloads/show.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<p id="notice"><%= notice %></p> - -<p> - <strong>Name:</strong> - <%= @download.name %> -</p> - -<p> - <strong>Filename:</strong> - <%= @download.filename %> -</p> - -<p> - <strong>Type:</strong> - <%= @download.type %> -</p> - -<p> - <strong>Description:</strong> - <%= @download.description %> -</p> - -<p> - <strong>Hits:</strong> - <%= @download.hits %> -</p> - -<%= link_to 'Edit', edit_download_path(@download) %> | -<%= link_to 'Back', downloads_path %> diff --git a/app/views/downloads/show.json.jbuilder b/app/views/downloads/show.json.jbuilder deleted file mode 100644 index 6bab62c..0000000 --- a/app/views/downloads/show.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.extract! @download, :id, :name, :filename, :type, :description, :hits, :created_at, :updated_at |