mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 06:33:41 +08:00
283b08d45f
* Move onebox gem in core library * Update template file path * Remove warning for onebox gem caching * Remove onebox version file * Remove onebox gem * Add sanitize gem * Require onebox library in lazy-yt plugin * Remove onebox web specific code This code was used in standalone onebox Sinatra application * Merge Discourse specific AllowlistedGenericOnebox engine in core * Fix onebox engine filenames to match class name casing * Move onebox specs from gem into core * DEV: Rename `response` helper to `onebox_response` Fixes a naming collision. * Require rails_helper * Don't use `before/after(:all)` * Whitespace * Remove fakeweb * Remove poor unit tests * DEV: Re-add fakeweb, plugins are using it * Move onebox helpers * Stub Instagram API * FIX: Follow additional redirect status codes (#476) Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses * Remove an empty file * DEV: Update the license file Using the copy from https://choosealicense.com/licenses/gpl-2.0/# Hopefully this will enable GitHub to show the license UI? * DEV: Update embedded copyrights * DEV: Add Onebox copyright notice * DEV: Add MIT license, convert COPYRIGHT.txt to md * DEV: Remove an incorrect copyright claim Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: jbrw <jamie@goatforce5.org>
56 lines
1.2 KiB
Ruby
56 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "openssl"
|
|
require "open-uri"
|
|
require "multi_json"
|
|
require "nokogiri"
|
|
require "mustache"
|
|
require "ostruct"
|
|
require "cgi"
|
|
require "net/http"
|
|
require "digest"
|
|
require "sanitize"
|
|
require_relative "onebox/sanitize_config"
|
|
|
|
module Onebox
|
|
DEFAULTS = {
|
|
connect_timeout: 5,
|
|
timeout: 10,
|
|
max_download_kb: (10 * 1024), # 10MB
|
|
load_paths: [File.join(Rails.root, "lib/onebox/templates")],
|
|
allowed_ports: [80, 443],
|
|
allowed_schemes: ["http", "https"],
|
|
sanitize_config: Sanitize::Config::ONEBOX,
|
|
redirect_limit: 5
|
|
}
|
|
|
|
@@options = DEFAULTS
|
|
|
|
def self.preview(url, options = Onebox.options)
|
|
Preview.new(url, options)
|
|
end
|
|
|
|
def self.check(url, options = Onebox.options)
|
|
StatusCheck.new(url, options)
|
|
end
|
|
|
|
def self.options
|
|
OpenStruct.new(@@options)
|
|
end
|
|
|
|
def self.has_matcher?(url)
|
|
!!Matcher.new(url).oneboxed
|
|
end
|
|
|
|
def self.options=(options)
|
|
@@options = DEFAULTS.merge(options)
|
|
end
|
|
end
|
|
|
|
require_relative "onebox/preview"
|
|
require_relative "onebox/status_check"
|
|
require_relative "onebox/matcher"
|
|
require_relative "onebox/engine"
|
|
require_relative "onebox/layout"
|
|
require_relative "onebox/view"
|