Skip to content

Commit

Permalink
Add: Add background item info
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed May 4, 2024
1 parent bab1595 commit 629aaa6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 64 deletions.
63 changes: 4 additions & 59 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,6 @@ GEM
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
async (2.6.2)
console (~> 1.10)
fiber-annotation
io-event (~> 1.1)
timers (~> 4.1)
async-container (0.16.12)
async
async-io
async-http (0.60.2)
async (>= 1.25)
async-io (>= 1.28)
async-pool (>= 0.2)
protocol-http (~> 0.24.0)
protocol-http1 (~> 0.15.0)
protocol-http2 (~> 0.15.0)
traces (>= 0.10.0)
async-http-cache (0.4.3)
async-http (~> 0.56)
async-io (1.35.0)
async
async-pool (0.4.0)
async (>= 1.25)
aws-eventstream (1.2.0)
aws-partitions (1.786.0)
aws-sdk-core (3.178.0)
Expand All @@ -120,7 +98,6 @@ GEM
bigdecimal (3.1.7)
bootsnap (1.16.0)
msgpack (~> 1.2)
build-environment (1.13.0)
builder (3.2.4)
bullet (7.0.7)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -151,19 +128,6 @@ GEM
railties (>= 3.2)
drb (2.2.1)
erubi (1.12.0)
falcon (0.42.3)
async
async-container (~> 0.16.0)
async-http (~> 0.57)
async-http-cache (~> 0.4.0)
async-io (~> 1.22)
build-environment (~> 1.13)
bundler
localhost (~> 1.1)
openssl (~> 3.0)
process-metrics (~> 0.2.0)
protocol-rack (~> 0.1)
samovar (~> 2.1)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
Expand All @@ -183,7 +147,6 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-console (0.6.0)
io-event (1.2.2)
irb (1.7.3)
reline (>= 0.3.6)
jmespath (1.6.2)
Expand All @@ -194,7 +157,6 @@ GEM
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
localhost (1.1.10)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -203,7 +165,6 @@ GEM
net-imap
net-pop
net-smtp
mapping (1.1.1)
marcel (1.0.4)
mini_mime (1.1.5)
mini_portile2 (2.8.6)
Expand All @@ -223,7 +184,6 @@ GEM
nokogiri (1.14.5)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
openssl (3.1.0)
openssl-oaep (0.1.0)
parallel (1.23.0)
parallel_tests (4.2.1)
Expand All @@ -234,19 +194,6 @@ GEM
pg (1.5.3)
pg (1.5.3-x64-mingw-ucrt)
prettier_print (1.2.1)
process-metrics (0.2.1)
console (~> 1.8)
samovar (~> 2.1)
protocol-hpack (1.4.2)
protocol-http (0.24.4)
protocol-http1 (0.15.0)
protocol-http (~> 0.22)
protocol-http2 (0.15.1)
protocol-hpack (~> 1.4)
protocol-http (~> 0.18)
protocol-rack (0.2.6)
protocol-http (~> 0.23)
rack (>= 1.0)
public_suffix (5.0.3)
puma (6.3.0)
nio4r (~> 2.0)
Expand Down Expand Up @@ -280,6 +227,9 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
rails-i18n (7.0.9)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
railties (7.1.3.2)
actionpack (= 7.1.3.2)
activesupport (= 7.1.3.2)
Expand Down Expand Up @@ -340,9 +290,6 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
samovar (2.2.0)
console (~> 1.0)
mapping (~> 1.0)
sentry-rails (5.10.0)
railties (>= 5.0)
sentry-ruby (~> 5.10.0)
Expand All @@ -362,8 +309,6 @@ GEM
prettier_print (>= 1.2.0)
thor (1.2.2)
timeout (0.4.1)
timers (4.3.5)
traces (0.11.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2023.3)
Expand Down Expand Up @@ -394,7 +339,6 @@ DEPENDENCIES
counter_culture (~> 3.2)
debug
dotenv-rails (~> 2.8)
falcon (~> 0.42)
http (~> 5.1)
jwt (~> 2.8)
nokogiri (~> 1.14.0.rc1)
Expand All @@ -403,6 +347,7 @@ DEPENDENCIES
pg (~> 1.4)
puma (~> 6.3)
rails (~> 7.1)
rails-i18n (~> 7.0)
rbnacl (~> 7.1)
redis (~> 4.0)
request_store_rails (~> 2.0)
Expand Down
45 changes: 45 additions & 0 deletions backend/app/controllers/sonolus/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,50 @@ def show
status: :not_found
end
end

def background
params.permit(:name)
name, version = params[:name].split("-")
unless version.match?(/v[13]/)
render json: {
code: "bad_request",
error: "Invalid background name"
},
status: :bad_request
return
end

chart = Chart.find_by(name:)
unless chart
render json: {
code: "not_found",
error: "Background not found"
},
status: :not_found
return
end

version_num = version.delete_prefix("v").to_i

render json: {
item:
chart.to_sonolus_background(
chart.resources,
version: version_num
),
description: "",
sections: [
{
title: "#VERSIONS",
items: [
chart.to_sonolus_background(
chart.resources,
version: version_num == 1 ? 3 : 1
)
]
}
]
}
end
end
end
7 changes: 2 additions & 5 deletions backend/app/models/chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def to_sonolus
title:
I18n.t(
"sonolus.levels.published_at",
time:
time_ago_in_words(
published_at
)
time: time_ago_in_words(published_at)
)
}
when "private"
Expand Down Expand Up @@ -171,7 +168,7 @@ def to_sonolus_background(resources, version: 3)
version: 2,
tags: [],
source: ENV.fetch("HOST", nil),
title:,
title: I18n.t("sonolus.background.title", name: title, version:),
subtitle: "#{composer}#{artist.presence ? " / #{artist}" : ""}",
author: "#{author_name.presence || author.name}##{author.display_handle}",
thumbnail: resources[:cover]&.to_srl || { hash: "", url: "" },
Expand Down
Binary file modified backend/assets/backgrounds/configuration.json.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions backend/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ en:
info:
description: "Chart Cyanvas is a sekai custom charts platform for Sonolus."
logged_in: "Logged in as %{name}#%{handle}."
background:
title: "%{name} (v%{version})"
levels:
published_at: "Published: %{time} ago"
variants:
Expand Down
2 changes: 2 additions & 0 deletions backend/config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ja:
info:
description: "Chart Cyanvas は Sonolus 用の某セカイ創作譜面プラットフォームです。"
logged_in: "%{name}#%{handle} としてログインしています。"
background:
title: "%{name}(v%{version})"
levels:
published_at: "公開:%{time}前"
variants: "派生譜面:%{count}個"
Expand Down
2 changes: 2 additions & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
get "/posts/info", to: "sonolus/info#empty_info"
get "/levels/info", to: "sonolus/levels#info"
get "/levels/list", to: "sonolus/levels#list"

get "/backgrounds/chcy-bg-:name", to: "sonolus/levels#background"
end
scope "/test" do
scope "sonolus" do
Expand Down

0 comments on commit 629aaa6

Please sign in to comment.