mirror of
https://github.com/hkalexling/Mango.git
synced 2026-01-24 00:03:14 -05:00
* Add "title_title" to slim JSON * WIP * WIP * WIP * WIP * Add plugin subscription types * Revert "Subscription manager" This reverts commita612500b0f. * Use auto overflow tables cherry-picked froma612500b0f* Add endpoint for plugin subscription * WIP * WIP * Simplify subscription JSON parsing * Remove MangaDex files that are no longer needed * Fix linter * Refactor date filtering and use native date picker * Delete unnecessary raise for debugging * Subscription management API endpoints * Store manga ID with subscriptions * Add subscription manager page (WIP) * Finish subscription manager page * WIP * Finish plugin updater * Base64 encode chapter IDs * Fix actions on download manager * Trigger subscription update from manager page * Fix timestamp precision issue in plugin * Show target API version * Update last checked from manager page * Update last checked even when no chapters found * Fix null pid * Clean up * Document the subscription endpoints * Fix BigFloat conversion issue * Confirmation before deleting subscriptions * Reset table sort options * Show manga title on subscription manager
81 lines
2.2 KiB
Crystal
81 lines
2.2 KiB
Crystal
struct AdminRouter
|
|
def initialize
|
|
get "/admin" do |env|
|
|
storage = Storage.default
|
|
missing_count = storage.missing_titles.size +
|
|
storage.missing_entries.size
|
|
layout "admin"
|
|
end
|
|
|
|
get "/admin/user" do |env|
|
|
users = Storage.default.list_users
|
|
username = get_username env
|
|
layout "user"
|
|
end
|
|
|
|
get "/admin/user/edit" do |env|
|
|
username = env.params.query["username"]?
|
|
admin = env.params.query["admin"]?
|
|
if admin
|
|
admin = admin == "true"
|
|
end
|
|
error = env.params.query["error"]?
|
|
current_user = get_username env
|
|
new_user = username.nil? && admin.nil?
|
|
layout "user-edit"
|
|
end
|
|
|
|
post "/admin/user/edit" do |env|
|
|
# creating new user
|
|
username = env.params.body["username"]
|
|
password = env.params.body["password"]
|
|
# if `admin` is unchecked, the body hash
|
|
# would not contain `admin`
|
|
admin = !env.params.body["admin"]?.nil?
|
|
|
|
Storage.default.new_user username, password, admin
|
|
|
|
redirect env, "/admin/user"
|
|
rescue e
|
|
Logger.error e
|
|
redirect_url = URI.new \
|
|
path: "/admin/user/edit",
|
|
query: hash_to_query({"error" => e.message})
|
|
redirect env, redirect_url.to_s
|
|
end
|
|
|
|
post "/admin/user/edit/:original_username" do |env|
|
|
# editing existing user
|
|
username = env.params.body["username"]
|
|
password = env.params.body["password"]
|
|
# if `admin` is unchecked, the body hash would not contain `admin`
|
|
admin = !env.params.body["admin"]?.nil?
|
|
original_username = env.params.url["original_username"]
|
|
|
|
Storage.default.update_user \
|
|
original_username, username, password, admin
|
|
|
|
redirect env, "/admin/user"
|
|
rescue e
|
|
Logger.error e
|
|
redirect_url = URI.new \
|
|
path: "/admin/user/edit",
|
|
query: hash_to_query({"username" => original_username, \
|
|
"admin" => admin, "error" => e.message})
|
|
redirect env, redirect_url.to_s
|
|
end
|
|
|
|
get "/admin/downloads" do |env|
|
|
layout "download-manager"
|
|
end
|
|
|
|
get "/admin/subscriptions" do |env|
|
|
layout "subscription-manager"
|
|
end
|
|
|
|
get "/admin/missing" do |env|
|
|
layout "missing-items"
|
|
end
|
|
end
|
|
end
|