diff --git a/Gemfile.lock b/Gemfile.lock index 3c5b201..5a4cbf0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -206,6 +206,7 @@ GEM mapping (1.1.1) marcel (1.0.4) mini_mime (1.1.5) + mini_portile2 (2.8.6) minitest (5.18.1) msgpack (1.7.1) mutex_m (0.2.0) @@ -219,9 +220,8 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.5.9) - nokogiri (1.14.5-x64-mingw-ucrt) - racc (~> 1.4) - nokogiri (1.14.5-x86_64-linux) + nokogiri (1.14.5) + mini_portile2 (~> 2.8.0) racc (~> 1.4) openssl (3.1.0) openssl-oaep (0.1.0) diff --git a/Rakefile b/Rakefile index 534af88..9e9375d 100644 --- a/Rakefile +++ b/Rakefile @@ -50,7 +50,6 @@ task "configure" do end task "install" do - sh "cd frontend && pnpm install" sh "cd backend && bundle install" sh "cd sub-audio && poetry install" sh "cd sub-chart && pnpm install" diff --git a/backend/app/controllers/sonolus/levels_controller.rb b/backend/app/controllers/sonolus/levels_controller.rb index aa3963c..1b1a170 100644 --- a/backend/app/controllers/sonolus/levels_controller.rb +++ b/backend/app/controllers/sonolus/levels_controller.rb @@ -100,7 +100,7 @@ def info Chart .order(updated_at: :desc) .limit(5) - .eager_load(file_resources: { file_attachment: :blob }) + .eager_load(:tags, :_variants, file_resources: { file_attachment: :blob }) .where( visibility: :private, author_id: [current_user.id] + alt_users.map(&:id) @@ -120,7 +120,7 @@ def info .order(published_at: :desc) .limit(5) .includes(:author) - .eager_load(file_resources: { file_attachment: :blob }) + .eager_load(:tags, file_resources: { file_attachment: :blob }) .where(visibility: :public) .sonolus_listed .map(&:to_sonolus) @@ -140,7 +140,7 @@ def list charts = Chart .includes(:author) - .eager_load(file_resources: { file_attachment: :blob }) + .eager_load(:tags, :_variants, file_resources: { file_attachment: :blob }) .sonolus_listed charts = @@ -306,7 +306,7 @@ def show items: chart.variants.map(&:to_sonolus) } ].filter { |section| section[:items].any? }, - description: chart.sonolus_description + description: chart.description } else render json: { diff --git a/backend/app/models/chart.rb b/backend/app/models/chart.rb index cd98c5b..9aea0ea 100644 --- a/backend/app/models/chart.rb +++ b/backend/app/models/chart.rb @@ -101,7 +101,10 @@ def to_sonolus artists: "#{composer} / #{artist.presence || "-"}", author: "#{author_name.presence || author.name}##{author.display_handle}", source: ENV.fetch("HOST", nil), - tags: [], + tags: [ + { title: likes_count.to_s, icon: "heart" }, + *tags.map { |tag| { title: tag.name } } + ].filter(&:itself), cover: resources[:cover]&.to_srl || { hash: "", url: "" }, bgm: resources[:bgm]&.to_srl || { hash: "", url: "" }, preview: resources[:preview]&.to_srl || { hash: "", url: "" }, @@ -150,12 +153,7 @@ def to_sonolus_background(resources, version: 3) title:, subtitle: "#{composer}#{artist.presence ? " / #{artist}" : ""}", author: "#{author_name.presence || author.name}##{author.display_handle}", - thumbnail: - resources[:cover]&.to_srl || - { - hash: "", - url: "" - }, + thumbnail: resources[:cover]&.to_srl || { hash: "", url: "" }, data:, image: resources[:"background_v#{version}"]&.to_srl || @@ -167,14 +165,4 @@ def to_sonolus_background(resources, version: 3) configuration: config } end - - def sonolus_description - I18n.t( - "sonolus.levels.description", - tags: - tags.map(&:name).join(I18n.t("sonolus.tag_separator")).presence || "-", - likes: likes_count, - description: - ) - end end diff --git a/backend/app/models/file_resource.rb b/backend/app/models/file_resource.rb index 0206ff3..76fb5c8 100644 --- a/backend/app/models/file_resource.rb +++ b/backend/app/models/file_resource.rb @@ -52,20 +52,18 @@ def self.upload_from_string(chart_name, kind, string) end def to_frontend - - if ENV["S3_PUBLIC_ROOT"].present? - "#{ENV["S3_PUBLIC_ROOT"]}/#{file.key}" - elsif ENV["HOSTS_BACKEND"].blank? - file.url - else - Rails.application.routes.url_helpers.rails_blob_path( - file, - host: ENV["HOSTS_BACKEND"] - ) - end - rescue StandardError - nil - + if ENV["S3_PUBLIC_ROOT"].present? + "#{ENV["S3_PUBLIC_ROOT"]}/#{file.key}" + elsif ENV["HOSTS_BACKEND"].blank? + file.url + else + Rails.application.routes.url_helpers.rails_blob_path( + file, + host: ENV["HOSTS_BACKEND"] + ) + end + rescue StandardError + nil end alias url to_frontend @@ -73,4 +71,4 @@ def to_frontend def to_srl { hash: sha1, url: to_frontend } end -end \ No newline at end of file +end diff --git a/backend/app/models/user.rb b/backend/app/models/user.rb index 767d369..af4ee87 100644 --- a/backend/app/models/user.rb +++ b/backend/app/models/user.rb @@ -4,17 +4,14 @@ class User < ApplicationRecord foreign_key: :author_id, dependent: :destroy, inverse_of: :author - belongs_to :owner, - class_name: "User", - optional: true, - inverse_of: :alt_users + belongs_to :owner, class_name: "User", optional: true, inverse_of: :alt_users has_many :alt_users, foreign_key: :owner_id, dependent: :destroy, class_name: "User", inverse_of: :owner has_many :likes, dependent: :destroy - enum discord_status: {no: 0, linked: 1, joined: 2} + enum discord_status: { no: 0, linked: 1, joined: 2 } def display_handle owner_id ? "x#{handle}" : handle @@ -80,7 +77,8 @@ def refresh_discord_token end def admin? - ENV.fetch("ADMIN_HANDLE", nil) && ENV["ADMIN_HANDLE"].split(",").include?(handle) + ENV.fetch("ADMIN_HANDLE", nil) && + ENV["ADMIN_HANDLE"].split(",").include?(handle) end def self.sync_profile(user_profile) diff --git a/backend/config/locales/en.yml b/backend/config/locales/en.yml index 54cbdfb..8eb32c8 100644 --- a/backend/config/locales/en.yml +++ b/backend/config/locales/en.yml @@ -39,12 +39,11 @@ en: info: description: "Chart Cyanvas is a sekai custom charts platform for Sonolus." logged_in: "Logged in as %{name}#%{handle}." - tag_separator: ", " levels: - description: | - Likes: %{likes} / Tag(s): %{tags} - - %{description} + variants: + zero: "No variants" + one: "1 variant" + other: "%{count} variants" sections: actions: "Actions" variant_of: "Vary from" diff --git a/backend/config/locales/ja.yml b/backend/config/locales/ja.yml index 8c1daa3..3d47748 100644 --- a/backend/config/locales/ja.yml +++ b/backend/config/locales/ja.yml @@ -40,12 +40,9 @@ ja: info: description: "Chart Cyanvas は Sonolus 用の某セカイ創作譜面プラットフォームです。" logged_in: "%{name}#%{handle} としてログインしています。" - tag_separator: "、" levels: - description: | - 高評価:%{likes} / タグ:%{tags} + variants: "派生譜面:%{count}個" - %{description} sections: actions: "操作" variant_of: "派生元"