app/controllers/datasets_controller.rb
# GET /datasets/1/filedownload/1
# given a dataset id and a file id, update the dataset's last_access and number_of_downloads fields and redirect the user to the file they want
GET /datasets/1/filedownload/1
given a dataset id and a file id, update the dataset's last_access and number_of_downloads fields and redirect the user to the file they want
GET / datasets / 1 / filedownload / 1 given a dataset id and a file id update the dataset ' s last_access and number_of_downloads fields and redirect the user to the file they want
def filedownload
    dataset = find_dataset(params[:id])
    if (current_user && current_user.admin?) || (dataset.dc_access_rights[0] == 'Open') then
      dip_files = dip_directory_structure(dataset)
      if params[:fileid] and params[:fileid].to_s.match(/^[-a-zA-Z0-9]+$/) and dip_files[params[:fileid]] and dip_files[params[:fileid]][:file_path_abs]
        log_download(dataset)
        send_file(dip_files[params[:fileid]][:file_path_abs])
      else
        render :plain => "The requested file can not be served"
      end
    else
      render :plain => "You do not have permission to download this file"
    end
  end
def filedownload dataset = find_dataset ( params [ :id ] ) if ( current_user && current_user . admin? ) || ( dataset . dc_access_rights [ 0 ] == 'Open' ) then dip_files = dip_directory_structure ( dataset ) if params [ :fileid ] and params [ :fileid ] . to_s . match ( / ^[-a-zA-Z0-9]+$ / ) and dip_files [ params [ :fileid ] ] and dip_files [ params [ :fileid ] ] [ :file_path_abs ] log_download ( dataset ) send_file ( dip_files [ params [ :fileid ] ] [ :file_path_abs ] ) else render :plain => "The requested file can not be served" end else render :plain => "You do not have permission to download this file" end end
GET /datasets/1/filedownload/1
given a dataset id and a file id, update the dataset's last_access and number_of_downloads fields and redirect the user to the file they want
GET / datasets / 1 / filedownload / 1 given a dataset id and a file id update the dataset ' s last_access and number_of_downloads fields and redirect the user to the file they want
# get the dataset # if the user is allowed to download this file (i.e. they're an admin or it's an 'open' dataset) # get the dip files structure array # log the last_access time and increment the number_of_downloads for this dataset # give the user the file from the dip store (no longer storing files in hydra as they might be massive)