Skip to content

Commit

Permalink
Delete: Deprecate test server
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Apr 6, 2024
1 parent 706392a commit fbe7cde
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 133 deletions.
18 changes: 1 addition & 17 deletions backend/app/controllers/sonolus/info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,7 @@ def test_info
title = I18n.t("test.title")
title += " (dev)" if ENV["RAILS_ENV"] != "production"

render json:
{
title:,
banner: banner("banner"),
levels: {
items: [
dummy_level("test.welcome", "test-welcome", cover: "logo")
],
search: {
options: Sonolus::LevelsController.search_options
}
}
}.tap { |json|
%i[backgrounds skins effects particles engines].each do |key|
json[key] = { items: [], search: { options: [] } }
end
}
render json: { title:, banner: banner("banner") }
end
end
end
158 changes: 66 additions & 92 deletions backend/app/controllers/sonolus/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ def self.search_options
max: 99,
step: 1
},
{
query: :q_target,
name: I18n.t("sonolus.search.target"),
type: "select",
def: 0,
values: I18n.t("sonolus.search.targets")
},
{
query: :q_sort,
name: I18n.t("sonolus.search.sort"),
Expand All @@ -74,22 +67,52 @@ def self.search_options
]
end

def self.test_search_options
self.search_options.reject do |option|
%i[q_target q_author q_author_name].include?(option[:query])
end
def searches
[
current_user &&
[
{
type: "testing",
title: I18n.t("sonolus.targets.testing"),
options: []
},
{
type: "liked",
title: I18n.t("sonolus.targets.liked"),
options: []
}
],
{
type: "advanced",
title: "#ADVANCED",
options: self.class.search_options
}
].compact.flatten
end

def info
private_section =
if current_user
alt_users = User.where(owner_id: current_user.id)
{
title: "#PRIVATE",
items:
Chart
.order(updated_at: :desc)
.limit(5)
.eager_load(file_resources: { file_attachment: :blob })
.where(
visibility: :private,
author_id: [current_user.id] + alt_users.map(&:id)
)
.sonolus_listed
.map(&:to_sonolus)
}
end
render json: {
searches: [
{
type: "advanced",
title: "#ADVANCED",
options: self.class.search_options
}
],
searches:,
sections: [
private_section,
{
title: "#NEWEST",
items:
Expand All @@ -102,12 +125,17 @@ def info
.sonolus_listed
.map(&:to_sonolus)
}
]
].compact
}
end

def list
params.permit(:page, :type, :keywords, *(self.class.search_options.map { |o| o[:query] }))
params.permit(
:page,
:type,
:keywords,
*(self.class.search_options.map { |o| o[:query] })
)

charts =
Chart
Expand Down Expand Up @@ -199,26 +227,24 @@ def list
"%#{params[:q_author_name].downcase}%"
)
end
if !params[:q_target] || params[:q_target].to_i.zero?
case params[:type]
when "quick", "advanced"
charts = charts.where(visibility: :public)
else
case params[:q_target].to_i
when 1
require_login!
alt_users = User.where(owner_id: current_user.id)
charts =
charts
.where(author_id: [current_user.id] + alt_users.map(&:id))
.where.not(visibility: :public)
when 2
require_login!
likes =
Like
.where(user_id: current_user.id)
.select(:chart_id)
.order(created_at: :desc)
charts = charts.where(id: likes.map(&:chart_id))
end
when "testing"
require_login!
alt_users = User.where(owner_id: current_user.id)
charts =
charts
.where(author_id: [current_user.id] + alt_users.map(&:id))
.where.not(visibility: :public)
when "liked"
require_login!
likes =
Like
.where(user_id: current_user.id)
.select(:chart_id)
.order(created_at: :desc)
charts = charts.where(id: likes.map(&:chart_id))
end
if params[:q_id].present?
charts =
Expand All @@ -234,59 +260,7 @@ def list

render json: {
items: charts.map(&:to_sonolus),
searches: [
{
type: "advanced",
title: "#ADVANCED",
options: self.class.search_options
}
],
pageCount: page_count
}
end

def test_list
require_login!
params.permit(
:page,
*(self.class.test_search_options.map { |o| o[:query] })
)

