From 5a6b36eccef00ed789786abde8bcb8214ed76321 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 5 Aug 2018 18:35:52 -0500 Subject: [PATCH] Add extra handling for year format --- src/invidious.cr | 12 ++++++++---- src/invidious/helpers/utils.cr | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 47fccb95..9b26b889 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -336,19 +336,23 @@ end # Search get "/results" do |env| - search_query = env.params.query["search_query"]? + query = env.params.query["search_query"]? + query ||= env.params.query["q"]? + query ||= "" + page = env.params.query["page"]?.try &.to_i? page ||= 1 - if search_query - env.redirect "/search?q=#{URI.escape(search_query)}&page=#{page}" + if query + env.redirect "/search?q=#{URI.escape(query)}&page=#{page}" else env.redirect "/" end end get "/search" do |env| - query = env.params.query["q"]? + query = env.params.query["search_query"]? + query ||= env.params.query["q"]? query ||= "" page = env.params.query["page"]?.try &.to_i? diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 4adc8ec2..3a9003da 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -63,7 +63,12 @@ def decode_time(string) end def decode_date(string : String) - # Time matches format "20 hours ago", "40 minutes ago"... + # String matches 'YYYY' + if string.match(/\d{4}/) + return Time.new(string.to_i, 1, 1) + end + + # String matches format "20 hours ago", "40 minutes ago"... date = string.split(" ")[-3, 3] delta = date[0].to_i