72 lines
3.0 KiB
Ruby
72 lines
3.0 KiB
Ruby
Rails.application.routes.draw do
|
|
|
|
locales = Site.first.in_use_locales rescue I18n.available_locales
|
|
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)
|
|
trans[locale]['more_plus'] = I18n.t("feed.more")
|
|
end
|
|
end
|
|
SiteFeedAnnc.where(:feed_id.nin=>SiteFeed.all.pluck(:id)).destroy
|
|
SiteFeed.each do |site_feed|
|
|
site_feed.add_notify
|
|
count = SiteFeedAnnc.where(feed_id: site_feed.id).count
|
|
if count>1
|
|
SiteFeedAnnc.where(feed_id: site_feed.id).limit(count-1).destroy
|
|
end
|
|
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
|
|
site_feed.sync_data_to_annc(tmp)
|
|
tmp.all_contents_for_feed = tmp.cache_annc(false,locales,trans)
|
|
tmp.save
|
|
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
|
|
elsif !tmp.nil?
|
|
tmp.destroy
|
|
end
|
|
end
|
|
SiteFeedAnnc.create_indexes
|
|
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
|
|
end
|
|
rescue => e
|
|
puts ['feed_routes',e]
|
|
end
|
|
end
|
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
|
namespace :admin do
|
|
get "/feeds/get_channel_list", to: 'feeds#get_channel_list'
|
|
get "/feeds/get_feed_list", to: 'feeds#get_feed_list'
|
|
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'
|
|
post "/feeds/channel_title", to: 'feeds#channel_title'
|
|
resources :feeds,only: ['new','index']
|
|
get '/feeds/settings' => 'feeds#settings'
|
|
patch '/feeds/update_settings' => 'feeds#update_settings'
|
|
get '/feeds/announcements' => 'feeds#announcements'
|
|
post '/feeds/process_annc' => 'feeds#process_annc'
|
|
get '/feeds/annc_content' => 'feeds#annc_content'
|
|
post "/feeds/force_refresh", to: 'feeds#force_refresh'
|
|
end
|
|
end
|
|
post "/xhr/feeds/notify_change" => "feeds#notify_change"
|
|
end
|