mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
initial stab at screenshots
This commit is contained in:
parent
5164914c4e
commit
87c733c932
8 changed files with 65 additions and 8 deletions
3
Gemfile
3
Gemfile
|
@ -10,6 +10,9 @@ gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
|
||||||
gem 'puma', require: nil
|
gem 'puma', require: nil
|
||||||
gem 'rubyzip'
|
gem 'rubyzip'
|
||||||
gem 'rack-recaptcha', require: 'rack/recaptcha'
|
gem 'rack-recaptcha', require: 'rack/recaptcha'
|
||||||
|
gem 'rmagick', require: nil
|
||||||
|
gem 'selenium-webdriver', require: nil
|
||||||
|
gem 'backburner'
|
||||||
|
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
17
Gemfile.lock
17
Gemfile.lock
|
@ -3,11 +3,18 @@ GEM
|
||||||
specs:
|
specs:
|
||||||
addressable (2.3.4)
|
addressable (2.3.4)
|
||||||
ansi (1.4.3)
|
ansi (1.4.3)
|
||||||
|
backburner (0.3.4)
|
||||||
|
beaneater (~> 0.3.0)
|
||||||
|
dante (~> 0.1.5)
|
||||||
bcrypt-ruby (3.0.1)
|
bcrypt-ruby (3.0.1)
|
||||||
|
beaneater (0.3.0)
|
||||||
builder (3.2.0)
|
builder (3.2.0)
|
||||||
|
childprocess (0.3.9)
|
||||||
|
ffi (~> 1.0, >= 1.0.11)
|
||||||
coderay (1.0.9)
|
coderay (1.0.9)
|
||||||
columnize (0.3.6)
|
columnize (0.3.6)
|
||||||
crack (0.3.2)
|
crack (0.3.2)
|
||||||
|
dante (0.1.5)
|
||||||
debugger (1.6.0)
|
debugger (1.6.0)
|
||||||
columnize (>= 0.3.1)
|
columnize (>= 0.3.1)
|
||||||
debugger-linecache (~> 1.2.0)
|
debugger-linecache (~> 1.2.0)
|
||||||
|
@ -63,7 +70,13 @@ GEM
|
||||||
raindrops (0.10.0)
|
raindrops (0.10.0)
|
||||||
rake (10.0.4)
|
rake (10.0.4)
|
||||||
redis (3.0.4)
|
redis (3.0.4)
|
||||||
|
rmagick (2.13.2)
|
||||||
rubyzip (0.9.9)
|
rubyzip (0.9.9)
|
||||||
|
selenium-webdriver (2.33.0)
|
||||||
|
childprocess (>= 0.2.5)
|
||||||
|
multi_json (~> 1.0)
|
||||||
|
rubyzip
|
||||||
|
websocket (~> 1.0.4)
|
||||||
sequel (3.47.0)
|
sequel (3.47.0)
|
||||||
sequel_pg (1.6.6)
|
sequel_pg (1.6.6)
|
||||||
pg (>= 0.8.0)
|
pg (>= 0.8.0)
|
||||||
|
@ -95,11 +108,13 @@ GEM
|
||||||
webmock (1.11.0)
|
webmock (1.11.0)
|
||||||
addressable (>= 2.2.7)
|
addressable (>= 2.2.7)
|
||||||
crack (>= 0.3.2)
|
crack (>= 0.3.2)
|
||||||
|
websocket (1.0.7)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
backburner
|
||||||
bcrypt-ruby
|
bcrypt-ruby
|
||||||
fabrication
|
fabrication
|
||||||
faker
|
faker
|
||||||
|
@ -120,8 +135,10 @@ DEPENDENCIES
|
||||||
rainbows
|
rainbows
|
||||||
rake
|
rake
|
||||||
redis
|
redis
|
||||||
|
rmagick
|
||||||
ruby-debug
|
ruby-debug
|
||||||
rubyzip
|
rubyzip
|
||||||
|
selenium-webdriver
|
||||||
sequel
|
sequel
|
||||||
sequel_pg
|
sequel_pg
|
||||||
shotgun
|
shotgun
|
||||||
|
|
1
Rakefile
1
Rakefile
|
@ -1,4 +1,5 @@
|
||||||
require "rake/testtask"
|
require "rake/testtask"
|
||||||
|
require 'backburner/tasks'
|
||||||
|
|
||||||
desc "Run all tests"
|
desc "Run all tests"
|
||||||
Rake::TestTask.new do |t|
|
Rake::TestTask.new do |t|
|
||||||
|
|
5
app.rb
5
app.rb
|
@ -143,6 +143,8 @@ post '/site_files/upload' do
|
||||||
FileUtils.mv params[:newfile][:tempfile].path, dest_path
|
FileUtils.mv params[:newfile][:tempfile].path, dest_path
|
||||||
File.chmod(0640, dest_path) if self.class.production?
|
File.chmod(0640, dest_path) if self.class.production?
|
||||||
|
|
||||||
|
Backburner.enqueue ScreenshotJob, current_site.username
|
||||||
|
|
||||||
flash[:success] = "Successfully uploaded file #{sanitized_filename}."
|
flash[:success] = "Successfully uploaded file #{sanitized_filename}."
|
||||||
redirect '/dashboard'
|
redirect '/dashboard'
|
||||||
end
|
end
|
||||||
|
@ -200,6 +202,9 @@ post '/site_files/save/:filename' do |filename|
|
||||||
|
|
||||||
FileUtils.mv tmpfile.path, dest_path
|
FileUtils.mv tmpfile.path, dest_path
|
||||||
File.chmod(0640, dest_path) if self.class.production?
|
File.chmod(0640, dest_path) if self.class.production?
|
||||||
|
|
||||||
|
Backburner.enqueue ScreenshotJob, current_site.username
|
||||||
|
|
||||||
'ok'
|
'ok'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,4 @@ development:
|
||||||
session_secret: SETSOMETHINGHERE
|
session_secret: SETSOMETHINGHERE
|
||||||
recaptcha_public_key: ddsfsdfsdf
|
recaptcha_public_key: ddsfsdfsdf
|
||||||
recaptcha_private_key: fsdgfdsdfd
|
recaptcha_private_key: fsdgfdsdfd
|
||||||
|
phantomjs_url: http://localhost:40000
|
|
@ -24,6 +24,8 @@ if defined?(Pry)
|
||||||
Pry.commands.alias_command 'f', 'finish'
|
Pry.commands.alias_command 'f', 'finish'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require File.join(DIR_ROOT, 'jobs', 'screenshot_job.rb')
|
||||||
|
|
||||||
Sequel.datetime_class = Time
|
Sequel.datetime_class = Time
|
||||||
Sequel.extension :pagination
|
Sequel.extension :pagination
|
||||||
Sequel.extension :migration
|
Sequel.extension :migration
|
||||||
|
|
28
jobs/screenshot_job.rb
Normal file
28
jobs/screenshot_job.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'selenium-webdriver'
|
||||||
|
require 'RMagick'
|
||||||
|
|
||||||
|
class ScreenshotJob
|
||||||
|
include Backburner::Queue
|
||||||
|
|
||||||
|
queue_priority 1000
|
||||||
|
|
||||||
|
def self.perform(username)
|
||||||
|
screenshot = Tempfile.new 'neocities_screenshot'
|
||||||
|
screenshot.close
|
||||||
|
|
||||||
|
driver = Selenium::WebDriver.for :remote, url: $config['phantomjs_url']
|
||||||
|
driver.manage.window.resize_to 1280, 720
|
||||||
|
|
||||||
|
wait = Selenium::WebDriver::Wait.new(:timeout => 5) # seconds
|
||||||
|
wait.until {
|
||||||
|
driver.navigate.to "http://#{username}.neocities.org"
|
||||||
|
driver.save_screenshot screenshot.path
|
||||||
|
}
|
||||||
|
|
||||||
|
driver.quit
|
||||||
|
|
||||||
|
img = Magick::Image.read(screenshot.path).first
|
||||||
|
img.crop_resized!(600, 400, Magick::NorthGravity)
|
||||||
|
img.write File.join(DIR_ROOT, 'public', 'site_screenshots', "#{user}.jpg")
|
||||||
|
end
|
||||||
|
end
|
0
public/site_screenshots/.gitignore
vendored
Normal file
0
public/site_screenshots/.gitignore
vendored
Normal file
Loading…
Add table
Reference in a new issue