Merge pull request from ZogStriP/extract-imgur-support-to-a-gem

Extract imgur support to a gem
This commit is contained in:
Sam 2013-06-11 16:59:53 -07:00
commit eb91a0c9df
41 changed files with 199 additions and 75 deletions

View file

@ -69,9 +69,6 @@ class SiteSetting < ActiveRecord::Base
setting(:access_password)
setting(:queue_jobs, !Rails.env.test?)
setting(:crawl_images, !Rails.env.test?)
setting(:enable_imgur, false)
setting(:imgur_client_id, '')
setting(:imgur_endpoint, "https://api.imgur.com/3/image.json")
setting(:max_image_width, 690)
client_setting(:category_featured_topics, 6)
setting(:topics_per_page, 30)

View file

@ -1,6 +1,5 @@
require 'digest/sha1'
require 'image_sizer'
require 'imgur'
require 's3'
require 'local_store'
@ -39,7 +38,6 @@ class Upload < ActiveRecord::Base
end
def self.store_file(file, image_info, upload_id)
return Imgur.store_file(file, image_info, upload_id) if SiteSetting.enable_imgur?
return S3.store_file(file, image_info, upload_id) if SiteSetting.enable_s3_uploads?
return LocalStore.store_file(file, image_info, upload_id)
end

View file

@ -462,10 +462,6 @@ cs:
queue_jobs: "Zařazovat úlohy do fronty v sidekiq, není-li nastaveno, jsou úlohy vyřizovány okamžitě"
crawl_images: "Povolit získávání obrázků z webů třetích stran"
ninja_edit_window: "Jak rychle smíte udělat změnu, aniž by se uložila jako nová verze"
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ů"
imgur_endpoint: "Koncový bod pro upload obrázků na imgur.com"
max_image_width: "Maximální šířka obrázku v příspěvku"
category_featured_topics: "Počet témat zobrazených v seznamu kategorií"
add_rel_nofollow_to_user_content: "Přidávat 'rel nofollow' do uživatelského obsahu, mimo interních odkazů (včetně nadřazené domény) změna tohoto nastavení vyžaduje přegenerování všech MarkDownových textů"

View file

@ -310,9 +310,6 @@ da:
queue_jobs: "Queue various jobs in sidekiq, if false queues are inline"
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
enable_imgur: "Enable imgur api for uploading, don't host files locally"
imgur_api_key: "Your imgur.com api key, required for image upload to function"
imgur_endpoint: "End point for uploading imgur.com images"
max_image_width: "Maximum allowed width of images in a post"
category_featured_topics: "Number of topics displayed per category in the /categories page"
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown"

View file

@ -443,10 +443,6 @@ de:
queue_jobs: "Benutze die Sidekiq-Queue, falls falsche Queues inline sind."
crawl_images: "Lade Bilder von Dritten herunter, um ihre Höhe und Breite zu bestimmen."
ninja_edit_window: "Sekunden nach Empfang eines Beitrag, in denen Bearbeitungen nicht als neue Version gelten."
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."
imgur_endpoint: "Endknoten für das Hochladen von imgur.com-Bildern."
max_image_width: "Maximalbreite von Bildern in einem Beitrag."
category_featured_topics: "Zahl der angezeigten Themen je Kategorie auf der Kategorieseite /categories."
add_rel_nofollow_to_user_content: "Füge mit Ausnahme interner Links allen nutzergenerierten Inhalten 'rel nofollow' hinzu (inkludiert übergeordnete Domains). Die Änderung dieser Einstellung erfordert, dass Du sämtliche Markdown-Beiträge aktualisierst."

View file

@ -447,10 +447,6 @@ en:
queue_jobs: "Queue various jobs in sidekiq, if false queues are inline"
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
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."
imgur_endpoint: "End point for uploading imgur.com images"
max_image_width: "Maximum allowed width of images in a post"
category_featured_topics: "Number of topics displayed per category in the /categories page"
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown (<code>rake posts:rebake</code>)"

View file

