Giter VIP home page Giter VIP logo

media_gallery's Introduction

MediaGallery

This gem provides a Rails engine that allows for the storage of images on Amazon S3. Images are organized in galleries. All interactions are done through a simple REST API.

Usage

As this is a Rails engine, you need to mount it in your app. This can be done by modifying your config/routes.rb file. You can add a line like:

mount MediaGallery::Engine => "/media_gallery"

Next, you need to deal with access control. The media_gallery engine uses cancancan for access_control. It does not make any assumptions as to what library or method you use for sign in. It works fine with Devise if that is what you are using. JWT access will also work. You do need to override two methods in the MediaGallery::ApplicationController class. These methods are:

  • current_user: Returns the current user
  • create_ability: Returns an cancan Ability class for use in the media_gallery. It can be your app's defined ability.

The recommended approach for this is to create an initializer. You can check out the one defined in the spec/dummy test app. It defines something like:

MediaGallery::ApplicationController.class_eval do

  def current_user
    User.find_by_token(request.headers['token'])
  end

  def create_ability(user)
    Ability.new(user)
  end
end

You can also look at an example of how this can be done with Devise here.

Lastly, media_gallery uses carrierwave to interact with the S3 storage system. Carrierwave needs to be configured appropriately. The way we do it is through another initializer file (e.g. config/initializers/carrierwave_s3.rb) which defines something like:

class FogSettings

  def self.S3
    {
      :provider               => 'AWS',
      :aws_access_key_id      => ENV['MEDIA_GALLERY_TEST_AWS_PUBLIC'],
      :aws_secret_access_key  => ENV['MEDIA_GALLERY_TEST_AWS_SECRET']
    }
  end

  def self.directory
    ENV['MEDIA_GALLERY_TEST_AWS_DIR']
  end

end

CarrierWave.configure do |config|

  config.fog_credentials = FogSettings.S3
  config.fog_directory   = FogSettings.directory

  #The following is specifically for Heroku.  Heroku only allows you to save data
  #in the tmp folder.  We therefore make sure that the tmp files are put there.
  #See https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
  config.cache_dir = "#{Rails.root}/tmp/uploads"

end

In the previous block, the MEDIA_GALLERY_TEST_AWS... keys are fed from the environment. You can use whatever approach you want. If deploying in Heroku or AWS, it's better to use this approach as your deployed code does not have hardcoded values.

Installation

Add this line to your application's Gemfile:

gem 'media_gallery'

And then execute:

$ bundle

Or install it yourself as:

$ gem install media_gallery

You'll also need to ensure that the associated migrations are run. You can do this with the following:

bin/rails media_gallery:install:migrations
bin/rails db:migrate SCOPE=media_gallery

Contributing

If you want to help out, no problem. The more, the merrier. You can fix issues if you want to or look at the list of outstanding features here.

Make sure that you write unit tests. We presently have model and request specs. The request specs require you to have an AWS account with S3 setup correctly. You then need to define three environment variables:

  • MEDIA_GALLERY_TEST_AWS_PUBLIC
  • MEDIA_GALLERY_TEST_AWS_SECRET
  • MEDIA_GALLERY_TEST_AWS_DIR

The rspecs look for these variables in your environment. On Linux or Mac, you can add something like this to you .bash_profile

export MEDIA_GALLERY_TEST_AWS_PUBLIC=AJEJEKNJE87JS 
export MEDIA_GALLERY_TEST_AWS_SECRET=Bskljfslkdjflksjflkjslls+sljksjlk
export MEDIA_GALLERY_TEST_AWS_DIR=gallery2018

(All values provided in the previous block are fake... obviously :-)

License

The gem is available as open source under the terms of the MIT License.

media_gallery's People

Contributors

mbeauv avatar

Stargazers

 avatar

Watchers

 avatar  avatar

media_gallery's Issues

Limit the size of the uploaded image

At the present time, there is no hard limit to the allowed size of the image to be uploaded. There needs to be a hard limit. It should be configurable through a property. Should also come with a default sensible value.

Setup Travis and CodeClimate

Setup travis and code climate so that builds and coverage reports are generated. As an added bonus it would be nice to have trouble ticketing in github issue setup.

Deletion of non existant gallery returns stack trace

When attempting to delete a non existant gallery, the proper HTTP code is returned (404) but the content of the message itself contains a stack trace. The content should either have nothing or a short descriptive message.

Simplify REST payload of gallery and image info

The gallery and image_info REST response each have two different forms; a partial and full form. The full form being used for get and set operations while the partial is used for index operations. This is not justified by the amount of data that a gallery can contain. One form of the data should be returned.

The gallery should not contain image infos anymore. Those should be obtained through the image_infos resource only.

Provide an install command

Instead of having to copy the migrations manually and then running them. It would be nice to have an install command that would do all of this in one step.

Get invalid ImageInfo returns stack trace

When accessing an ImageInfo that does not exist, 404 is returned but a stack trace is in the message body. This should be either removed or made into a sensible message.

Add gallery code

Gallery code should be unique, have no spaces and be less than 64 characters long.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.