From 2dacfae17e59eac85b4876ef152efcf3857af4a2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Tue, 6 Jan 2026 03:52:30 -0800 Subject: [PATCH] add quest_id and lobby/background image sizes for raids - add quest_id column to raids table - add lobby and background image downloads using quest_id - lobby uses quest_id with "1" appended - background uses quest_id for treasureraid directory --- app/blueprints/api/v1/raid_blueprint.rb | 2 +- app/controllers/api/v1/raids_controller.rb | 5 +- app/services/raid_image_download_service.rb | 5 ++ .../20260106114730_add_quest_id_to_raids.rb | 5 ++ db/schema.rb | 3 +- lib/granblue/downloaders/raid_downloader.rb | 58 ++++++++++++++++++- 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20260106114730_add_quest_id_to_raids.rb diff --git a/app/blueprints/api/v1/raid_blueprint.rb b/app/blueprints/api/v1/raid_blueprint.rb index dcea066..f4de032 100644 --- a/app/blueprints/api/v1/raid_blueprint.rb +++ b/app/blueprints/api/v1/raid_blueprint.rb @@ -13,7 +13,7 @@ module Api } end - fields :slug, :level, :element, :enemy_id, :summon_id + fields :slug, :level, :element, :enemy_id, :summon_id, :quest_id association :group, blueprint: RaidGroupBlueprint, view: :flat end diff --git a/app/controllers/api/v1/raids_controller.rb b/app/controllers/api/v1/raids_controller.rb index 17cfdfb..767152a 100644 --- a/app/controllers/api/v1/raids_controller.rb +++ b/app/controllers/api/v1/raids_controller.rb @@ -75,6 +75,9 @@ module Api if size == 'thumbnail' && @raid.summon_id.blank? return render json: { error: 'Raid has no summon_id configured' }, status: :unprocessable_entity end + if %w[lobby background].include?(size) && @raid.quest_id.blank? + return render json: { error: 'Raid has no quest_id configured' }, status: :unprocessable_entity + end begin downloader = Granblue::Downloaders::RaidDownloader.new( @@ -151,7 +154,7 @@ module Api end def raid_params - params.require(:raid).permit(:name_en, :name_jp, :level, :element, :slug, :group_id, :enemy_id, :summon_id) + params.require(:raid).permit(:name_en, :name_jp, :level, :element, :slug, :group_id, :enemy_id, :summon_id, :quest_id) end def apply_filters(scope) diff --git a/app/services/raid_image_download_service.rb b/app/services/raid_image_download_service.rb index 429c9e1..516ab4c 100644 --- a/app/services/raid_image_download_service.rb +++ b/app/services/raid_image_download_service.rb @@ -63,6 +63,11 @@ class RaidImageDownloadService manifest['thumbnail'] = ["#{@raid.summon_id}_high.png"] end + if @raid.quest_id + manifest['lobby'] = ["#{@raid.quest_id}1.png"] + manifest['background'] = ["#{@raid.quest_id}_raid_image_new.png"] + end + manifest end diff --git a/db/migrate/20260106114730_add_quest_id_to_raids.rb b/db/migrate/20260106114730_add_quest_id_to_raids.rb new file mode 100644 index 0000000..6b0e7fd --- /dev/null +++ b/db/migrate/20260106114730_add_quest_id_to_raids.rb @@ -0,0 +1,5 @@ +class AddQuestIdToRaids < ActiveRecord::Migration[8.0] + def change + add_column :raids, :quest_id, :bigint + end +end diff --git a/db/schema.rb b/db/schema.rb index f617f8d..aad690c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2026_01_06_104115) do +ActiveRecord::Schema[8.0].define(version: 2026_01_06_114730) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_catalog.plpgsql" @@ -757,6 +757,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_01_06_104115) do t.uuid "group_id" t.integer "enemy_id" t.bigint "summon_id" + t.bigint "quest_id" end create_table "skill_effects", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/lib/granblue/downloaders/raid_downloader.rb b/lib/granblue/downloaders/raid_downloader.rb index 3274c1c..c847c77 100644 --- a/lib/granblue/downloaders/raid_downloader.rb +++ b/lib/granblue/downloaders/raid_downloader.rb @@ -3,21 +3,25 @@ module Granblue module Downloaders # Downloads raid image assets from the game server. - # Raids have two different image types from different sources: + # Raids have four different image types from different sources: # - Icon: from enemy directory using enemy_id # - Thumbnail: from summon directory using summon_id + # - Lobby: from quest/lobby directory using quest_id (with "1" appended) + # - Background: from quest/treasureraid directory using quest_id # # @example Download images for a specific raid # downloader = RaidDownloader.new(raid, storage: :both) # downloader.download # # @note Unlike other downloaders, RaidDownloader takes a Raid model instance - # since it needs both enemy_id and summon_id + # since it needs enemy_id, summon_id, and quest_id class RaidDownloader < BaseDownloader - SIZES = %w[icon thumbnail].freeze + SIZES = %w[icon thumbnail lobby background].freeze ICON_BASE_URL = 'https://prd-game-a-granbluefantasy.akamaized.net/assets_en/img/sp/assets/enemy' THUMBNAIL_BASE_URL = 'https://prd-game-a1-granbluefantasy.akamaized.net/assets_en/img/sp/assets/summon' + LOBBY_BASE_URL = 'https://prd-game-a1-granbluefantasy.akamaized.net/assets_en/img/sp/quest/assets/lobby' + BACKGROUND_BASE_URL = 'https://prd-game-a-granbluefantasy.akamaized.net/assets_en/img/sp/quest/assets/treasureraid' # Initialize with a Raid model instead of just an ID # @param raid [Raid] Raid model instance @@ -52,6 +56,10 @@ module Granblue download_icon(last: index == sizes.size - 1) when 'thumbnail' download_thumbnail(last: index == sizes.size - 1) + when 'lobby' + download_lobby(last: index == sizes.size - 1) + when 'background' + download_background(last: index == sizes.size - 1) end end end @@ -94,6 +102,42 @@ module Granblue log_info "\t404 returned\t#{url}" end + # Download the lobby image (from quest/lobby directory) + def download_lobby(last: false) + return unless @raid.quest_id + + path = download_path('lobby') + url = build_lobby_url + filename = "#{@raid.quest_id}1.png" + s3_key = build_s3_key('lobby', filename) + download_uri = "#{path}/#{filename}" + + return unless should_download?(download_uri, s3_key) + + log_download('lobby', url, last: last) + process_image_download(url, download_uri, s3_key) + rescue OpenURI::HTTPError + log_info "\t404 returned\t#{url}" + end + + # Download the background image (from quest/treasureraid directory) + def download_background(last: false) + return unless @raid.quest_id + + path = download_path('background') + url = build_background_url + filename = "raid_image_new.png" + s3_key = build_s3_key('background', "#{@raid.quest_id}_raid_image_new.png") + download_uri = "#{path}/#{@raid.quest_id}_#{filename}" + + return unless should_download?(download_uri, s3_key) + + log_download('background', url, last: last) + process_image_download(url, download_uri, s3_key) + rescue OpenURI::HTTPError + log_info "\t404 returned\t#{url}" + end + def log_download(size, url, last: false) if last log_info "\tâ”” #{size}: #{url}..." @@ -121,6 +165,14 @@ module Granblue "#{THUMBNAIL_BASE_URL}/qm/#{@raid.summon_id}_high.png" end + def build_lobby_url + "#{LOBBY_BASE_URL}/#{@raid.quest_id}1.png" + end + + def build_background_url + "#{BACKGROUND_BASE_URL}/#{@raid.quest_id}/raid_image_new.png" + end + def object_type 'raid' end