Content Delivery Network (CDN) - optional, for either uploads only or both uploads & extras (rfe 9134)

This commit is contained in:
Randall Schwartz 2009-05-13 21:12:05 +00:00
parent d6696f8a7e
commit acd3fded45
8 changed files with 646 additions and 11 deletions

View file

@ -42,6 +42,28 @@ These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 fromHex ( hexId )
Returns the guid corresponding to hexId. Converse of toHex.
=head3 hexId
Hex value to convert to guid.
=cut
sub fromHex {
my $self = shift;
my $hexId = shift;
my $binId = pack('H2' x 16, unpack('A2' x 16, $hexId));
my $id = substr(encode_base64($binId), 0, 22);
$id =~ tr{+/}{_-};
return $id;
}
#-------------------------------------------------------------------
=head2 DESTROY ( )

View file

@ -131,7 +131,7 @@ sub escape {
=head2 extras ( path )
Combinds the base extrasURL defined in the config file with a specfied path.
Combines the base extrasURL defined in the config file with a specified path.
=head3 path
@ -144,7 +144,20 @@ consecutive slashes in the path part of the URL will be replaced with a single s
sub extras {
my $self = shift;
my $path = shift;
my $url = $self->session->config->get("extrasURL").'/'.$path;
my $url = $self->session->config->get("extrasURL");
my $cdnCfg = $self->session->config->get('cdn');
if ($cdnCfg and $cdnCfg->{'enabled'} and $cdnCfg->{'extrasCdn'}) {
unless ($path and grep $path =~ m/$_/, @{$cdnCfg->{'extrasExclude'}}) {
if ($cdnCfg->{'extrasSsl'} and
($self->session->env->get('HTTPS') eq 'on' or
$self->session->env->get('SSLPROXY'))) {
$url = $cdnCfg->{'extrasSsl'};
} else {
$url = $cdnCfg->{'extrasCdn'};
}
} # if excluded, stick with regular extrasURL
}
$url .= '/' . $path;
$url =~ s$(?<!:)/{2,}$/$g; ##Remove //, unless it's after a :, which can't be a valid URL character
return $url;
}