mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 08:03:40 +08:00
added untested discourse_imgur plugin
tried to keep as much logic/data from the original source code
This commit is contained in:
parent
8a2d635e62
commit
4db87e4972
13
vendor/gems/discourse_imgur/Gemfile
vendored
Normal file
13
vendor/gems/discourse_imgur/Gemfile
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
group :test do
|
||||
gem 'rails'
|
||||
gem 'rspec'
|
||||
gem 'mocha'
|
||||
end
|
||||
|
||||
# TODO: We need our own gem server
|
||||
gem 'discourse_plugin', path: '../discourse_plugin'
|
||||
|
||||
# Specify your gem's dependencies in rails_multisite.gemspec
|
||||
gemspec
|
22
vendor/gems/discourse_imgur/LICENSE.txt
vendored
Normal file
22
vendor/gems/discourse_imgur/LICENSE.txt
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
Copyright (c) 2013 Régis Hanol
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3
vendor/gems/discourse_imgur/README.md
vendored
Normal file
3
vendor/gems/discourse_imgur/README.md
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# DiscourseImgur
|
||||
|
||||
Add support for Imgur storage
|
7
vendor/gems/discourse_imgur/Rakefile
vendored
Normal file
7
vendor/gems/discourse_imgur/Rakefile
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env rake
|
||||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
RSpec::Core::RakeTask.new(:test) do |spec|
|
||||
spec.pattern = 'spec/*_spec.rb'
|
||||
end
|
23
vendor/gems/discourse_imgur/discourse_imgur.gemspec
vendored
Normal file
23
vendor/gems/discourse_imgur/discourse_imgur.gemspec
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# coding: utf-8
|
||||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'discourse_imgur/version'
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "discourse_imgur"
|
||||
spec.version = DiscourseImgur::VERSION
|
||||
spec.authors = ["Régis Hanol"]
|
||||
spec.email = ["regis@hanol.fr"]
|
||||
spec.description = %q{Add support for Imgur}
|
||||
spec.summary = %q{Add support for Imgur}
|
||||
spec.homepage = ""
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.files = `git ls-files`.split($/)
|
||||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.3"
|
||||
spec.add_development_dependency "rake"
|
||||
end
|
2
vendor/gems/discourse_imgur/lib/discourse_imgur.rb
vendored
Normal file
2
vendor/gems/discourse_imgur/lib/discourse_imgur.rb
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "discourse_imgur/version"
|
||||
require 'discourse_imgur/engine' if defined?(Rails) && (!Rails.env.test?)
|
19
vendor/gems/discourse_imgur/lib/discourse_imgur/engine.rb
vendored
Normal file
19
vendor/gems/discourse_imgur/lib/discourse_imgur/engine.rb
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'discourse_imgur/plugin'
|
||||
|
||||
module DiscourseImgur
|
||||
|
||||
class Engine < Rails::Engine
|
||||
|
||||
engine_name 'discourse_imgur'
|
||||
|
||||
initializer "discourse_imgur.configure_rails_initialization" do |app|
|
||||
|
||||
app.config.after_initialize do
|
||||
DiscoursePluginRegistry.setup(DiscourseImgur::Plugin)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
31
vendor/gems/discourse_imgur/lib/discourse_imgur/imgur.rb
vendored
Normal file
31
vendor/gems/discourse_imgur/lib/discourse_imgur/imgur.rb
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'rest_client'
|
||||
|
||||
# /!\ WARNING /!\
|
||||
# This plugin has been extracted from the Discourse source code and has not been tested.
|
||||
# It really needs some love <3
|
||||
# /!\ WARNING /!\
|
||||
|
||||
|
||||
module Imgur
|
||||
|
||||
def self.store_file(file, image_info, upload_id)
|
||||
raise Discourse::SiteSettingMissing.new("imgur_endpoint") if SiteSetting.imgur_endpoint.blank?
|
||||
raise Discourse::SiteSettingMissing.new("imgur_client_id") if SiteSetting.imgur_client_id.blank?
|
||||
|
||||
@imgur_loaded = require 'imgur' unless @imgur_loaded
|
||||
|
||||
blob = file.read
|
||||
|
||||
response = RestClient.post(
|
||||
SiteSetting.imgur_endpoint,
|
||||
{ image: Base64.encode64(blob) },
|
||||
{ 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
|
||||
)
|
||||
|
||||
json = JSON.parse(response.body)['data'] rescue nil
|
||||
|
||||
return nil if json.blank?
|
||||
return json['link']
|
||||
end
|
||||
|
||||
end
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.cs.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.cs.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
cs:
|
||||
site_settings:
|
||||
enable_imgur: "Používat imgur pro ukládání obrázků, nehostovat obrázky lokálně"
|
||||
imgur_client_id: "Přístupový klíč 'client ID' pro imgur.com - vyžadováno pro upload obrázků"
|
||||
imgur_client_secret: "Přístupový klíč 'client secret' pro imgur.com - vyžadováno pro upload obrázků"
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.de.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.de.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
de:
|
||||
site_settings:
|
||||
enable_imgur: "Aktiviere die Imgur API zum Hochladen, so dass Dateien nicht lokal gehostet werden."
|
||||
imgur_client_id: "Deine imgur.com Client-ID. Wird benötigt, um Bilder hochzuladen."
|
||||
imgur_client_secret: "Dein imgur.com Geheimniss. Wird zur Zeit für das Hochladen der Bilder nicht benötigt, könnte aber in Zukunft benötigt werden."
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.en.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.en.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
en:
|
||||
site_settings:
|
||||
enable_imgur: "Enable imgur api for uploading, don't host files locally"
|
||||
imgur_client_id: "Your imgur.com client ID, required for image upload to function"
|
||||
imgur_client_secret: "Your imgur.com client secret. Not currently required for image upload to function, but may be at some point."
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.es.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.es.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
es:
|
||||
site_settings:
|
||||
enable_imgur: "Activar imgur api para subidas, no almacenes ficheros localmente"
|
||||
imgur_api_key: "Tu imgur.com api key, requerida para la función de subida de imágenes"
|
||||
imgur_endpoint: "End point para la subida de imagenes de imgur.com"
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.fr.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.fr.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
fr:
|
||||
site_settings:
|
||||
enable_imgur: "utiliser l'envoi des images avec l'API imgur, ne pas stocker les fichiers localement"
|
||||
imgur_client_id: "Votre ID client imgur.com. Requis pour que l'envoi d'images fonctionne."
|
||||
imgur_client_secret: "Votre secret imgur.com. Pas nécessaire pour que l'envoi d'image fonctionne, mais pourrais le devenir."
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.it.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.it.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
it:
|
||||
site_settings:
|
||||
enable_imgur: "Utilizza le api imgur per l'upload, non salvare file in locale"
|
||||
imgur_client_id: "Your imgur.com client ID, required for image upload to function"
|
||||
imgur_client_secret: "Your imgur.com client secret. Not currently required for image upload to function, but may be at some point."
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.nl.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.nl.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
nl:
|
||||
site_settings:
|
||||
enable_imgur: "Gebruik de imgur API voor uploads en sla afbeeldingen niet lokaal op"
|
||||
imgur_client_id: "Je imgur.com client ID, nodig om afbeeldingen te kunnen uploaden naar imgur"
|
||||
imgur_client_secret: "Je imgur.com client secret. Is nog niet nodig voor het uploaden van afbeeldingen, maar dat zou in de toekomst kunnen veranderen."
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.pt.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.pt.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
pt:
|
||||
site_settings:
|
||||
enable_imgur: "permitir imgur api para uploading, não guardar ficheiros localmente"
|
||||
imgur_api_key: "chave para imgur.com api - necessária para image upload"
|
||||
imgur_endpoint: "end point para uploading imgur.com images"
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.sv.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.sv.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
sv:
|
||||
site_settings:
|
||||
enable_imgur: "Aktivera imgur.coms API för uppladdning, sparar inte filer lokalt"
|
||||
imgur_api_key: "Din API-nyckel för imgur.com, krävs för att bilduppladdningen ska funka"
|
||||
imgur_endpoint: "Ändpunkt för uppladdning av bilder till imgur.com"
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.zh_CN.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.zh_CN.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
zs_CN:
|
||||
site_settings:
|
||||
enable_imgur: "启用 Imgur API 来上传文件,不在本地(站点服务器)保存文件"
|
||||
imgur_client_id: "你的imgur.com的客户端ID,以便图片上传能正常工作。"
|
||||
imgur_client_secret: "你的imgur.com的客户端secret。 目前图片上传功能并不需要这项信息,但是将来的某天可能需要。"
|
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.zh_TW.yml
vendored
Normal file
5
vendor/gems/discourse_imgur/lib/discourse_imgur/locale/server.zh_TW.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
zh_TW:
|
||||
site_settings:
|
||||
enable_imgur: "啓用 Imgur API 來上傳文件,不在本地(站點服務器)保存文件"
|
||||
imgur_client_id: "你的imgur.com的客戶端ID,以便圖片上傳能正常工作。"
|
||||
imgur_client_secret: "你的imgur.com的客戶端secret。 目前圖片上傳功能並不需要這項信息,但是將來的某天可能需要。"
|
23
vendor/gems/discourse_imgur/lib/discourse_imgur/plugin.rb
vendored
Normal file
23
vendor/gems/discourse_imgur/lib/discourse_imgur/plugin.rb
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'discourse_plugin'
|
||||
|
||||
# /!\ WARNING /!\
|
||||
# This plugin has been extracted from the Discourse source code and has not been tested.
|
||||
# It really needs some love <3
|
||||
# /!\ WARNING /!\
|
||||
|
||||
module DiscourseImgur
|
||||
|
||||
class Plugin < DiscoursePlugin
|
||||
|
||||
def setup
|
||||
# add_setting(:enable_imgur, false)
|
||||
# add_setting(:imgur_client_id, '')
|
||||
# add_setting(:imgur_endpoint, "https://api.imgur.com/3/image.json")
|
||||
|
||||
# TODO: Mix the following logic in Upload#store_file
|
||||
# return Imgur.store_file(file, image_info, upload_id) if SiteSetting.enable_imgur?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
3
vendor/gems/discourse_imgur/lib/discourse_imgur/version.rb
vendored
Normal file
3
vendor/gems/discourse_imgur/lib/discourse_imgur/version.rb
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
module DiscourseImgur
|
||||
VERSION = "0.0.1"
|
||||
end
|
55
vendor/gems/discourse_imgur/spec/imgur_spec.rb
vendored
Normal file
55
vendor/gems/discourse_imgur/spec/imgur_spec.rb
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
require 'spec_helper'
|
||||
require 'discourse_imgur/imgur'
|
||||
|
||||
# /!\ WARNING /!\
|
||||
# This plugin has been extracted from the Discourse source code and has not been tested.
|
||||
# It really needs some love <3
|
||||
# /!\ WARNING /!\
|
||||
|
||||
describe Imgur do
|
||||
|
||||
describe "store_file" do
|
||||
|
||||
let(:file) { Rails.root.join('app', 'assets', 'images', 'logo.png') }
|
||||
let(:image_info) { FastImage.new(file) }
|
||||
let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }] }
|
||||
|
||||
before(:each) do
|
||||
SiteSetting.stubs(:imgur_endpoint).returns("imgur_endpoint")
|
||||
SiteSetting.stubs(:imgur_client_id).returns("imgur_client_id")
|
||||
end
|
||||
|
||||
it 'returns the url of the Imgur upload if successful' do
|
||||
json = {
|
||||
data: {
|
||||
id: 'fake',
|
||||
link: 'http://imgur.com/fake.png',
|
||||
deletehash: 'a3kaoad30'
|
||||
},
|
||||
success: true,
|
||||
status: 200
|
||||
}.to_json
|
||||
|
||||
response = mock
|
||||
response.expects(:body).returns(json)
|
||||
RestClient.expects(:post).with(*params).returns(response)
|
||||
|
||||
Imgur.store_file(file, image_info, 1).should == 'http://imgur.com/fake.png'
|
||||
end
|
||||
|
||||
it 'returns nil if the request fails' do
|
||||
json = {
|
||||
success: false,
|
||||
status: 400
|
||||
}.to_json
|
||||
|
||||
response = mock
|
||||
response.expects(:body).returns(json)
|
||||
RestClient.expects(:post).with(*params).returns(response)
|
||||
|
||||
Imgur.store_file(file, image_info, 1).should be_nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
11
vendor/gems/discourse_imgur/spec/spec_helper.rb
vendored
Normal file
11
vendor/gems/discourse_imgur/spec/spec_helper.rb
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'rubygems'
|
||||
require 'rails'
|
||||
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
||||
config.mock_framework = :mocha
|
||||
config.color_enabled = true
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user