Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
989ec0ee
Commit
989ec0ee
authored
Sep 11, 2011
by
Christoph Lupprich
Committed by
Prem Sichanugrist
Dec 13, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Fog's slow `public_url` access
parent
9574cd00
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
lib/paperclip/storage/fog.rb
+11
-0
test/storage/fog_test.rb
+27
-0
No files found.
lib/paperclip/storage/fog.rb
View file @
989ec0ee
...
@@ -51,6 +51,8 @@ module Paperclip
...
@@ -51,6 +51,8 @@ module Paperclip
end
end
end
end
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
=
/^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
def
exists?
(
style
=
default_style
)
def
exists?
(
style
=
default_style
)
if
original_filename
if
original_filename
!!
directory
.
files
.
head
(
path
(
style
))
!!
directory
.
files
.
head
(
path
(
style
))
...
@@ -126,9 +128,18 @@ module Paperclip
...
@@ -126,9 +128,18 @@ module Paperclip
host
=
(
@options
[
:fog_host
]
=~
/%d/
)
?
@options
[:
fog_host
]
%
(
path
(
style
).
hash
%
4
)
:
@options
[
:fog_host
]
host
=
(
@options
[
:fog_host
]
=~
/%d/
)
?
@options
[:
fog_host
]
%
(
path
(
style
).
hash
%
4
)
:
@options
[
:fog_host
]
"
#{
host
}
/
#{
path
(
style
)
}
"
"
#{
host
}
/
#{
path
(
style
)
}
"
else
else
if
fog_credentials
[
:provider
]
==
'AWS'
if
@options
[
:fog_directory
].
to_s
=~
Fog
::
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
"https://
#{
@options
[
:fog_directory
]
}
.s3.amazonaws.com/
#{
path
(
style
)
}
"
else
# directory is not a valid subdomain, so use path style for access
"https://s3.amazonaws.com/
#{
@options
[
:fog_directory
]
}
/
#{
path
(
style
)
}
"
end
else
directory
.
files
.
new
(
:key
=>
path
(
style
)).
public_url
directory
.
files
.
new
(
:key
=>
path
(
style
)).
public_url
end
end
end
end
end
def
parse_credentials
(
creds
)
def
parse_credentials
(
creds
)
creds
=
find_credentials
(
creds
).
stringify_keys
creds
=
find_credentials
(
creds
).
stringify_keys
...
...
test/storage/fog_test.rb
View file @
989ec0ee
...
@@ -186,6 +186,33 @@ class FogTest < Test::Unit::TestCase
...
@@ -186,6 +186,33 @@ class FogTest < Test::Unit::TestCase
end
end
end
end
context
"with a valid bucket name for a subdomain"
do
should
"provide an url in subdomain style"
do
assert_match
/^https:\/\/papercliptests.s3.amazonaws.com\/avatars\/5k.png\?\d*$/
,
@dummy
.
avatar
.
url
end
end
context
"with an invalid bucket name for a subdomain"
do
setup
do
rebuild_model
(
@options
.
merge
(
:fog_directory
=>
"this_is_invalid"
))
@dummy
=
Dummy
.
new
@dummy
.
avatar
=
@file
@dummy
.
save
end
should
"not match the bucket-subdomain restrictions"
do
invalid_subdomains
=
%w(this_is_invalid in iamareallylongbucketnameiamareallylongbucketnameiamareallylongbu invalid- inval..id inval-.id inval.-id -invalid 192.168.10.2)
invalid_subdomains
.
each
do
|
name
|
assert_no_match
Paperclip
::
Storage
::
Fog
::
AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
,
name
end
end
should
"provide an url in folder style"
do
assert_match
/^https:\/\/s3.amazonaws.com\/this_is_invalid\/avatars\/5k.png\?\d*$/
,
@dummy
.
avatar
.
url
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment