mirror of
https://github.com/neocities/neocities.git
synced 2025-04-28 11:12:30 +02:00
fixes for screenshot worker
This commit is contained in:
parent
0aca6b3328
commit
fbf78f04d6
8 changed files with 69 additions and 2 deletions
1
Gemfile
1
Gemfile
|
@ -61,6 +61,7 @@ group :test do
|
||||||
gem 'phantomjs', require: 'phantomjs/poltergeist'
|
gem 'phantomjs', require: 'phantomjs/poltergeist'
|
||||||
gem 'capybara_minitest_spec'
|
gem 'capybara_minitest_spec'
|
||||||
gem 'rack_session_access', require: nil
|
gem 'rack_session_access', require: nil
|
||||||
|
gem 'webmock', require: nil
|
||||||
|
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'simplecov', require: nil
|
gem 'simplecov', require: nil
|
||||||
|
|
|
@ -45,6 +45,8 @@ GEM
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
columnize (0.3.6)
|
columnize (0.3.6)
|
||||||
connection_pool (2.0.0)
|
connection_pool (2.0.0)
|
||||||
|
crack (0.4.2)
|
||||||
|
safe_yaml (~> 1.0.0)
|
||||||
debugger (1.6.6)
|
debugger (1.6.6)
|
||||||
columnize (>= 0.3.1)
|
columnize (>= 0.3.1)
|
||||||
debugger-linecache (~> 1.2.0)
|
debugger-linecache (~> 1.2.0)
|
||||||
|
@ -144,6 +146,7 @@ GEM
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
retriable (1.4.1)
|
retriable (1.4.1)
|
||||||
rmagick (2.13.2)
|
rmagick (2.13.2)
|
||||||
|
safe_yaml (1.0.1)
|
||||||
sass (3.3.8)
|
sass (3.3.8)
|
||||||
screencap (0.1.1)
|
screencap (0.1.1)
|
||||||
phantomjs
|
phantomjs
|
||||||
|
@ -191,6 +194,9 @@ GEM
|
||||||
rack
|
rack
|
||||||
raindrops (~> 0.7)
|
raindrops (~> 0.7)
|
||||||
uuidtools (2.1.4)
|
uuidtools (2.1.4)
|
||||||
|
webmock (1.17.4)
|
||||||
|
addressable (>= 2.2.7)
|
||||||
|
crack (>= 0.3.2)
|
||||||
websocket-driver (0.3.4)
|
websocket-driver (0.3.4)
|
||||||
xpath (2.0.0)
|
xpath (2.0.0)
|
||||||
nokogiri (~> 1.3)
|
nokogiri (~> 1.3)
|
||||||
|
@ -244,4 +250,5 @@ DEPENDENCIES
|
||||||
sinatra-xsendfile
|
sinatra-xsendfile
|
||||||
stripe!
|
stripe!
|
||||||
tilt
|
tilt
|
||||||
|
webmock
|
||||||
zipruby
|
zipruby
|
||||||
|
|
|
@ -366,7 +366,7 @@ class Site < Sequel::Model
|
||||||
ext = File.extname(path).gsub(/^./, '')
|
ext = File.extname(path).gsub(/^./, '')
|
||||||
|
|
||||||
if ext.match HTML_REGEX
|
if ext.match HTML_REGEX
|
||||||
ScreenshotWorker.perform_async values[:username], path
|
ScreenshotWorker.perform_async values[:username], relative_path
|
||||||
elsif ext.match IMAGE_REGEX
|
elsif ext.match IMAGE_REGEX
|
||||||
ThumbnailWorker.perform_async values[:username], relative_path
|
ThumbnailWorker.perform_async values[:username], relative_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,9 @@ Bundler.require :test
|
||||||
|
|
||||||
#require 'minitest/pride'
|
#require 'minitest/pride'
|
||||||
require 'minitest/autorun'
|
require 'minitest/autorun'
|
||||||
|
require 'webmock'
|
||||||
|
include WebMock::API
|
||||||
|
require 'webmock/minitest'
|
||||||
require 'sidekiq/testing'
|
require 'sidekiq/testing'
|
||||||
|
|
||||||
Sinatra::Application.configure do |app|
|
Sinatra::Application.configure do |app|
|
||||||
|
|
8
tests/files/index.html
Normal file
8
tests/files/index.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Hello?</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hi there!</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -9,6 +9,24 @@ end
|
||||||
|
|
||||||
describe 'site_files' do
|
describe 'site_files' do
|
||||||
describe 'upload' do
|
describe 'upload' do
|
||||||
|
|
||||||
|
it 'succeeds with index.html file' do
|
||||||
|
site = Fabricate :site
|
||||||
|
PurgeCacheWorker.jobs.clear
|
||||||
|
ScreenshotWorker.jobs.clear
|
||||||
|
|
||||||
|
post '/site_files/upload', {
|
||||||
|
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html'),
|
||||||
|
'csrf_token' => 'abcd'
|
||||||
|
}, {'rack.session' => { 'id' => site.id, '_csrf_token' => 'abcd' }}
|
||||||
|
last_response.body.must_match /successfully uploaded/i
|
||||||
|
File.exists?(site.files_path('index.html')).must_equal true
|
||||||
|
|
||||||
|
args = ScreenshotWorker.jobs.first['args']
|
||||||
|
args.first.must_equal site.username
|
||||||
|
args.last.must_equal 'index.html'
|
||||||
|
end
|
||||||
|
|
||||||
it 'succeeds with valid file' do
|
it 'succeeds with valid file' do
|
||||||
site = Fabricate :site
|
site = Fabricate :site
|
||||||
PurgeCacheWorker.jobs.clear
|
PurgeCacheWorker.jobs.clear
|
||||||
|
|
28
tests/workers/screenshot_worker_tests.rb
Normal file
28
tests/workers/screenshot_worker_tests.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require_relative '../environment.rb'
|
||||||
|
|
||||||
|
describe ScreenshotWorker do
|
||||||
|
|
||||||
|
it 'saves a screenshot for a root html file' do
|
||||||
|
worker = ScreenshotWorker.new
|
||||||
|
worker.perform 'kyledrake', 'index.html'
|
||||||
|
site = Fabricate :site
|
||||||
|
Site::SCREENSHOT_RESOLUTIONS.each do |r|
|
||||||
|
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "index.html.#{r}.jpg")).must_equal true
|
||||||
|
site.screenshot_url('index.html', r).must_equal(
|
||||||
|
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "index.html.#{r}.jpg")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'saves a screenshot for a path html file' do
|
||||||
|
worker = ScreenshotWorker.new
|
||||||
|
worker.perform 'kyledrake', 'derpie/derp/index.html'
|
||||||
|
site = Fabricate :site
|
||||||
|
Site::SCREENSHOT_RESOLUTIONS.each do |r|
|
||||||
|
File.exists?(File.join(Site::SCREENSHOTS_ROOT, 'kyledrake', "derpie/derp/index.html.#{r}.jpg")).must_equal true
|
||||||
|
site.screenshot_url('derpie/derp/index.html', r).must_equal(
|
||||||
|
File.join(Site::SCREENSHOTS_URL_ROOT, site.username, "derpie/derp/index.html.#{r}.jpg")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -80,7 +80,9 @@ class ScreenshotWorker
|
||||||
img = img_list.reverse.flatten_images
|
img = img_list.reverse.flatten_images
|
||||||
|
|
||||||
user_screenshots_path = File.join SCREENSHOTS_PATH, username
|
user_screenshots_path = File.join SCREENSHOTS_PATH, username
|
||||||
FileUtils.mkdir_p user_screenshots_path
|
screenshot_path = File.join user_screenshots_path, File.dirname(path)
|
||||||
|
|
||||||
|
FileUtils.mkdir_p screenshot_path unless Dir.exists?(screenshot_path)
|
||||||
|
|
||||||
Site::SCREENSHOT_RESOLUTIONS.each do |res|
|
Site::SCREENSHOT_RESOLUTIONS.each do |res|
|
||||||
img.scale(*res.split('x').collect {|r| r.to_i}).write(File.join(user_screenshots_path, "#{path}.#{res}.jpg")) {
|
img.scale(*res.split('x').collect {|r| r.to_i}).write(File.join(user_screenshots_path, "#{path}.#{res}.jpg")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue