From 65ea1c8f3064437f3929539608ba91d013f26c7c Mon Sep 17 00:00:00 2001 From: Dale Hamel Date: Thu, 24 Oct 2024 08:48:30 -0400 Subject: [PATCH] Remove file --- .../base_middleware.rb | 142 ------------------ 1 file changed, 142 deletions(-) delete mode 100644 lib/app_profiler/viewer/speedscope_remote_viewer/base_middleware.rb diff --git a/lib/app_profiler/viewer/speedscope_remote_viewer/base_middleware.rb b/lib/app_profiler/viewer/speedscope_remote_viewer/base_middleware.rb deleted file mode 100644 index 4ee7a28a..00000000 --- a/lib/app_profiler/viewer/speedscope_remote_viewer/base_middleware.rb +++ /dev/null @@ -1,142 +0,0 @@ -# frozen_string_literal: true - -gem "rails-html-sanitizer", ">= 1.6.0" -require "rails-html-sanitizer" - -module AppProfiler - module Viewer - class SpeedscopeRemoteViewer < BaseViewer - class BaseMiddleware - class Sanitizer < Rails::HTML::Sanitizer.best_supported_vendor.safe_list_sanitizer - self.allowed_tags = Set.new([ - "strong", - "em", - "b", - "i", - "p", - "code", - "pre", - "tt", - "samp", - "kbd", - "var", - "sub", - "sup", - "dfn", - "cite", - "big", - "small", - "address", - "hr", - "br", - "div", - "span", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "ul", - "ol", - "li", - "dl", - "dt", - "dd", - "abbr", - "acronym", - "a", - "img", - "blockquote", - "del", - "ins", - "script", - ]) - end - - private_constant(:Sanitizer) - - class << self - def id(file) - file.basename.to_s.delete_suffix(".json") - end - end - - def initialize(app) - @app = app - end - - def call(env) - request = Rack::Request.new(env) - - return index(env) if request.path_info =~ %r(\A/app_profiler/?\z) - return viewer(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/viewer/(.*)\z) - return show(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/(.*)\z) - - @app.call(env) - end - - protected - - def id(file) - self.class.id(file) - end - - def profile_files - AppProfiler.profile_root.glob("**/*.json") - end - - def render(html) - [ - 200, - { "Content-Type" => "text/html" }, - [ - +<<~HTML, - - - - App Profiler - - - #{sanitizer.sanitize(html)} - - - HTML - ], - ] - end - - def sanitizer - @sanitizer ||= Sanitizer.new - end - - def viewer(_env, path) - raise NotImplementedError - end - - def index(_env) - render( - (+"").tap do |content| - content << "

Profiles

" - profile_files.each do |file| - content << <<~HTML -

- - #{id(file)} - -

- HTML - end - end, - ) - end - - def show(env, id) - raise NotImplementedError - end - end - - private_constant(:BaseMiddleware) - end - end -end