This commit is contained in:
BoHung Chiu 2022-05-22 19:02:20 +08:00
parent c3cfada5d7
commit bf6234cdbc
1 changed files with 9 additions and 7 deletions

View File

@ -1,13 +1,15 @@
Rails.application.routes.draw do Rails.application.routes.draw do
require 'fileutils' require 'fileutils'
get 'ad_banners/widget' get 'ad_banners/widget'
Thread.new do if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a Thread.new do
ad_images.each do |ad_image| ad_images = AdImage.where(:video_file.ne=>nil,:video_snapshot=>nil).to_a
ad_image[:video_snapshot] = File.basename(ad_image.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg" ad_images.each do |ad_image|
FileUtils.mkdir_p(File.dirname(ad_image.video_snapshot.file.path)) ad_image[:video_snapshot] = File.basename(ad_image.video_file.file.path).split(/\.[^.]+$/)[0] + ".jpg"
system("tmp/ffmpeg/ffmpeg -i #{ad_image.video_file.file.path} -vframes 1 #{ad_image.video_snapshot.file.path}") FileUtils.mkdir_p(File.dirname(ad_image.video_snapshot.file.path))
ad_image.save system("tmp/ffmpeg/ffmpeg -i #{ad_image.video_file.file.path} -vframes 1 #{ad_image.video_snapshot.file.path}")
ad_image.save
end
end end
end end
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales