OSDN Git Service

t#30124:create md5 dupulicate check
[pettanr/pettanr.git] / app / controllers / pictures_controller.rb
1 class PicturesController < ApplicationController
2   layout 'test' if MagicNumber['test_layout']
3   before_filter :authenticate_user!, :only => [:show, :credit, :search]
4   before_filter :authenticate_author, :only => [:show, :credit, :search]
5   before_filter :authenticate_admin!, :only => [:list, :browse]
6   
7   def show
8     @picture = Picture.show(params[:id], @author)
9
10     respond_to do |format|
11       opt = {:type => @picture.mime_type, :disposition=>"inline"}
12       format.png { send_data(@picture.restore(params[:subdir]), opt ) }
13       format.gif { send_data(@picture.restore(params[:subdir]), opt ) }
14       format.jpeg { send_data(@picture.restore(params[:subdir]), opt ) }
15       format.html 
16       format.json { render :json => @picture.to_json}
17     end
18   end
19   
20   def credit
21     @picture = Picture.show(params[:id], @author)
22
23     respond_to do |format|
24       format.html { render :layout => false } # show.html.erb
25       format.json { render :json => @picture.to_json}
26     end
27   end
28   
29   def search
30     @pictures = Picture.list_by_md5(params[:md5])
31     
32     respond_to do |format|
33       format.html
34       format.json { render json: @pictures.to_json }
35     end
36   end
37   
38   def list
39     @pictures = Picture.all
40
41     respond_to do |format|
42       format.html { render layout: 'system' }# index.html.erb
43       format.json { render json: @pictures }
44     end
45   end
46
47   def browse
48     @picture = Picture.find(params[:id])
49
50     respond_to do |format|
51       format.html { render layout: 'system' } # show.html.erb
52       format.json { render json: @picture }
53     end
54   end
55 end