OSDN Git Service

fix: rp update faild
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
1 class ResourcePicturesController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
4     before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
5   else
6     before_action :authenticate_resource_reader, :only => [
7       :index, :show, :credit, 
8       :by_original_picture, :by_license_group, :by_license, :by_artist, :search
9     ]
10     before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
11     before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
12   end
13   
14   def index
15     filer_list
16   end
17   
18   def by_original_picture
19     filer_list param: params[:id]
20   end
21   
22   def by_license_group
23     filer_list param: params[:id]
24   end
25   
26   def by_license
27     filer_list param: params[:id]
28   end
29   
30   def by_artist
31     filer_list param: params[:id]
32   end
33   
34   def show_html_format format
35     format.html {
36       @item.boosts 'post'
37     }
38   end
39   
40   def show
41     set_show
42     respond_to do |format|
43       opt = {:type => @item.mime_type, :disposition=>"inline"}
44       format.png { send_data(@item.restore(params[:subdir]), opt ) }
45       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
46       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
47       show_html_format format
48       show_prof_format format
49       show_json_format format
50     end
51   end
52   
53   def credit
54     @resource_picture = ResourcePicture.show(params[:id], @operators)
55     
56     respond_to do |format|
57       format.html { render :layout => false } # show.html.erb
58     end
59   end
60   
61   def new
62     # use @item, @original_picture
63     respond_to do |format|
64       format.html
65     end
66   end
67   
68   def create
69     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
70     @imager = PettanImager.load @original_picture.restore
71     jsn = nil
72     if params[:json]
73       jsn = JSON.parse_no_except(params[:json])
74     end
75     @item = @original_picture.resource_picture || ResourcePicture.new
76     @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
77       jsn
78     else
79       @item.permit_params(params)
80     end
81     @prm.delete 'id'
82     @item.attributes = @prm
83     @item.overwrite @original_picture
84     @item.boosts 'post'
85     
86     respond_to do |format|
87       if @item.store(@imager)
88         format.html { redirect_to @item }
89         format.json { render json: @item.to_json, status: :created, location: @item }
90       else
91         format.html { render action: "new" }
92         format.json { render json: @item.errors, status: :unprocessable_entity }
93       end
94     end
95   end
96   
97   def destroy
98     set_model
99     @item = @my_model_class.edit(params[:id], @operators)
100     render_destroy_by 'unpublish', '/home/' + @item.path_name
101   end
102   
103   def count
104     @resource_picture = {:count => ResourcePicture.visible_count}
105     respond_to do |format|
106       format.json { render json: @resource_picture.to_json }
107     end
108   end
109   
110   def search
111     @resource_pictures = ResourcePicture.find_by_md5(params[:md5])
112     
113     respond_to do |format|
114       format.html
115       format.json { render json: @resource_pictures.to_json }
116     end
117   end
118   
119 end