Skip to content

Commit

Permalink
Change: Use native tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed May 4, 2024
1 parent 8b4d77c commit e929622
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 55 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions backend/app/controllers/sonolus/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 =
Expand Down Expand Up @@ -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: {
Expand Down
22 changes: 5 additions & 17 deletions backend/app/models/chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down Expand Up @@ -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 ||
Expand All @@ -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
28 changes: 13 additions & 15 deletions backend/app/models/file_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,23 @@ 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

def to_srl
{ hash: sha1, url: to_frontend }
end
end
end
10 changes: 4 additions & 6 deletions backend/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions backend/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions backend/config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "派生元"
Expand Down

0 comments on commit e929622

Please sign in to comment.