2015-07-07 11:51:56 +00:00
|
|
|
Rails.application.routes.draw do
|
|
|
|
|
|
|
|
locales = Site.first.in_use_locales rescue I18n.available_locales
|
2021-11-17 14:05:08 +00:00
|
|
|
Thread.new do
|
|
|
|
begin
|
|
|
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
|
|
|
trans = {}
|
|
|
|
locales.each do |locale|
|
|
|
|
locale = locale.to_s
|
|
|
|
trans[locale] = {}
|
|
|
|
I18n.with_locale(locale) do
|
|
|
|
trans[locale]['top'] = I18n.t(:top)
|
|
|
|
trans[locale]['hot'] = I18n.t(:hot)
|
2022-01-21 02:15:28 +00:00
|
|
|
trans[locale]['more_plus'] = I18n.t("feed.more")
|
2021-11-17 14:05:08 +00:00
|
|
|
end
|
|
|
|
end
|
2022-06-21 10:10:50 +00:00
|
|
|
org_remote_site_urls = SiteFeed.all.pluck(:remote_site_url).uniq
|
|
|
|
all_remote_site_urls = org_remote_site_urls.map{|a| a.split('://')[1]}.uniq
|
|
|
|
all_remote_site_urls.each do |remote_site_url|
|
|
|
|
match_urls = org_remote_site_urls.select{|s| s.include?("://#{remote_site_url}")}
|
|
|
|
if match_urls.count == 2
|
|
|
|
SiteFeed.where(:remote_site_url.in=>match_urls).update_all(:remote_site_url=>"https://#{remote_site_url}")
|
|
|
|
SiteFeedAnnc.where(:remote_site_url.in=>match_urls).update_all(:remote_site_url=>"https://#{remote_site_url}")
|
|
|
|
end
|
|
|
|
end
|
2022-05-24 09:17:26 +00:00
|
|
|
SiteFeed.all.order_by(:channel_title=>-1).to_a.group_by(&:remote_site_url).each do |url, site_feeds|
|
|
|
|
site_feed = site_feeds.first
|
|
|
|
channel_title_translations = site_feed.channel_title_translations
|
2022-06-21 10:10:50 +00:00
|
|
|
SiteFeed.where(:id.in=>site_feeds[1..-1].map{|sf| sf.id}).update_all(:channel_title_translations => channel_title_translations)
|
2022-05-24 09:17:26 +00:00
|
|
|
end
|
2021-11-18 05:33:25 +00:00
|
|
|
SiteFeedAnnc.where(:feed_id.nin=>SiteFeed.all.pluck(:id)).destroy
|
2021-11-17 14:05:08 +00:00
|
|
|
SiteFeed.each do |site_feed|
|
2022-05-09 12:10:29 +00:00
|
|
|
site_feed.add_notify
|
2021-11-18 05:59:37 +00:00
|
|
|
count = SiteFeedAnnc.where(feed_id: site_feed.id).count
|
|
|
|
if count>1
|
|
|
|
SiteFeedAnnc.where(feed_id: site_feed.id).limit(count-1).destroy
|
|
|
|
end
|
2021-11-17 14:05:08 +00:00
|
|
|
tmp = SiteFeedAnnc.where(feed_id: site_feed.id).first
|
|
|
|
if site_feed.disabled != true
|
|
|
|
if tmp.nil?
|
|
|
|
tmp = SiteFeedAnnc.new(feed_id: site_feed.id)
|
|
|
|
end
|
2022-05-22 10:36:26 +00:00
|
|
|
site_feed.sync_data_to_annc(tmp)
|
2021-11-17 14:05:08 +00:00
|
|
|
tmp.all_contents_for_feed = tmp.cache_annc(false,locales,trans)
|
|
|
|
tmp.save
|
2022-05-22 10:36:26 +00:00
|
|
|
if site_feed.feeds_model && site_feed.feeds_finish_callback
|
|
|
|
feeds_model = site_feed.feeds_model.constantize
|
|
|
|
feeds_model.send(site_feed.feeds_finish_callback, "update_all", {"data"=>site_feed.get_annc(false),"feed_id"=>site_feed.id,"category_id"=>site_feed.merge_with_category})
|
|
|
|
end
|
2021-11-17 14:05:08 +00:00
|
|
|
elsif !tmp.nil?
|
|
|
|
tmp.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
SiteFeedAnnc.create_indexes
|
2022-05-22 10:36:26 +00:00
|
|
|
sync_fields = SiteFeed::ModuleAppSyncFields
|
|
|
|
ModuleApp.where(:feeds_model.ne=>nil).each do |module_app|
|
|
|
|
sync_fields_data = sync_fields.map{|f| [f, module_app[f]] }.to_h
|
|
|
|
SiteFeedAnnc.where(:channel_key=>module_app.key).update_all(sync_fields_data)
|
|
|
|
SiteFeed.where(:channel_key=>module_app.key).update_all(sync_fields_data)
|
|
|
|
end
|
2021-11-17 14:05:08 +00:00
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
puts ['feed_routes',e]
|
|
|
|
end
|
|
|
|
end
|
2015-07-07 11:51:56 +00:00
|
|
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
|
|
|
namespace :admin do
|
|
|
|
get "/feeds/get_channel_list", to: 'feeds#get_channel_list'
|
2022-09-25 11:34:29 +00:00
|
|
|
post "/feeds/get_feed_list", to: 'feeds#get_feed_list'
|
2015-07-07 11:51:56 +00:00
|
|
|
get "/feeds/get_category_list", to: 'feeds#get_category_list'
|
|
|
|
post "/feeds/subscribe", to: 'feeds#subscribe'
|
|
|
|
post "/feeds/unsubscribe", to: 'feeds#unsubscribe'
|
|
|
|
post "/feeds/disable", to: 'feeds#disable'
|
2015-11-09 17:38:30 +00:00
|
|
|
post "/feeds/channel_title", to: 'feeds#channel_title'
|
2020-04-05 14:36:09 +00:00
|
|
|
resources :feeds,only: ['new','index']
|
2021-12-30 09:46:30 +00:00
|
|
|
get '/feeds/settings' => 'feeds#settings'
|
|
|
|
patch '/feeds/update_settings' => 'feeds#update_settings'
|
2020-04-05 14:36:09 +00:00
|
|
|
get '/feeds/announcements' => 'feeds#announcements'
|
|
|
|
post '/feeds/process_annc' => 'feeds#process_annc'
|
|
|
|
get '/feeds/annc_content' => 'feeds#annc_content'
|
2021-09-15 08:43:19 +00:00
|
|
|
post "/feeds/force_refresh", to: 'feeds#force_refresh'
|
2015-07-07 11:51:56 +00:00
|
|
|
end
|
|
|
|
end
|
2022-05-09 12:10:29 +00:00
|
|
|
post "/xhr/feeds/notify_change" => "feeds#notify_change"
|
2015-07-07 11:51:56 +00:00
|
|
|
end
|