Class: Specbook::ViewerController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Specbook::ViewerController
- Defined in:
- app/controllers/specbook/viewer_controller.rb
Instance Method Summary collapse
Instance Method Details
#screenshot ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/specbook/viewer_controller.rb', line 14 def screenshot filename = params[:filename] return head(:bad_request) unless filename.match?(/\Astep_\d{4}_\d{3}\.png\z/) path = screenshot_dir.join(filename) return head(:not_found) unless File.exist?(path) send_file path, type: "image/png", disposition: "inline" end |
#show ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/controllers/specbook/viewer_controller.rb', line 6 def show @manifest = load_manifest @traces = load_traces @features = load_features @specbook_js_config = build_js_config render "specbook/viewer/show", layout: false end |
#trace ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/specbook/viewer_controller.rb', line 24 def trace filename = params[:filename] return head(:bad_request) unless filename.match?(/\A[\w\-]+\.zip\z/) path = Specbook.config.trace_root.join(filename) return head(:not_found) unless File.exist?(path) send_file path, type: "application/zip", disposition: "attachment" end |
#view_trace ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/specbook/viewer_controller.rb', line 34 def view_trace filename = params[:filename] return head(:bad_request) unless filename.match?(/\A[\w\-]+\.zip\z/) path = Specbook.config.trace_root.join(filename) return head(:not_found) unless File.exist?(path) port = Specbook.config.trace_viewer_port # Kill any existing trace viewer on this port system("lsof -ti:#{port} | xargs kill -9 2>/dev/null") sleep 0.2 # Launch Playwright trace viewer on fixed port (headless — no browser open) spawn( "npx playwright show-trace --port #{port} --host 127.0.0.1 #{path}", [:out, :err] => "/dev/null" ) # Wait for server to be ready 5.times do sleep 0.3 break if port_open?(port) end render json: { url: "http://127.0.0.1:#{port}" } end |