mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:56:36 +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.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Onebox
|
|
module Engine
|
|
class PastebinOnebox
|
|
include Engine
|
|
include LayoutSupport
|
|
|
|
MAX_LINES = 10
|
|
|
|
matches_regexp(/^http?:\/\/pastebin\.com/)
|
|
|
|
private
|
|
|
|
def data
|
|
@data ||= {
|
|
title: 'pastebin.com',
|
|
link: link,
|
|
content: content,
|
|
truncated?: truncated?
|
|
}
|
|
end
|
|
|
|
def content
|
|
lines.take(MAX_LINES).join("\n")
|
|
end
|
|
|
|
def truncated?
|
|
lines.size > MAX_LINES
|
|
end
|
|
|
|
def lines
|
|
return @lines if defined?(@lines)
|
|
response = Onebox::Helpers.fetch_response("http://pastebin.com/raw/#{paste_key}", redirect_limit: 1) rescue ""
|
|
@lines = response.split("\n")
|
|
end
|
|
|
|
def paste_key
|
|
regex = case uri
|
|
when /\/raw\//
|
|
/\/raw\/([^\/]+)/
|
|
when /\/download\//
|
|
/\/download\/([^\/]+)/
|
|
when /\/embed\//
|
|
/\/embed\/([^\/]+)/
|
|
else
|
|
/\/([^\/]+)/
|
|
end
|
|
|
|
match = uri.path.match(regex)
|
|
match[1] if match && match[1]
|
|
end
|
|
end
|
|
end
|
|
end
|