lib/ayadn/diagnostics.rb in ayadn-3.0 vs lib/ayadn/diagnostics.rb in ayadn-4.0
- old
+ new
@@ -45,11 +45,11 @@
end
end
class CheckBase
- attr_accessor :response, :status
+ attr_accessor :response, :status, :baseURL
def initialize
@status = Status.new
end
@@ -108,11 +108,11 @@
def check
begin
check_root_api
@status.say_header "checking ADN server response"
- get_response "https://api.app.net/config"
+ get_response "#{@baseURL}/config"
check_response_code
body = JSON.parse(@response.body)
if body.blank? || body["data"].blank?
@status.say_red(:config, "no data")
else
@@ -126,16 +126,16 @@
private
def check_root_api
@status.say_header("default root API endpoint")
api_file = Dir.home + "/ayadn/.api.yml"
- baseURL = if File.exist?(api_file)
+ @baseURL = if File.exist?(api_file)
YAML.load(File.read(api_file))[:root]
else
"https://api.app.net"
end
- @status.say_green(:url, baseURL)
+ @status.say_green(:url, @baseURL)
end
end
class CheckAccounts < CheckBase
@@ -147,11 +147,11 @@
end
def check
begin
@status.say_header("checking accounts database")
- if find_active_account == true
+ if find_active_account
users = @db.execute("SELECT * FROM Accounts")
if users.blank?
@status.say_red(:abort, "no registered Ayadn users")
else
@status.say_green(:accounts, users.map { |user| user[2] }.join(", "))
@@ -162,11 +162,11 @@
check_id_handle
check_token
check_paths
check_config
@status.say_header("checking #{@handle}'s account database")
- if find_active_tables == true
+ if find_active_tables
check_tables_schemas
end
end
end
end
@@ -200,21 +200,21 @@
else
@userDB.schema.tables.each do |table|
@status.say_info "checking table #{table[0]}"
case table[0]
when "Bookmarks"
- break if check_bookmarks(table) == false
+ break if !check_bookmarks(table)
when "Aliases"
- break if check_aliases(table) == false
+ break if !check_aliases(table)
when "Blacklist"
- break if check_blacklist(table) == false
+ break if !check_blacklist(table)
when "Users"
- break if check_users(table) == false
+ break if !check_users(table)
when "Pagination"
- break if check_pagination(table) == false
+ break if !check_pagination(table)
when "TLIndex"
- break if check_TLIndex(table) == false
+ break if !check_TLIndex(table)
end
end
end
end
@@ -348,10 +348,11 @@
diff = Settings.defaults.deep_diff(config)
if diff.blank?
@status.say_green(:pass, "current user is using default values")
else
diff.each do |key, value|
+ skip if key == :movie || key == :tvshow # those are deprecated, not missing
if value.is_a?(Hash)
value.each do |inner_key, inner_value|
default = inner_value[0].nil? ? "none" : inner_value[0]
current = if inner_key == :deezer
inner_value[1].nil? ? "none" : inner_value[1][:code][0..10] + "..."
@@ -360,24 +361,24 @@
end
@status.say_green(:changed, "#{key}/#{inner_key} - Default: #{default}, Current: #{current}")
end
else
default = value[0].nil? ? "none" : value[0]
- if value[1].nil?
+ val = value[1]
+ if val.nil?
@status.say_red(:missing, "#{key} - Default: #{default}, Current: none")
else
- @status.say_green(:changed, "#{key} - Default: #{default}, Current: #{value[1]}")
+ @status.say_green(:changed, "#{key} - Default: #{default}, Current: #{val}")
end
end
end
end
end
end
def check_id_handle
id = @active_account[1]
@status.say_green(:id, id)
- # username = @active_account[0]
@handle = @active_account[2]
@status.say_green(:username, @handle)
end
def check_paths
\ No newline at end of file