# frozen_string_literal: true module YiffRest module APIV2 class ManageController < ApplicationController before_action :validate_discord, except: %i[logout] before_action :prepare_user, except: %i[logout] def index @categories = APIImage.categories end def show @category = APIImage.categories.find { |c| c.db == params[:id] } raise(ActiveRecord::RecordNotFound) if @category.blank? @count = APIImage.cached_count(params[:id]) @pagy, @images = pagy(APIImage.where(category: params[:id]).search(search_params).order(created_at: :desc), size: [1, 2, 2, 1]) end def sync APIImage.sync_all redirect_to(yiff_rest_api_v2_manage_index_path, notice: "Images will soon be synced.") end def logout session.delete("discord_user") CurrentUser.user = nil redirect_to(yiff_rest_root_path, notice: "You have been logged out.") end private def site_title "YiffyAPI V2 - Manage Images" end end end end