poto 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +4 -0
  5. data/.travis.yml +3 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Dockerfile +21 -0
  8. data/Gemfile +14 -0
  9. data/LICENSE.txt +21 -0
  10. data/Procfile +1 -0
  11. data/README.md +97 -0
  12. data/Rakefile +10 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/docker-compose.yml +16 -0
  16. data/exe/poto-aws-s3 +29 -0
  17. data/exe/poto-google-cloud-storage +34 -0
  18. data/lib/poto.rb +11 -0
  19. data/lib/poto/api.rb +62 -0
  20. data/lib/poto/app.rb +11 -0
  21. data/lib/poto/ext/open_uri.rb +7 -0
  22. data/lib/poto/file_repository/aws/s3.rb +32 -0
  23. data/lib/poto/file_repository/aws/s3/client.rb +33 -0
  24. data/lib/poto/file_repository/aws/s3/file_collection_mapper.rb +36 -0
  25. data/lib/poto/file_repository/aws/s3/file_mapper.rb +37 -0
  26. data/lib/poto/file_repository/dsl.rb +25 -0
  27. data/lib/poto/file_repository/file.rb +5 -0
  28. data/lib/poto/file_repository/file_collection.rb +5 -0
  29. data/lib/poto/file_repository/google/cloud/storage.rb +34 -0
  30. data/lib/poto/file_repository/google/cloud/storage/file_collection_mapper.rb +37 -0
  31. data/lib/poto/file_repository/google/cloud/storage/file_mapper.rb +39 -0
  32. data/lib/poto/file_repository/proxy.rb +27 -0
  33. data/lib/poto/image_proxy.rb +45 -0
  34. data/lib/poto/representers/file_collection_representer.rb +22 -0
  35. data/lib/poto/representers/file_representer.rb +19 -0
  36. data/lib/poto/services/download.rb +24 -0
  37. data/lib/poto/services/file_cache.rb +28 -0
  38. data/lib/poto/services/resize.rb +23 -0
  39. data/lib/poto/version.rb +3 -0
  40. data/poto.gemspec +40 -0
  41. data/public/ajax-loader.gif +0 -0
  42. data/public/index.html +150 -0
  43. metadata +244 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 472c1f8c3acd53b18e2af01643999923e53059d1
