Assorted updates (#146)

* Syntax updates

* Update rake task for image downloading

* Add endpoints for showing a single job
This commit is contained in:
Justin Edmund 2025-01-08 12:19:19 -08:00 committed by GitHub
parent 53760bf87a
commit 0e490df113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 89 additions and 14 deletions

View file

@ -10,6 +10,10 @@ module Api
render json: JobBlueprint.render(Job.all)
end
def show
render json: JobBlueprint.render(Job.find_by(granblue_id: params[:id]))
end
def update_job
if job_params[:job_id] != -1
# Extract job and find its main skills
@ -64,7 +68,8 @@ module Api
new_skill_ids = new_skill_keys.map { |key| job_params[key] }
new_skill_ids.map do |id|
skill = JobSkill.find(id)
raise Api::V1::IncompatibleSkillError.new(job: @party.job, skill: skill) if mismatched_skill(@party.job, skill)
raise Api::V1::IncompatibleSkillError.new(job: @party.job, skill: skill) if mismatched_skill(@party.job,
skill)
end
positions = extract_positions_from_keys(new_skill_keys)
@ -162,8 +167,8 @@ module Api
if %w[4 5 ex2].include?(job.row)
if skill.base && !mismatched_base
false
else
true if mismatched_emp || mismatched_main
elsif mismatched_emp || mismatched_main
true
end
elsif mismatched_emp || mismatched_main
true

View file

@ -1,8 +1,8 @@
require "active_support/core_ext/integer/time"
require 'active_support/core_ext/integer/time'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.hosts << "staging-api.granblue.team"
config.hosts << 'staging-api.granblue.team'
# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for development
@ -20,10 +20,10 @@ Rails.application.configure do
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp/caching-dev.txt").exist?
if Rails.root.join('tmp/caching-dev.txt').exist?
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
@ -57,4 +57,23 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
#
logger = ActiveSupport::Logger.new(STDOUT)
# To support a formatter, you must manually assign a formatter from the config.log_formatter value to the logger.
logger.formatter = config.log_formatter
# config.logger is the logger that will be used for Rails.logger and any
# related Rails logging such as ActiveRecord::Base.logger.
# It defaults to an instance of ActiveSupport::TaggedLogging that wraps an
# instance of ActiveSupport::Logger which outputs a log to the log/ directory.
config.logger = ActiveSupport::TaggedLogging.new(logger)
# config.log_level defines the verbosity of the Rails logger.
# This option defaults to :debug for all environments.
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown
# config.log_level = :debug
# config.log_tags accepts a list of: methods that the request object responds to,
# a Proc that accepts the request object, or something that responds to to_s.
# This makes it easy to tag log lines with debug information like subdomain and request id -
# both very helpful in debugging multi-user production applications.
config.log_tags = [:request_id]
end

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
class CacheFreeLogger < ActiveSupport::Logger
def add(severity, message = nil, progname = nil, &block)
return true if progname&.include? 'CACHE'
super
end
end
ActiveRecord::Base.logger = CacheFreeLogger.new($stdout)
ActiveRecord::Base.logger.level = 1

View file

@ -41,6 +41,7 @@ Rails.application.routes.draw do
get 'jobs', to: 'jobs#all'
get 'jobs/skills', to: 'job_skills#all'
get 'jobs/:id', to: 'jobs#show'
get 'jobs/:id/skills', to: 'job_skills#job'
get 'jobs/:id/accessories', to: 'job_accessories#job'

View file

@ -61,6 +61,15 @@ namespace :granblue do
puts "\t404 returned\t#{url}"
end
def download_elemental_images(url, size, path, filename)
filepath = "#{path}/#{filename}"
download = URI.parse(url).open
puts "\tDownloading #{size}\t#{url}..."
IO.copy_stream(download, filepath)
rescue OpenURI::HTTPError
puts "\t404 returned\t#{url}"
end
def download_chara_images(id)
sizes = %w[main grid square]
@ -109,13 +118,42 @@ namespace :granblue do
end
end
desc 'Downloads elemental weapon images'
task :download_elemental_images, [:id_base] => :environment do |_t, args|
id_base = args[:id_base].to_i
suffixes = [2, 3, 4, 1, 6, 5]
(1..6).each do |i|
id = id_base + (i - 1) * 100
sizes = %w[main grid square]
url = {
'main': build_weapon_url(id, 'main'),
'grid': build_weapon_url(id, 'grid'),
'square': build_weapon_url(id, 'square')
}
puts "Elemental Weapon #{id}_#{suffixes[i - 1]}"
sizes.each do |size|
path = "#{Rails.root}/download/weapon-#{size}"
filename = "#{id}_#{suffixes[i - 1]}.jpg"
download_elemental_images(url[size.to_sym], size, path, filename)
end
_progress_reporter(count: i, total: 6, result: "Elemental Weapon #{id}_#{suffixes[i - 1]}", bar_len: 40,
multi: true)
end
end
desc 'Downloads images for the given Granblue_IDs'
task :download_images, %i[object] => :environment do |_t, args|
object = args[:object]
list = args.extras
list.each do |id|
if object == 'character'
case object
when 'character'
character = Character.find_by(granblue_id: id)
next unless character
@ -123,7 +161,7 @@ namespace :granblue do
download_chara_images("#{id}_02")
download_chara_images("#{id}_03") if character.flb
download_chara_images("#{id}_04") if character.ulb
elsif object == 'weapon'
when 'weapon'
weapon = Weapon.find_by(granblue_id: id)
next unless weapon
@ -133,7 +171,7 @@ namespace :granblue do
download_weapon_images("#{id}_02")
download_weapon_images("#{id}_03")
end
elsif object == 'summon'
when 'summon'
summon = Summon.find_by(granblue_id: id)
next unless summon