@ -298,9 +298,6 @@ es:
queue_jobs: "Encolar varios trabajos en sidekiq, si es falso las colas serán en linea"
crawl_images: "Activar obtener imágenes de origines third party para insertar las dimensiones de ancho y alto"
ninja_edit_window: "Número de segundos after postear donde las ediciones no causan una nueva versión"
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"
max_image_width: "Máximo ancho permitido en las imágenes de un post"
category_featured_topics: "Número de topics mostrados por categoría en la página /categories"
add_rel_nofollow_to_user_content: "Añadir rel nofollow a todo el contenido subido por usuarios, exceptuando los links internos (incluyendo dominios padres) changing this requires you update all your baked markdown"

View file

@ -442,10 +442,6 @@ fr:
queue_jobs: "mettre les différents jobs en attente sur différentes queues, si false les queues sont en file"
crawl_images: "permettre la récupération des images provenant de sources tierces"
ninja_edit_window: "temps d'édition avant de sauvegarder une nouvelle version, en secondes."
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."
imgur_endpoint: "point d'arrêt pour le chargement d'images sur imgur.com"
max_image_width: "largeur maximale des images d'un message"
category_featured_topics: "nombre de discussions affichées dans la liste par catégories"
add_rel_nofollow_to_user_content: "Ajouter rel nofollow à tous les contenus des utilisateurs, sauf les liens internes (incluant les domaines parents) Modifier ceci requiert une mise à jour de tout votre markdown (<code>rake posts:rebake</code>)"

View file

@ -313,9 +313,6 @@ id:
queue_jobs: "Queue various jobs in sidekiq, if false queues are inline"
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
enable_imgur: "Enable imgur api for uploading, don't host files locally"
imgur_api_key: "Your imgur.com api key, required for image upload to function"
imgur_endpoint: "End point for uploading imgur.com images"
max_image_width: "Maximum allowed width of images in a post"
category_featured_topics: "Number of topics displayed per category in the /categories page"
add_rel_nofollow_to_user_content: "Add rel nofollow to all submitted user content, except for internal links (including parent domains) changing this requires you update all your baked markdown"

View file

@ -429,10 +429,6 @@ it:
queue_jobs: "Metti in coda diversi job in sidekiq, se false le code sono inline"
crawl_images: "Abilita la ricezione di immagini da sorgenti terze parti"
ninja_edit_window: "Numero di secondi trascorsi affinché una modifica del post appena inviato, non venga considerata come nuova revisione"
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."
imgur_endpoint: "End point per l'upload di immagini su img.ur"
max_image_width: "Larghezza massima delle immagini in un post"
category_featured_topics: "Numero di topic mostrati per categoira nella pagina /categories"
add_rel_nofollow_to_user_content: "Aggiungi l'attributo rel nofollow a tutti i contenuti degli utenti, tranne per i link interni (compresi i domini di livello superiore). Modificare questa opzione comporta l'aggiornamento di tutto il contenuto markdown salvato"

View file

@ -445,10 +445,6 @@ nl:
queue_jobs: "Zet verschillende taken in een queue binnen sidekiq, bij 'false' worden taken ineens uitgevoerd"
crawl_images: Zet het ophalen van afbeeldingen van externe bronnen aan
ninja_edit_window: "Hoe snel je een aanpassing kan maken zonder dat er een nieuwe versie wordt opgeslagen, in seconden."
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."
imgur_endpoint: "End point voor het uploaden van imgur.com-afbeeldingen"
max_image_width: Maximale breedte voor een afbeelding in een bericht
category_featured_topics: Aantal topics dat wordt weergegeven in de categorielijst
add_rel_nofollow_to_user_content: "Voeg 'rel nofollow' toe aan alle leden-content behalve voor interne links (inclusief parent domeinen). NB: Als je dit verandert, moet je ook alle 'baked markdown' updaten"

View file