4
+ data.tar.gz: eb24f11c8814efbeac49bb59ed71a9f94a83d102
5
+ SHA512:
6
+ metadata.gz: 5da15c65e22a0ff8d062cb211f6b8a25f783247125bb7bedaf9322b75db414463a77d338c0bc3ea5943c9102159c9cc45de16eda771a198b49bf75224c38ffd1
7
+ data.tar.gz: 287bc5290ccdabe03510be48c6134daebd9977fd7371caab63d340004affeb9eff2997ec97a9ce51b11b5dfc19ddf62f4a9eeab4e1cee0524e80019ca03a579c
@@ -0,0 +1,12 @@
1
+ .DS_Store
2
+ *.json
3
+ /public/cache/
4
+ /.bundle/
5
+ /.yardoc
6
+ /Gemfile.lock
7
+ /_yardoc/
8
+ /coverage/
9
+ /doc/
10
+ /pkg/
11
+ /spec/reports/
12
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Max: 120
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at james.moriarty@rea-group.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
@@ -0,0 +1,21 @@
1
+ FROM ruby:2.3.0-alpine
2
+
3
+ ENV PORT 80
4
+ ENV APP_HOME /app
5
+ ENV AWS_ACCESS_KEY_ID REQUIRED
6
+ ENV AWS_SECRET_ACCESS_KEY REQUIRED
7
+ ENV AWS_REGION REQUIRED
8
+ ENV AWS_S3_BUCKET REQUIRED
9
+
10
+ RUN apk add --no-cache git imagemagick make gcc libc-dev libxml2-dev libxslt-dev libffi-dev yaml-dev openssl-dev zlib-dev readline-dev
11
+
12
+ RUN mkdir $APP_HOME
13
+ WORKDIR $APP_HOME
14
+ COPY poto.gemspec $APP_HOME/poto.gemspec
15
+ COPY Gemfile $APP_HOME/Gemfile
16
+ COPY Gemfile.lock $APP_HOME/Gemfile.lock
17
+ COPY lib/poto/version.rb $APP_HOME/lib/poto/version.rb
18
+ RUN bundle install --jobs $(expr $(cat /proc/cpuinfo | grep processor | wc -l) - 1) --retry 3
19
+ COPY . $APP_HOME
20
+
21
+ CMD exe/poto-aws-s3
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.3.0'
4
+
5
+ gemspec
6
+
7
+ group 'test' do
8
+ gem 'codeclimate-test-reporter'
9
+ gem 'pry'
10
+ gem 'rack-test'
11
+ gem 'rspec'
12
+ gem 'rubocop', require: false
13
+ gem 'simplecov'
14
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 James Moriarty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ web: bundle exec exe/poto-aws-s3
@@ -0,0 +1,97 @@
1
+ [![Code Climate](https://codeclimate.com/github/jamesmoriarty/poto/badges/gpa.svg)](https://codeclimate.com/github/jamesmoriarty/poto) [![Test Coverage](https://codeclimate.com/github/jamesmoriarty/poto/badges/coverage.svg)](https://codeclimate.com/github/jamesmoriarty/poto/coverage) [![Build Status](https://travis-ci.org/jamesmoriarty/poto.svg?branch=master)](https://travis-ci.org/jamesmoriarty/poto)
2
+
3
+ # Poto
4
+
5
+ Turn your AWS S3 bucket into an image gallery.
6
+
7
+ ![Demo GIF](/doc/Demo.gif "Demo GIF")
8
+
9
+ Example: jamesmoriarty-poto-aws-s3
10
+
11
+ ## Poto::ImageProxy
12
+
13
+ The image resizing proxy is rack middleware and can be used standalone.
14
+
15
+ ```ruby
16
+ require "poto"
17
+
18
+ # width - max width in pixels.
19
+ # height - max height in pixels.
20
+ # src - source image url.
21
+ #
22
+ # Examples
23
+ #
24
+ # GET /image_proxy?width=500&height=500&src=https%3A%2F%2Faqueous-cliffs-6127.herokuapp.com%3A443%2Fapi%2Ffiles%2FRGVhdGggVmFsbGV5LmpwZw%3D%3D%250A
25
+
26
+ map("/image_proxy") do
27
+ run Poto::ImageProxy
28
+ end
29
+ ```
30
+
31
+ ## Poto::API
32
+
33
+ As well as the API - query and access the storage backend via hal+json.
34
+
35
+ ```ruby
36
+ require "poto"
37
+ require "poto/file_repository/aws/s3"
38
+
39
+ # Examples
40
+ #
41
+ # GET /files&per_page=9
42
+ # {
43
+ # "_embedded": {
44
+ # "files": [{
45
+ # "name": "Abstract.jpg",
46
+ # "size": 15198281,
47
+ # "_links": {
48
+ # "file": {
49
+ # "href": "https://aqueous-cliffs-6127.herokuapp.com:443/api/files/QWJzdHJhY3QuanBn%0A"
50
+ # }
51
+ # }
52
+ # }]
53
+ # },
54
+ # "_links": {
55
+ # "self": {
56
+ # "href": "https://aqueous-cliffs-6127.herokuapp.com:443/api/files?page="
57
+ # },
58
+ # "next": {
59
+ # "href": "https://aqueous-cliffs-6127.herokuapp.com:443/api/files?page=Death+Valley.jpg&per_page=9"
60
+ # }
61
+ # }
62
+ # }
63
+
64
+ repository = Poto::FileRepository::AWS::S3.new(bucket: ENV["AWS_S3_BUCKET"])
65
+
66
+ map("/api") do
67
+ run Poto::API.configure(repository: repository)
68
+ end
69
+ ```
70
+
71
+ ## Installation
72
+
73
+ $ gem install poto
74
+
75
+ ## Usage
76
+
77
+ ### S3
78
+
79
+ $ PORT=? AWS_ACCESS_KEY_ID=? AWS_SECRET_ACCESS_KEY=? AWS_REGION=? AWS_S3_BUCKET=? poto-aws-s3
80
+
81
+ ### Google Cloud Storage
82
+
83
+ $ PORT=? GOOGLE_CLOUD_PROJECT_ID=? GOOGLE_CLOUD_KEYFILE=? GOOGLE_CLOUD_STORAGE_BUCKET=? poto-google-cloud-storage
84
+
85
+ ## Development
86
+
87
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
88
+
89
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
90
+
91
+ ## Contributing
92
+
93
+ 1. Fork it ( https://github.com/[my-github-username]/poto/fork )
94
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
95
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
96
+ 4. Push to the branch (`git push origin my-new-feature`)
97
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
8
+ rescue LoadError => e
9
+ puts e.message
10
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "poto"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ web:
2
+ build: .
3
+ ports:
4
+ - '9292:9292'
5
+ environment:
6
+ PORT: 9292
7
+
8
+ test:
9
+ build: .
10
+ ports:
11
+ - '9292:9292'
12
+ environment:
13
+ PORT: 9292
14
+ volumes:
15
+ - '.:/app'
16
+ command: bundle exec rspec
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack'
4
+
5
+ app, _options = Rack::Builder.new_from_string <<-EOF
6
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
7
+
8
+ require "poto"
9
+ require "poto/file_repository/aws/s3"
10
+
11
+ repository = Poto::FileRepository::AWS::S3.new(bucket: ENV["AWS_S3_BUCKET"])
12
+
13
+ map("/") do
14
+ run Poto::App
15
+ end
16
+
17
+ map("/image_proxy") do
18
+ run Poto::ImageProxy
19
+ end
20
+
21
+ map("/api") do
22
+ run Poto::API.configure(repository: repository)
23
+ end
24
+ EOF
25
+
26
+ Rack::Server.start(
27
+ app: app,
28
+ Port: ENV.fetch('PORT', 9292)
29
+ )
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack'
4
+
5
+ app, _options = Rack::Builder.new_from_string <<-EOF
6
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
7
+
8
+ require "poto"
9
+ require "poto/file_repository/google/cloud/storage"
10
+
11
+ client = Google::Cloud::Storage.new(
12
+ project: ENV["GOOGLE_CLOUD_PROJECT_ID"],
13
+ keyfile: ENV["GOOGLE_CLOUD_KEYFILE"]
14
+ ).bucket(ENV["GOOGLE_CLOUD_STORAGE_BUCKET"])
15
+
16
+ repository = Poto::FileRepository::Google::Cloud::Storage.new(client: client)
17
+
18
+ map("/") do
19
+ run Poto::App
20
+ end
21
+
22
+ map("/image_proxy") do
23
+ run Poto::ImageProxy
24
+ end
25
+
26
+ map("/api") do
27
+ run Poto::API.configure(repository: repository)
28
+ end
29
+ EOF
30
+
31
+ Rack::Server.start(
32
+ app: app,
33
+ Port: ENV.fetch('PORT', 9292)
34
+ )
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/to_param'
5
+ require 'active_support/core_ext/object/try'
6
+ require 'poto/version'
7
+ require 'poto/api'
8
+ require 'poto/image_proxy'
9
+ require 'poto/app'
10
+
11
+ module Poto; end
@@ -0,0 +1,62 @@
1
+ require 'base64'
2
+ require 'grape'
3
+ require 'grape/roar'
4
+ require 'poto/file_repository/proxy'
5
+ require 'poto/representers/file_representer'
6
+ require 'poto/representers/file_collection_representer'
7
+
8
+ module Poto
9
+ class API < Grape::API
10
+ content_type :json, 'application/hal+json'
11
+ format :json
12
+ formatter :json, Grape::Formatter::Roar
13
+
14
+ resource :files do
15
+ get do
16
+ present global_setting(:proxy).prefix(prefix).page(page).per_page(per_page).all, with: FileCollectionRepresenter
17
+ end
18
+
19
+ route_param :id do
20
+ get do
21
+ redirect global_setting(:proxy).url(id)
22
+ end
23
+ end
24
+ end
25
+
26
+ helpers do
27
+ def url_for(opts, path, query = {})
28
+ request = Grape::Request.new(opts[:env])
29
+
30
+ URI::Generic.build(
31
+ host: request.host,
32
+ port: request.port,
33
+ path: File.join(opts[:env]['SCRIPT_NAME'], path),
34
+ query: query.to_param,
35
+ scheme: request.scheme
36
+ ).to_s.gsub(/\?$/, '')
37
+ end
38
+
39
+ def id
40
+ Base64.urlsafe_decode64(params[:id])
41
+ end
42
+
43
+ def prefix
44
+ params[:prefix]
45
+ end
46
+
47
+ def page
48
+ params[:page]
49
+ end
50
+
51
+ def per_page
52
+ params.fetch(:per_page, 25).to_i
53
+ end
54
+ end
55
+
56
+ def self.configure(repository:)
57
+ global_setting(:proxy, FileRepository::Proxy.new(repository))
58
+
59
+ new
60
+ end
61
+ end
62
+ end