-
Notifications
You must be signed in to change notification settings - Fork 63
/
s3_uploads_controller.rb
63 lines (56 loc) · 1.92 KB
/
s3_uploads_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class Admin::S3UploadsController < Admin::ApplicationController
# GET /admin/source_files
# GET /admin/source_files.json
def index
if params[:f].present?
source_files = SourceFile.where("LOWER(file_name) LIKE ?", "%#{params[:f]}%".downcase)
else
source_files = SourceFile.limit(3)
end
source_files = source_files.order(created_at: :desc)
respond_to do |format|
format.html { render partial: "table", locals: { source_files: source_files } }
end
end
# POST /admin/source_files
# POST /admin/source_files.json
def create
# this line allows for compatibility with `ProtectedAttributes` or `StrongParameters`
parameters = S3CorsFileupload.active_record_protected_attributes? ? params[:source_file] : params.require(:source_file).permit(:url, :bucket, :key)
@source_file = SourceFile.new(parameters)
respond_to do |format|
if @source_file.save
format.html {
render json: @source_file.to_jq_upload,
content_type: "text/html",
layout: false
}
format.json { render json: @source_file.to_jq_upload, status: :created }
else
format.html { render "new" }
format.json { render json: @source_file.errors, status: :unprocessable_entity }
end
end
end
# DELETE /admin/source_files/1
# DELETE /admin/source_files/1.json
def destroy
@source_file = SourceFile.find(params[:id])
@source_file.destroy
respond_to do |format|
format.html { redirect_to source_files_url }
format.json { head :no_content }
format.xml { head :no_content }
end
end
# used for s3_uploader on the javascript of the upload to gallery section
# for /admin/action_page/new
# GET /admin/source_files/generate_key
def generate_key
uid = SecureRandom.uuid.gsub(/-/, "")
render json: {
key: "uploads/#{uid}/#{params[:filename]}",
success_action_redirect: "/"
}
end
end