From 7cd25fe535691b2ca27e31340e8e40dd6798c0d3 Mon Sep 17 00:00:00 2001 From: devender Date: Sat, 21 Nov 2009 04:14:15 -0800 Subject: [PATCH] Attachment_FU also supports serving file with Amazon Cloud Front, when this option is enabled, the public filename will have this pattern http://xxx.cloudfront.net instead of https://s3.amazonaws.com and will break the matcher in the attachment_fu.rb#file_path. This path adds an extra pattern so that both s3 and cloudfront urls will be matched. --- lib/scribd_fu.rb | 1 + lib/scribd_fu/attachment_fu.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/lib/scribd_fu.rb b/lib/scribd_fu.rb index f1dc55c..741fc98 100644 --- a/lib/scribd_fu.rb +++ b/lib/scribd_fu.rb @@ -31,6 +31,7 @@ module ScribdFu # RegExp that matches AWS S3 URLs S3 = /^https?:\/\/s3.amazonaws.com/ + CLOUD_FRONT = /^http:\/\/[A-Za-z0-9]*.cloudfront.net/ # Available parameters for the JS API # http://www.scribd.com/publisher/api/api?method_name=Javascript+API diff --git a/lib/scribd_fu/attachment_fu.rb b/lib/scribd_fu/attachment_fu.rb index babed13..4043c99 100644 --- a/lib/scribd_fu/attachment_fu.rb +++ b/lib/scribd_fu/attachment_fu.rb @@ -22,7 +22,11 @@ module ScribdFu # Yields the correct path to the file, either the local filename or the S3 URL. def file_path - public_filename =~ ScribdFu::S3 ? public_filename : "#{RAILS_ROOT}/public#{public_filename}" + if public_filename =~ ScribdFu::S3 || public_filename =~ ScribdFu::CLOUD_FRONT + public_filename + else + "#{RAILS_ROOT}/public#{public_filename}" + end end end -- 1.6.5.2