OSDN Git Service

mrg
[pettanr/pettanr.git] / app / controllers / pictures_controller.rb
1 class PicturesController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => []
4     before_filter :authenticate_author, :only => []
5   else
6     before_filter :authenticate_user, :only => []
7     before_filter :authenticate_resource_reader, :only => [:show, :credit, :search]
8     before_filter :authenticate_author, :only => []
9   end
10   before_filter :authenticate_admin, :only => [:index, :by_artist, :count, :count_by_artist]
11   
12   def self.model
13     Picture
14   end
15   
16   def index
17     filer_list
18   end
19   
20   def by_artist
21     filer_list
22   end
23   
24   def show_html_format format
25     format.html {
26       @item.boosts 'post'
27       @picture = @item
28     }
29   end
30   
31   def show
32     set_show
33     respond_to do |format|
34       opt = {:type => @item.mime_type, :disposition=>"inline"}
35       format.png { send_data(@item.restore(params[:subdir]), opt ) }
36       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
37       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
38       show_html_format format
39       show_json_format format
40       show_prof_format format
41     end
42   end
43   
44   def credit
45     @picture = Picture.show(params[:id], @operators)
46
47     respond_to do |format|
48       format.html { render :layout => false }
49       format.json { render :json => @picture.to_json}
50     end
51   end
52   
53   def search
54     @pictures = Picture.list_by_md5(params[:md5])
55     
56     respond_to do |format|
57       format.html
58       format.json { render json: @pictures.to_json }
59     end
60   end
61   
62   def count
63     list_count
64   end
65   
66   def count_by_artist
67     list_count
68   end
69   
70 end