Friday, September 20, 2024 12:00:00 AM
> settings

Customize


Authenticate

> downloads_controller.rb
# 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
All opinions represented herein are my own
- © 2024 itsthedevman
- build 3c15a1b