mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 19:55:43 +00:00
FIX: fallback to local store when uploads are not on S3
This commit is contained in:
parent
eeda367e70
commit
e17f614771
@ -1,6 +1,7 @@
|
|||||||
require "file_store/base_store"
|
require "file_store/base_store"
|
||||||
require_dependency "s3_helper"
|
require_dependency "s3_helper"
|
||||||
require_dependency "file_helper"
|
require_dependency "file_helper"
|
||||||
|
require_dependency "file_store/local_store"
|
||||||
|
|
||||||
module FileStore
|
module FileStore
|
||||||
|
|
||||||
@ -67,6 +68,13 @@ module FileStore
|
|||||||
@s3_helper.update_tombstone_lifecycle(grace_period)
|
@s3_helper.update_tombstone_lifecycle(grace_period)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path_for(upload)
|
||||||
|
url = upload.url
|
||||||
|
if url && url[0] == "/" && url[1] != "/"
|
||||||
|
FileStore::LocalStore.new.path_for(upload)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_path_for_upload(file, upload)
|
def get_path_for_upload(file, upload)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'file_store/s3_store'
|
require 'file_store/s3_store'
|
||||||
|
require 'file_store/local_store'
|
||||||
|
|
||||||
describe FileStore::S3Store do
|
describe FileStore::S3Store do
|
||||||
|
|
||||||
@ -105,4 +106,23 @@ describe FileStore::S3Store do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".path_for" do
|
||||||
|
|
||||||
|
def assert_path(path, expected)
|
||||||
|
upload = Upload.new(url: path)
|
||||||
|
|
||||||
|
path = store.path_for(upload)
|
||||||
|
expected = FileStore::LocalStore.new.path_for(upload) if expected
|
||||||
|
|
||||||
|
expect(path).to eq(expected)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "correctly falls back to local" do
|
||||||
|
assert_path("/hello", "/hello")
|
||||||
|
assert_path("//hello", nil)
|
||||||
|
assert_path("http://hello", nil)
|
||||||
|
assert_path("https://hello", nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user