This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplugin.rb
74 lines (61 loc) · 1.96 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# name: discourse-azure-blob-storage
# about: Azure Blob storage
# version: 0.0.2
# authors: Maja Komel
# url: https://github.com/discourse/discourse-azure-blob-storage
require "file_store/base_store"
# GEMS
gem 'net-http-persistent', '4.0.1', { require: true, require_name: "net/http/persistent" }
gem 'faraday_middleware', '1.2.0', { require: false }
gem 'azure-storage-common', '2.0.4', { require: false }
gem 'azure-storage-blob', '2.0.3', { require: false }
require 'azure/storage/blob'
enabled_site_setting :azure_blob_storage_enabled
after_initialize do
class ::Faraday::Adapter::NetHttpPersistent
def self.new(*)
self.load_error = nil
super
end
end
SiteSetting::Upload.class_eval do
class << self
alias_method :core_s3_cdn_url, :s3_cdn_url
alias_method :core_enable_s3_uploads, :enable_s3_uploads
alias_method :core_absolute_base_url, :absolute_base_url
alias_method :core_s3_base_url, :s3_base_url
end
def self.s3_cdn_url
if SiteSetting.azure_blob_storage_enabled
SiteSetting.azure_cdn_url
else
core_s3_cdn_url
end
end
def self.enable_s3_uploads
return true if SiteSetting.azure_blob_storage_enabled
core_enable_s3_uploads
end
def self.s3_base_url
return "//#{SiteSetting.azure_blob_storage_account_name}.blob.core.windows.net" if SiteSetting.azure_blob_storage_enabled
core_s3_base_url
end
def self.absolute_base_url
return "//#{SiteSetting.azure_blob_storage_account_name}.blob.core.windows.net" if SiteSetting.azure_blob_storage_enabled
core_absolute_base_url
end
end
Discourse.module_eval do
class << self
alias_method :core_store, :store
end
def self.store
if SiteSetting.azure_blob_storage_enabled
@azure_blob_loaded ||= require './plugins/discourse-azure-blob-storage/lib/azure_blob_store'
FileStore::AzureStore.new
else
core_store
end
end
end
end