<h1>
<%= t 'original_pictures.show.history' %>
</h1>
- <%= render 'history_list', :history => @item.history %>
+ <%= render 'history_list', :history => OriginalPicture.find_history(@item.id) %>
</td>
</tr>
</table>
y = YAML.load(open(Rails.root + 'config/picture_io.yml').read)
require y[Rails.env]["adapter"]
pio = PictureIO.const_get y[Rails.env]["io"]
+host_dir = y[Rails.env]["host_dir"]
PictureIO.setup do |config|
- config.original_picture_io = pio.new y[Rails.env]["original_picture"]
- config.resource_picture_io = pio.new y[Rails.env]["resource_picture"]
- config.picture_io = pio.new y[Rails.env]["picture"]
- config.system_picture_io = pio.new y[Rails.env]["system_picture"]
+ config.original_picture_io = pio.new host_dir, y[Rails.env]["original_picture"]
+ config.resource_picture_io = pio.new host_dir, y[Rails.env]["resource_picture"]
+ config.picture_io = pio.new host_dir, y[Rails.env]["picture"]
+ config.system_picture_io = pio.new host_dir, y[Rails.env]["system_picture"]
end
module ActiveRecord
class Forbidden < ActiveRecordError
+++ /dev/null
-Aws.config.update(
- region: Rails.application.secrets.aws_region,
- credentials: Aws::Credentials.new(
- Rails.application.secrets.aws_access_key_id,
- Rails.application.secrets.aws_secret_access_key
- )
-)
-#require 'aws/s3'
-#AWS::S3::Base.establish_connection!(
-# :access_key_id => Rails.application.secrets.aws_access_key_id,
-# :secret_access_key => Rails.application.secrets.aws_secret_access_key,
-#)
-#AWS::S3::DEFAULT_HOST = "us-east-1.amazonaws.com"
-# :s3_endpoint => "us-east-1.amazonaws.com"
development:
adapter: local_picture
io: LocalPicture
- original_picture: /pettanr/dev/o/
- resource_picture: /pettanr/dev/r/
- picture: /temp/p/p/
- system_picture: /pettanr/dev/s/
+ host_dir: /pettanr/dev/
+ original_picture: o
+ resource_picture: r
+ picture: p
+ system_picture: s
test:
adapter: local_picture
io: LocalPicture
- original_picture: /pettanr/test/o/
- resource_picture: /pettanr/test/r/
- picture: /temp/p/tp/
- system_picture: /pettanr/test/s/
+ host_dir: /pettanr/test/
+ original_picture: o
+ resource_picture: r
+ picture: p
+ system_picture: s
production:
adapter: s3_picture
io: S3Picture
- original_picture: pettan/o/
- resource_picture: pettan/r/
- picture: pettan/p/
- system_picture: pettan/s/
+ host_dir: pettanr
+ original_picture: o
+ resource_picture: r
+ picture: p
+ system_picture: s
require 'picture_io'
class PictureIO
class LocalPicture
- def initialize base_dir = Rails.root + 'public/images/'
- @base = base_dir
+ def initialize host_dir = Rails.root + 'public/images/', base_dir = ''
+ @host_dir = host_dir
+ @base_dir = @host_dir + base_dir
end
- def base
- @base
+ def host_dir
+ @host_dir
end
- def base=(b)
- @base = b
+ def host_dir=(d)
+ @host_dir = d
+ end
+
+ def base_dir
+ @base_dir
+ end
+
+ def base_dir=(d)
+ @base_dir = d
end
def dir(subdir = nil)
sd = if subdir.to_s.empty?
- self.base
+ ''
else
- self.base + (subdir.to_s + '/')
+ subdir.to_s + '/'
end
- sd
+ @base_dir + '/' + sd
end
def mkdir subdir = nil
- Dir.mkdir(base) unless File.exist?(base)
+ Dir.mkdir(base_dir) unless File.exist?(base_dir)
return if subdir.to_s.empty?
Dir.mkdir(dir(subdir)) unless File.exist?(dir(subdir))
end
require 'picture_io'
class PictureIO
+ Aws.config.update(
+ region: Rails.application.secrets.aws_region,
+ credentials: Aws::Credentials.new(
+ Rails.application.secrets.aws_access_key_id,
+ Rails.application.secrets.aws_secret_access_key
+ )
+ )
class S3Picture
@@client = Aws::S3::Client.new
- def initialize base_dir = 'pettanr'
- @base = base_dir
+ def initialize host_dir = 'pettanr', base_dir = ''
+ @host_dir = host_dir
+ @base_dir = base_dir
+ s3 = Aws::S3::Resource.new
+ @bucket = s3.bucket(@host_dir)
end
- def base
- @base
+ def self.client
+ @@client
end
- def base=(b)
- @base = b
+ def bucket
+ @bucket
+ end
+
+ def host_dir
+ @host_dir
+ end
+
+ def host_dir=(d)
+ @host_dir = d
end
def self.subdirs
def exist?(filename, subdir = nil)
res = true
begin
- res = @@client.get_object(bucket: self.base, key: dir(subdir) + filename).exist?
+ res = self.bucket.object(dir(subdir) + filename).exists?
rescue
raise PictureIO::Error
end
def put(bindata, filename, subdir = nil)
res = true
begin
- @@client.put_object(bucket: self.base, key: dir(subdir) + filename, body: bindata)
+ @@client.put_object(bucket: self.host_dir, key: dir(subdir) + filename, body: bindata)
rescue
raise PictureIO::Error
end
def get(filename, subdir = nil)
bindata = ''
begin
- @@client.get_object(bucket: self.base, key: dir(subdir) + filename) do |st|
+ @@client.get_object(bucket: self.host_dir, key: dir(subdir) + filename) do |st|
bindata += st if st
end
rescue
def delete(filename, subdir = nil)
res = true
begin
- @@client.delete_object(bucket: self.base, key: dir(subdir) + filename)
+ @@client.delete_object(bucket: self.host_dir, key: dir(subdir) + filename)
rescue
raise PictureIO::Error
end