alt_users = User.where(owner_id: current_user.id)
charts =
Chart
.where(author_id: [current_user.id] + alt_users.map(&:id))
.where.not(visibility: :public)

charts = charts.order(updated_at: :desc)
if params[:q_title].present?
charts =
charts.where("LOWER(title) LIKE ?", "%#{params[:q_title].downcase}%")
end
if params[:q_composer].present?
charts =
charts.where(
"LOWER(composer) LIKE ?",
"%#{params[:q_composer].downcase}%"
)
end
if params[:q_artist].present?
charts =
charts.where(
"LOWER(artist) LIKE ?",
"%#{params[:q_artist].downcase}%"
)
end

page_count = (charts.count / 20.0).ceil

charts = charts.offset((params[:page].to_i) * 20).limit(20)

render json: {
items: charts.map(&:to_sonolus),
search: {
options: self.class.test_search_options
},
searches:,
pageCount: page_count
}
end
Expand Down
17 changes: 7 additions & 10 deletions backend/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
en:
test:
title: "Chart Cyanvas: Test Server"
title: "Do not use this server!"
description: "This server is no longer in use."
levels:
_:
engine-title: "(Message)"
Expand Down Expand Up @@ -33,11 +34,6 @@ en:
not:
title: "Not liked."
description: "You have not liked this chart. Please tap the upper right button to go back."

test:
welcome:
title: "Welcome to Chart Cyanvas!"
description: "You can test your chart here, by tapping the [ More ] button below."
sonolus:
title: "Chart Cyanvas"
info:
Expand All @@ -53,6 +49,11 @@ en:
actions: "Actions"
variant_of: "Vary from"
variants: "Variants"

targets:
public: "Public"
testing: "Testing"
liked: "Liked"
search:
title: "Title"
title_placeholder: "Please enter the title..."
Expand All @@ -67,10 +68,6 @@ en:
id: "ID"
id_placeholder: "Please enter the ID..."
target: "Target"
targets:
- "Public"
- "Testing"
- "Liked"
sort: "Sort"
sorts:
- "Default"
Expand Down
17 changes: 7 additions & 10 deletions backend/config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ja:
test:
title: "Chart Cyanvas:テストサーバー"
title: "このサーバーは使用しないで下さい!"
description: "このサーバーはもう使用されていません。"
levels:
_:
engine-title: "(メッセージ)"
Expand Down Expand Up @@ -34,10 +35,6 @@ ja:
title: "この譜面は高評価されていません。"
description: "右上のボタンで前の画面に戻ります。"

test:
welcome:
title: "Chart Cyanvas テストサーバーへようこそ!"
description: "下の [ もっと ] ボタンを押すと譜面一覧に移動します。"
sonolus:
title: "Chart Cyanvas"
info:
Expand All @@ -53,6 +50,11 @@ ja:
actions: "操作"
variant_of: "派生元"
variants: "派生譜面"

targets:
public: "公開"
testing: "テスト中"
liked: "高評価済"
search:
title: "タイトル"
title_placeholder: "タイトルを入力して下さい..."
Expand All @@ -67,10 +69,6 @@ ja:
id: "ID"
id_placeholder: "#の後のIDを入力して下さい..."
target: "表示対象"
targets:
- "公開"
- "テスト中"
- "高評価済"
sort: "並び替え"
sorts:
- "デフォルト"
Expand All @@ -79,4 +77,3 @@ ja:
- "高評価順"
rating_max: "難易度(最高)"
rating_min: "難易度(最低)"

9 changes: 5 additions & 4 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
scope "/test" do
scope "sonolus" do
get "/info", to: "sonolus/info#test_info"
get "/levels/list", to: "sonolus/levels#test_list"
end
get "/rails/active_storage/*path" =>
redirect("/rails/active_storage/%{path}")
Expand All @@ -70,9 +69,11 @@
scope "/assets" do
get "/generate", to: "sonolus/asset#generate"
get "/:type/chcy-:name", to: "sonolus/asset#show"
get "/:type/:name", to: "sonolus/asset#show_static", constraints: {
name: /[^\/]+/
}
get "/:type/:name",
to: "sonolus/asset#show_static",
constraints: {
name: %r{[^/]+}
}
end

types = %w[backgrounds effects particles engines skins]
Expand Down

0 comments on commit fbe7cde

Please sign in to comment.