forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdn.rb
More file actions
36 lines (31 loc) · 1000 Bytes
/
Copy pathcdn.rb
File metadata and controls
36 lines (31 loc) · 1000 Bytes
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
module Canvas
module Cdn
class << self
def config
@config ||= begin
config = ActiveSupport::OrderedOptions.new
config.enabled = false
yml = ConfigFile.load('canvas_cdn')
config.merge!(yml.symbolize_keys) if yml
config
end
end
def should_be_in_bucket?(source)
source.start_with?('/dist/brandable_css') || Canvas::Cdn::RevManifest.include?(source)
end
def asset_host_for(source)
return unless config.host # unless you've set a :host in the canvas_cdn.yml file, just serve normally
config.host if should_be_in_bucket?(source)
# Otherwise, return nil & use the same domain the page request came from, like normal.
end
def push_to_s3!(*args, &block)
return unless config.bucket
uploader = Canvas::Cdn::S3Uploader.new(*args)
uploader.upload!(&block)
end
def enabled?
!!config.bucket
end
end
end
end