# frozen_string_literal: true class DownloadsController < ApplicationController def latest release = Download.where(current_release: true).first redirect_not_found if release.nil? send_file(Rails.root.join("public", release.file.current_path)) end def show release = Download.where(uuid: params[:id]).first redirect_not_found if release.nil? send_file(Rails.root.join("public", release.file.current_path)) end def create redirect_to_not_found if !current_user.developer? download = Download.create!(download_params) if download.valid? # Reset all other releases if download_params[:current_release] Download.where(current_release: true) .where.not(id: download.id) .update_all(current_release: false) end redirect_to root_path, notice: "Created" else redirect_to root_path, notice: "Failed" end end private def download_params params.require(:download).permit(:file, :version, :current_release) end end