|
|
@ -11,7 +11,7 @@ struct User
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
add_mapping({
|
|
|
|
db_mapping({
|
|
|
|
updated: Time,
|
|
|
|
updated: Time,
|
|
|
|
notifications: Array(String),
|
|
|
|
notifications: Array(String),
|
|
|
|
subscriptions: Array(String),
|
|
|
|
subscriptions: Array(String),
|
|
|
@ -26,29 +26,6 @@ struct User
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_USER_PREFERENCES = Preferences.new(
|
|
|
|
|
|
|
|
video_loop: false,
|
|
|
|
|
|
|
|
autoplay: false,
|
|
|
|
|
|
|
|
continue: false,
|
|
|
|
|
|
|
|
local: false,
|
|
|
|
|
|
|
|
listen: false,
|
|
|
|
|
|
|
|
speed: 1.0_f32,
|
|
|
|
|
|
|
|
quality: "hd720",
|
|
|
|
|
|
|
|
volume: 100,
|
|
|
|
|
|
|
|
comments: ["youtube", ""],
|
|
|
|
|
|
|
|
captions: ["", "", ""],
|
|
|
|
|
|
|
|
related_videos: true,
|
|
|
|
|
|
|
|
redirect_feed: false,
|
|
|
|
|
|
|
|
locale: "en-US",
|
|
|
|
|
|
|
|
dark_mode: false,
|
|
|
|
|
|
|
|
thin_mode: false,
|
|
|
|
|
|
|
|
max_results: 40,
|
|
|
|
|
|
|
|
sort: "published",
|
|
|
|
|
|
|
|
latest_only: false,
|
|
|
|
|
|
|
|
unseen_only: false,
|
|
|
|
|
|
|
|
notifications_only: false,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Preferences
|
|
|
|
struct Preferences
|
|
|
|
module StringToArray
|
|
|
|
module StringToArray
|
|
|
|
def self.to_json(value : Array(String), json : JSON::Builder)
|
|
|
|
def self.to_json(value : Array(String), json : JSON::Builder)
|
|
|
@ -71,29 +48,62 @@ struct Preferences
|
|
|
|
|
|
|
|
|
|
|
|
result
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.to_yaml(value : Array(String), yaml : YAML::Nodes::Builder)
|
|
|
|
|
|
|
|
yaml.sequence do
|
|
|
|
|
|
|
|
value.each do |element|
|
|
|
|
|
|
|
|
yaml.scalar element
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Array(String)
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
unless node.is_a?(YAML::Nodes::Sequence)
|
|
|
|
|
|
|
|
node.raise "Expected sequence, not #{node.class}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = [] of String
|
|
|
|
|
|
|
|
node.nodes.each do
|
|
|
|
|
|
|
|
unless node.is_a?(YAML::Nodes::Scalar)
|
|
|
|
|
|
|
|
node.raise "Expected scalar, not #{node.class}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result << node.value
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
rescue ex
|
|
|
|
|
|
|
|
if node.is_a?(YAML::Nodes::Scalar)
|
|
|
|
|
|
|
|
result = [node.value, ""]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
result = ["", ""]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
json_mapping({
|
|
|
|
json_mapping({
|
|
|
|
video_loop: {type: Bool, default: DEFAULT_USER_PREFERENCES.video_loop},
|
|
|
|
autoplay: {type: Bool, default: CONFIG.default_user_preferences.autoplay},
|
|
|
|
autoplay: {type: Bool, default: DEFAULT_USER_PREFERENCES.autoplay},
|
|
|
|
captions: {type: Array(String), default: CONFIG.default_user_preferences.captions, converter: StringToArray},
|
|
|
|
continue: {type: Bool, default: DEFAULT_USER_PREFERENCES.continue},
|
|
|
|
comments: {type: Array(String), default: CONFIG.default_user_preferences.comments, converter: StringToArray},
|
|
|
|
local: {type: Bool, default: DEFAULT_USER_PREFERENCES.local},
|
|
|
|
continue: {type: Bool, default: CONFIG.default_user_preferences.continue},
|
|
|
|
listen: {type: Bool, default: DEFAULT_USER_PREFERENCES.listen},
|
|
|
|
dark_mode: {type: Bool, default: CONFIG.default_user_preferences.dark_mode},
|
|
|
|
speed: {type: Float32, default: DEFAULT_USER_PREFERENCES.speed},
|
|
|
|
latest_only: {type: Bool, default: CONFIG.default_user_preferences.latest_only},
|
|
|
|
quality: {type: String, default: DEFAULT_USER_PREFERENCES.quality},
|
|
|
|
listen: {type: Bool, default: CONFIG.default_user_preferences.listen},
|
|
|
|
volume: {type: Int32, default: DEFAULT_USER_PREFERENCES.volume},
|
|
|
|
local: {type: Bool, default: CONFIG.default_user_preferences.local},
|
|
|
|
comments: {type: Array(String), default: DEFAULT_USER_PREFERENCES.comments, converter: StringToArray},
|
|
|
|
locale: {type: String, default: CONFIG.default_user_preferences.locale},
|
|
|
|
captions: {type: Array(String), default: DEFAULT_USER_PREFERENCES.captions, converter: StringToArray},
|
|
|
|
max_results: {type: Int32, default: CONFIG.default_user_preferences.max_results},
|
|
|
|
redirect_feed: {type: Bool, default: DEFAULT_USER_PREFERENCES.redirect_feed},
|
|
|
|
notifications_only: {type: Bool, default: CONFIG.default_user_preferences.notifications_only},
|
|
|
|
related_videos: {type: Bool, default: DEFAULT_USER_PREFERENCES.related_videos},
|
|
|
|
quality: {type: String, default: CONFIG.default_user_preferences.quality},
|
|
|
|
dark_mode: {type: Bool, default: DEFAULT_USER_PREFERENCES.dark_mode},
|
|
|
|
redirect_feed: {type: Bool, default: CONFIG.default_user_preferences.redirect_feed},
|
|
|
|
thin_mode: {type: Bool, default: DEFAULT_USER_PREFERENCES.thin_mode},
|
|
|
|
related_videos: {type: Bool, default: CONFIG.default_user_preferences.related_videos},
|
|
|
|
max_results: {type: Int32, default: DEFAULT_USER_PREFERENCES.max_results},
|
|
|
|
sort: {type: String, default: CONFIG.default_user_preferences.sort},
|
|
|
|
sort: {type: String, default: DEFAULT_USER_PREFERENCES.sort},
|
|
|
|
speed: {type: Float32, default: CONFIG.default_user_preferences.speed},
|
|
|
|
latest_only: {type: Bool, default: DEFAULT_USER_PREFERENCES.latest_only},
|
|
|
|
thin_mode: {type: Bool, default: CONFIG.default_user_preferences.thin_mode},
|
|
|
|
unseen_only: {type: Bool, default: DEFAULT_USER_PREFERENCES.unseen_only},
|
|
|
|
unseen_only: {type: Bool, default: CONFIG.default_user_preferences.unseen_only},
|
|
|
|
notifications_only: {type: Bool, default: DEFAULT_USER_PREFERENCES.notifications_only},
|
|
|
|
video_loop: {type: Bool, default: CONFIG.default_user_preferences.video_loop},
|
|
|
|
locale: {type: String, default: DEFAULT_USER_PREFERENCES.locale},
|
|
|
|
volume: {type: Int32, default: CONFIG.default_user_preferences.volume},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -174,7 +184,7 @@ def fetch_user(sid, headers, db)
|
|
|
|
|
|
|
|
|
|
|
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
|
|
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
|
|
|
|
|
|
|
|
|
|
|
user = User.new(Time.now, [] of String, channels, email, DEFAULT_USER_PREFERENCES, nil, token, [] of String)
|
|
|
|
user = User.new(Time.now, [] of String, channels, email, CONFIG.default_user_preferences, nil, token, [] of String)
|
|
|
|
return user, sid
|
|
|
|
return user, sid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -182,7 +192,7 @@ def create_user(sid, email, password)
|
|
|
|
password = Crypto::Bcrypt::Password.create(password, cost: 10)
|
|
|
|
password = Crypto::Bcrypt::Password.create(password, cost: 10)
|
|
|
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
|
|
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
|
|
|
|
|
|
|
|
|
|
|
user = User.new(Time.now, [] of String, [] of String, email, DEFAULT_USER_PREFERENCES, password.to_s, token, [] of String)
|
|
|
|
user = User.new(Time.now, [] of String, [] of String, email, CONFIG.default_user_preferences, password.to_s, token, [] of String)
|
|
|
|
|
|
|
|
|
|
|
|
return user, sid
|
|
|
|
return user, sid
|
|
|
|
end
|
|
|
|
end
|
|
|
|