|
|
|
@ -54,6 +54,56 @@ module Invidious::Routes::API::V1::Authenticated
|
|
|
|
|
env.response.status_code = 204
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.get_history(env)
|
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
|
user = env.get("user").as(User)
|
|
|
|
|
|
|
|
|
|
page = env.params.query["page"]?.try &.to_i?
|
|
|
|
|
page ||= 1
|
|
|
|
|
|
|
|
|
|
max_results = env.params.query["max_results"]?.try &.to_i?.try &.clamp(0, MAX_ITEMS_PER_PAGE)
|
|
|
|
|
max_results ||= user.preferences.max_results
|
|
|
|
|
max_results ||= CONFIG.default_user_preferences.max_results
|
|
|
|
|
|
|
|
|
|
if user.watched[(page - 1) * max_results]?
|
|
|
|
|
watched = user.watched.reverse[(page - 1) * max_results, max_results]
|
|
|
|
|
end
|
|
|
|
|
watched ||= [] of String
|
|
|
|
|
|
|
|
|
|
return watched.to_json
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.mark_watched(env)
|
|
|
|
|
user = env.get("user").as(User)
|
|
|
|
|
|
|
|
|
|
id = env.params.url["id"]?.try &.as(String)
|
|
|
|
|
if !id
|
|
|
|
|
return error_json(400, "Invalid video id.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Invidious::Database::Users.mark_watched(user, id)
|
|
|
|
|
env.response.status_code = 204
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.mark_unwatched(env)
|
|
|
|
|
user = env.get("user").as(User)
|
|
|
|
|
|
|
|
|
|
id = env.params.url["id"]?.try &.as(String)
|
|
|
|
|
if !id
|
|
|
|
|
return error_json(400, "Invalid video id.")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Invidious::Database::Users.mark_unwatched(user, id)
|
|
|
|
|
env.response.status_code = 204
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.clear_history(env)
|
|
|
|
|
user = env.get("user").as(User)
|
|
|
|
|
|
|
|
|
|
Invidious::Database::Users.clear_watch_history(user)
|
|
|
|
|
env.response.status_code = 204
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.feed(env)
|
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
|
|
|
|
|
|