@ -491,12 +491,6 @@ pseudo:
ŵíďťĥ áɳď ĥéíǧĥť ďíɱéɳšíóɳš ]]'
ninja_edit_window: '[[ Ѝůɱƀéř óƒ šéčóɳďš áƒťéř ƿóšťíɳǧ ŵĥéřé éďíťš ďó ɳóť čřéáťé
á ɳéŵ νéřšíóɳ ]]'
enable_imgur: '[[ Éɳáƀłé íɱǧůř áƿí ƒóř ůƿłóáďíɳǧ, ďóɳ''ť ĥóšť ƒíłéš łóčáłłý ]]'
imgur_client_id: '[[ Ýóůř íɱǧůř.čóɱ čłíéɳť ÍĎ, řéƣůířéď ƒóř íɱáǧé ůƿłóáď ťó ƒůɳčťíóɳ
]]'
imgur_client_secret: '[[ Ýóůř íɱǧůř.čóɱ čłíéɳť šéčřéť. Ѝóť čůřřéɳťłý řéƣůířéď
ƒóř íɱáǧé ůƿłóáď ťó ƒůɳčťíóɳ, ƀůť ɱáý ƀé áť šóɱé ƿóíɳť. ]]'
imgur_endpoint: '[[ Éɳď ƿóíɳť ƒóř ůƿłóáďíɳǧ íɱǧůř.čóɱ íɱáǧéš ]]'
max_image_width: '[[ Ϻáхíɱůɱ áłłóŵéď ŵíďťĥ óƒ íɱáǧéš íɳ á ƿóšť ]]'
category_featured_topics: '[[ Ѝůɱƀéř óƒ ťóƿíčš ďíšƿłáýéď ƿéř čáťéǧóřý íɳ ťĥé /čáťéǧóříéš
ƿáǧé ]]'

View file

@ -250,9 +250,6 @@ pt:
queue_jobs: "'queue' vários 'jobs' no sidekiq, if false queues are inline"
crawl_images: "permitir mostrar imagens de sites terceiros"
ninja_edit_window: "quão rápido é possivél fazer uma alteração sem guardar uma nova versão, em segundos."
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"
max_image_width: "máxima largura para uma imagem num post"
category_featured_topics: "numero de tópicos mostrados na lista de categorias"
popup_delay: "Espaço de tempo em ms antes dos popus aparecer no ecrã"

View file

@ -352,9 +352,6 @@ sv:
queue_jobs: "Köa diverse jobb i sidekiq, om urkryssat så körs köer infogat"
crawl_images: "Aktivera hämtning av bilder från tredjepartskällor för att infoga bredd och höjd"
ninja_edit_window: "Antal sekunder efter ett inlägg när en ändring inte skapar en ny version"
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"
max_image_width: "Maxbredd för bilder i ett inlägg"
category_featured_topics: "Antal visade trådar per kategori på sidan /categories"
add_rel_nofollow_to_user_content: "Lägg till rel nofollow på allt användargenererat innehåll, förutom interna länkar (inkluderat förälderdomäner) så kräver en ändring av detta att du uppdaterar all bakad markdown"

View file

@ -443,10 +443,6 @@ zh_CN:
queue_jobs: "如果失败队列在排队,使用 Sidekiq 消息引擎对不同的工作排队"
crawl_images: "允许从第三方获取图片来插入宽、高数值"
ninja_edit_window: "在多少秒钟之内,对帖子的多次编辑不生成新版本"
enable_imgur: "启用 Imgur API 来上传文件,不在本地(站点服务器)保存文件"
imgur_client_id: "你的imgur.com的客户端ID以便图片上传能正常工作。"
imgur_client_secret: "你的imgur.com的客户端secret。 目前图片上传功能并不需要这项信息,但是将来的某天可能需要。"
imgur_endpoint: "上传图片到 imgur.com 的终点"
max_image_width: "帖子中图片允许的最大宽度"
category_featured_topics: "在分类 /categories 页面每个分类显示的主题数目"
add_rel_nofollow_to_user_content: "添加 rel nofollow 标签到所有提交的用户信息(以防止搜索引擎搜集),除了内部链接(包括父域名)。修改此设置将要求你更新所有已有的 markdown 标签内容"

