fix for report

This commit is contained in:
rulingcom 2024-11-25 19:30:25 +08:00
parent 1d33e33263
commit 86972bbd48
1 changed files with 24 additions and 13 deletions

View File

@ -58,6 +58,9 @@ class CalendarsController < ApplicationController
end end
def events def events
if !(valid_timestamp?(params[:start]) && valid_timestamp?(params[:end]))
return render json: {}, status: :unprocessable_entity
end
page = Page.find_by(:page_id => params[:page_id]) rescue nil page = Page.find_by(:page_id => params[:page_id]) rescue nil
events =[] events =[]
locale = params[:locale]||I18n.locale locale = params[:locale]||I18n.locale
@ -83,8 +86,11 @@ class CalendarsController < ApplicationController
end end
end end
def index_agenda def index_agenda
if !(valid_timestamp?(params[:unix_start]) && valid_timestamp?(params[:unix_end]))
return render json: {}, status: :unprocessable_entity
end
locale = params[:locale]||I18n.locale locale = params[:locale]||I18n.locale
locale = 'zh_tw' if locale == 'zh_cn' locale = 'zh_tw' if locale == 'zh_cn'
I18n.with_locale(locale) do I18n.with_locale(locale) do
@ -114,6 +120,9 @@ class CalendarsController < ApplicationController
end end
def agenda def agenda
if !(valid_timestamp?(params[:unix_start]) && valid_timestamp?(params[:unix_end]))
return render json: {}, status: :unprocessable_entity
end
locale = params[:locale]||I18n.locale locale = params[:locale]||I18n.locale
locale = 'zh_tw' if locale == 'zh_cn' locale = 'zh_tw' if locale == 'zh_cn'
I18n.with_locale(locale) do I18n.with_locale(locale) do
@ -129,6 +138,7 @@ class CalendarsController < ApplicationController
calendar_types = [] calendar_types = []
tags = [] tags = []
end end
if params[:unix_start].present? && params[:unix_end].present? if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).utc agenda_start = Time.at(params[:unix_start].to_i).utc
agenda_end = Time.at(params[:unix_end].to_i).utc agenda_end = Time.at(params[:unix_end].to_i).utc
@ -156,16 +166,17 @@ class CalendarsController < ApplicationController
</tr>" </tr>"
end.join("\n") end.join("\n")
end end
private
def valid_timestamp?(number)
begin
# Ensure the input is numeric and within a practical range
number = Integer(number) rescue Float(number)
min_timestamp = Time.new(1900, 1, 1).to_i
max_timestamp = Time.new(3000, 12, 31).to_i
number >= min_timestamp && number <= max_timestamp
rescue ArgumentError, TypeError
false
end
end
end end