diff --git a/Gemfile b/Gemfile index 9ce0f998..5b738ec7 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem 'stripe', '1.15.0' #, source: 'https://code.stripe.com/' gem 'cocaine' gem 'zipruby' gem 'sass', require: nil -gem 'dav4rack' +gem 'dav4rack', git: 'https://github.com/planio-gmbh/dav4rack.git', branch: 'redmine-storage' gem 'filesize' gem 'thread' gem 'scrypt' diff --git a/Gemfile.lock b/Gemfile.lock index 041a0009..e5d828f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,14 @@ +GIT + remote: https://github.com/planio-gmbh/dav4rack.git + revision: e68dcf97399a116878a1a68b5c879f5cb05c40cb + branch: redmine-storage + specs: + dav4rack (0.3.0) + nokogiri (>= 1.4.2) + ox (>= 2.1.0) + rack (>= 1.1.0) + uuidtools (~> 2.1.1) + GEM remote: https://rubygems.org/ specs: @@ -49,10 +60,6 @@ GEM safe_yaml (~> 1.0.0) crass (1.0.2) dante (0.2.0) - dav4rack (0.3.0) - nokogiri (>= 1.4.2) - rack (>= 1.1.0) - uuidtools (~> 2.1.1) docile (1.1.5) domain_name (0.5.20160826) unf (>= 0.0.5, < 1.0.0) @@ -126,6 +133,7 @@ GEM mini_portile2 (~> 2.1.0) nokogumbo (1.4.7) nokogiri + ox (2.4.6) paypal-recurring (1.1.0) pg (0.18.4) poltergeist (1.11.0) @@ -258,7 +266,7 @@ DEPENDENCIES certified cocaine coveralls - dav4rack + dav4rack! erubis fabrication faker diff --git a/config.yml.template b/config.yml.template index 736cae23..5e9e892f 100644 --- a/config.yml.template +++ b/config.yml.template @@ -22,6 +22,7 @@ development: - 10.0.0.2 education_tag_whitelist: - mrteacher + screenshots_url: http://screenshots:derp@127.0.0.1:12345 test: database: 'postgres://localhost/neocities_test' database_pool: 1 diff --git a/workers/screenshot_worker.rb b/workers/screenshot_worker.rb index c39cfc16..d8807382 100644 --- a/workers/screenshot_worker.rb +++ b/workers/screenshot_worker.rb @@ -7,49 +7,22 @@ require 'open3' class ScreenshotWorker SCREENSHOTS_PATH = Site::SCREENSHOTS_ROOT HARD_TIMEOUT = 30.freeze + PAGE_WAIT_TIME = 5.freeze # 3D/VR sites take a bit to render after loading usually. include Sidekiq::Worker sidekiq_options queue: :screenshots, retry: 3, backtrace: true def perform(username, path) path = "/#{path}" unless path[0] == '/' - screenshot = Tempfile.new 'neocities_screenshot' - screenshot.close - screenshot_output_path = screenshot.path+'.png' - line = Cocaine::CommandLine.new( - "timeout #{HARD_TIMEOUT} phantomjs #{File.join DIR_ROOT, 'files', 'phantomjs_screenshot.js'}", ":url :output", - expected_outcodes: [0] + uri = Addressable::URI.parse $config['screenshots_url'] + api_user, api_password = uri.user, uri.password + uri = "#{uri.scheme}://#{uri.host}:#{uri.port}" + '?' + Rack::Utils.build_query( + url: Site.select(:username,:domain).where(username: username).first.uri + path, + wait_time: PAGE_WAIT_TIME ) - begin - output = line.run( - url: "http://#{username}.neocities.org#{path}", - output: screenshot_output_path - ) - rescue Cocaine::ExitStatusError => e - raise e - - # We set is_crashing after retries now, but use this code to go back to instant: - - #if e.message && e.message.match(/returned 124/) - # puts "#{username}/#{path} is timing out, discontinuing" - # site = Site[username: username] - # site.is_crashing = true - # site.save_changes validate: false - # return true - # - #else - # raise - #end - ensure - screenshot.unlink - end - img_list = Magick::ImageList.new - img_list.from_blob File.read(screenshot_output_path) - - screenshot.unlink - File.unlink screenshot_output_path + img_list.from_blob HTTP.basic_auth(user: api_user, pass: api_password).get(uri).to_s img_list.new_image(img_list.first.columns, img_list.first.rows) { self.background_color = "white" } img = img_list.reverse.flatten_images