View file

@ -429,10 +429,6 @@ zh_TW:
queue_jobs: "如果失敗隊列在排隊,使用 Sidekiq 消息引擎對不同的工作排隊"
crawl_images: "允許從第三方獲取圖片來插入寬、高數值"
ninja_edit_window: "在多少秒鍾之內,對帖子的多次編輯不生成新版本"
enable_imgur: "啓用 Imgur API 來上傳文件,不在本地(站點服務器)保存文件"
imgur_client_id: "你的imgur.com的客戶端ID以便圖片上傳能正常工作。"
imgur_client_secret: "你的imgur.com的客戶端secret。 目前圖片上傳功能並不需要這項信息,但是將來的某天可能需要。"
imgur_endpoint: "上傳圖片到 imgur.com 的終點"
max_image_width: "帖子中圖片允許的最大寬度"
category_featured_topics: "在分類 /categories 頁面每個分類顯示的主題數目"
add_rel_nofollow_to_user_content: "添加 rel nofollow 標簽到所有提交的用戶信息(以防止搜索引擎搜集),除了內部鏈接(包括父域名)。修改此設置將要求你更新所有已有的 markdown 標簽內容"

View file

@ -93,7 +93,7 @@ class CookedPostProcessor
# 7. Optimise images should be a seperate site setting.
# supports only local uploads
return src if SiteSetting.enable_imgur? || SiteSetting.enable_s3_uploads?
return src if SiteSetting.enable_s3_uploads?
width, height = img["width"].to_i, img["height"].to_i

View file

@ -37,16 +37,6 @@ describe Upload do
end
end
context "imgur" do
before(:each) do
SiteSetting.stubs(:enable_imgur?).returns(true)
Imgur.stubs(:store_file).returns(url)
end
it_behaves_like "upload"
end
context "s3" do
before(:each) do
SiteSetting.stubs(:enable_s3_uploads?).returns(true)

13
vendor/gems/discourse_imgur/Gemfile vendored Normal file
View 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
View 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
View file

@ -0,0 +1,3 @@
# DiscourseImgur
Add support for Imgur storage

7
vendor/gems/discourse_imgur/Rakefile vendored Normal file
View 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

View 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

View file

@ -0,0 +1,2 @@
require "discourse_imgur/version"
require 'discourse_imgur/engine' if defined?(Rails) && (!Rails.env.test?)

View 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

View file

@ -1,5 +1,11 @@
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)
@ -11,9 +17,9 @@ module Imgur
blob = file.read
response = RestClient.post(
SiteSetting.imgur_endpoint,
{ image: Base64.encode64(blob) },
{ 'Authorization' => "Client-ID #{SiteSetting.imgur_client_id}" }
SiteSetting.imgur_endpoint,
{ image: Base64.encode64(blob) },
{ 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }
)
json = JSON.parse(response.body)['data'] rescue nil

View 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ů"

View 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."

View 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."

View 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"

View 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."

View 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."

View 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."

View 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"

View 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"

View 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。 目前图片上传功能并不需要这项信息,但是将来的某天可能需要。"

View 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。 目前圖片上傳功能並不需要這項信息,但是將來的某天可能需要。"

View 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

View file

@ -0,0 +1,3 @@
module DiscourseImgur
VERSION = "0.0.1"
end

View file

@ -1,5 +1,10 @@
require 'spec_helper'
require 'imgur'
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
@ -7,9 +12,9 @@ describe Imgur 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' => "Client-ID #{SiteSetting.imgur_client_id}" }] }
let(:params) { [SiteSetting.imgur_endpoint, { image: Base64.encode64(file.read) }, { 'Authorization' => "ClientID #{SiteSetting.imgur_client_id}" }] }
before(:each) do
before(:each) do
SiteSetting.stubs(:imgur_endpoint).returns("imgur_endpoint")
SiteSetting.stubs(:imgur_client_id).returns("imgur_client_id")
end

View 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