Commit f4893c2c by tady

Merge commit '8c6ad9e0'

parents 1ca84cae 8c6ad9e0
...@@ -123,4 +123,6 @@ gem 'draper', '~> 1.3' ...@@ -123,4 +123,6 @@ gem 'draper', '~> 1.3'
# ActiveRecord versioning # ActiveRecord versioning
gem 'paper_trail', '~> 3.0.0' gem 'paper_trail', '~> 3.0.0'
gem 'aws-sdk'
gem 'newrelic_rpm' gem 'newrelic_rpm'
...@@ -40,6 +40,10 @@ GEM ...@@ -40,6 +40,10 @@ GEM
arel (4.0.2) arel (4.0.2)
ast (1.1.0) ast (1.1.0)
atomic (1.1.15) atomic (1.1.15)
aws-sdk (1.35.0)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
bcrypt (3.1.7) bcrypt (3.1.7)
bcrypt-ruby (3.1.5) bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3) bcrypt (>= 3.1.3)
...@@ -316,7 +320,7 @@ GEM ...@@ -316,7 +320,7 @@ GEM
therubyracer (0.12.1) therubyracer (0.12.1)
libv8 (~> 3.16.14.0) libv8 (~> 3.16.14.0)
ref ref
thin (1.6.1) thin (1.6.2)
daemons (>= 1.0.9) daemons (>= 1.0.9)
eventmachine (>= 1.0.0) eventmachine (>= 1.0.0)
rack (>= 1.0.0) rack (>= 1.0.0)
...@@ -336,6 +340,7 @@ GEM ...@@ -336,6 +340,7 @@ GEM
unf (0.1.3) unf (0.1.3)
unf_ext unf_ext
unf_ext (0.0.6) unf_ext (0.0.6)
uuidtools (2.1.4)
validates_email_format_of (1.5.3) validates_email_format_of (1.5.3)
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
...@@ -350,6 +355,7 @@ PLATFORMS ...@@ -350,6 +355,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
action-gmailer! action-gmailer!
ancestry ancestry
aws-sdk
better_errors better_errors
binding_of_caller binding_of_caller
capistrano (~> 3.1) capistrano (~> 3.1)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
// require jquery // require jquery
//= require jquery_ujs //= require jquery_ujs
// require turbolinks // require turbolinks
//= require ./lib/jquery.ui.widget
//= require_tree ./lib //= require_tree ./lib
//= require_tree . //= require_tree .
......
$.extend
mod_fileuploader: (options) ->
settings =
$input: null,
$textarea: null
settings = $.extend settings, options
settings.$input.fileupload
dataType: 'json'
done: (e, data) ->
$.each data.result.files, (index, _file) ->
settings.$textarea.val(settings.$textarea.val() + "![" + _file.name + "](" + _file.url + ")\n")
settings.$textarea.trigger("change")
# $('<p/>').text(file.name).appendTo('#files') # TODO
progressall: (e, data) ->
progress = parseInt(data.loaded / data.total * 100, 10)
$('.progress-bar').css
width: progress + '%'
settings.$input.prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');
$('<p id="mod-fileuploader-notify"/>').text('ここにドロップしてください').appendTo('body')
$(window).bind 'dragover', (e) ->
console.log('dragover')
$('#mod-fileuploader-notify').show()
# $(window).bind 'dragleave', (e) ->
# console.log('dragleave')
# $('#mod-fileuploader-notify').hide()
$(window).bind 'dragend', (e) ->
console.log('dragend')
$('#mod-fileuploader-notify').hide()
$(window).bind 'drop', (e) ->
console.log('drop')
$('#mod-fileuploader-notify').hide()
...@@ -69,7 +69,7 @@ $.fn.extend ...@@ -69,7 +69,7 @@ $.fn.extend
# TODO # TODO
prettyPrint() prettyPrint()
$('.mod-mdEditor-body').on('keyup mouseup', generatePreview) $('.mod-mdEditor-body').on('keyup mouseup change', generatePreview)
generatePreview() generatePreview()
......
@charset "UTF-8";
/*
* jQuery File Upload Plugin NoScript CSS 1.2.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileinput-button input {
position: static;
opacity: 1;
filter: none;
font-size: inherit;
direction: inherit;
}
.fileinput-button span {
display: none;
}
@charset "UTF-8";
/*
* jQuery File Upload UI Plugin NoScript CSS 8.8.5
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileinput-button i,
.fileupload-buttonbar .delete,
.fileupload-buttonbar .toggle {
display: none;
}
@charset "UTF-8";
/*
* jQuery File Upload UI Plugin CSS 9.0.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileupload-buttonbar .btn,
.fileupload-buttonbar .toggle {
margin-bottom: 5px;
}
.progress-animated .progress-bar,
.progress-animated .bar {
background: url("../img/progressbar.gif") !important;
filter: none;
}
.fileupload-process {
float: right;
display: none;
}
.fileupload-processing .fileupload-process,
.files .processing .preview {
display: block;
width: 32px;
height: 32px;
background: url("../img/loading.gif") center no-repeat;
background-size: contain;
}
.files audio,
.files video {
max-width: 300px;
}
@media (max-width: 767px) {
.fileupload-buttonbar .toggle,
.files .toggle,
.files .btn span {
display: none;
}
.files .name {
width: 80px;
word-wrap: break-word;
}
.files audio,
.files video {
max-width: 80px;
}
.files img,
.files canvas {
max-width: 100%;
}
}
@charset "UTF-8";
/*
* jQuery File Upload Plugin CSS 1.3.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2013, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
.fileinput-button {
position: relative;
overflow: hidden;
}
.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
-ms-filter: 'alpha(opacity=0)';
font-size: 200px;
direction: ltr;
cursor: pointer;
}
/* Fixes for IE < 8 */
@media screen\9 {
.fileinput-button input {
filter: alpha(opacity=0);
font-size: 100%;
height: 100%;
}
}
.mod-fileuploader-box {
margin: 10px;
padding: 10px;
border: dotted 5px #AFEEEE;
background: #F0FFFF;
}
#mod-fileuploader-notify {
opacity:0.5;
margin: 20px;
padding-top: 40%;
font-size: 40px;
text-align: center;
display: none;
width: 100%;
height: 100%;
background: #1E90FF;
color: white;
position: absolute;
top: 0;
left: 0;
}
require 'digest/md5'
class ApisController < ApplicationController class ApisController < ApplicationController
# TODO: not to use # TODO: not to use
...@@ -7,5 +9,27 @@ class ApisController < ApplicationController ...@@ -7,5 +9,27 @@ class ApisController < ApplicationController
# TODO: not to use # TODO: not to use
render text: h_application_format_markdown(params[:text] || '') render text: h_application_format_markdown(params[:text] || '')
end end
end
def file_receiver
s3 = AWS::S3.new
bucket_name = "#{Settings.s3.bucket_name}/1/#{current_user.id}"
# bucket_name = "1/#{current_user.id}"
bucket = s3.buckets[bucket_name]
s3_files = []
params[:files].each do |file|
basename = File.basename(file.path)
object_file_name = "#{Digest::MD5.file(file.path).to_s}#{File.extname(file.original_filename)}"
obj = bucket.objects[object_file_name]
res = obj.write(file: file.path, acl: :public_read)
s3_files << { name: file.original_filename, url: res.public_url.to_s }
end
render json: { status: 'OK', files: s3_files }
end
end
...@@ -14,15 +14,24 @@ ...@@ -14,15 +14,24 @@
<% end %> <% end %>
<div class="row"> <div class="row">
<div class="col-xs-10">
<div class="col-md-10">
<div class="field"> <div class="field">
<div class="input-group"> <div class="input-group">
<span class="input-group-addon"><%= f.label :title %></span> <span class="input-group-addon"><%= f.label :title %></span>
<%= f.text_field :title, class: 'form-control mod-mdEditor-title' %> <%= f.text_field :title, class: 'form-control mod-mdEditor-title' %>
</div> </div>
</div> </div>
</div>
<div class="col-xs-2">
<div class="actions">
<%= f.submit class: 'btn btn-primary js-disable-confirm-unload', id: 'save_button' %>
</div>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-xs-8">
<div class="field"> <div class="field">
<div class="input-group"> <div class="input-group">
<span class="input-group-addon"><%= f.label :tags %></span> <span class="input-group-addon"><%= f.label :tags %></span>
...@@ -32,13 +41,18 @@ ...@@ -32,13 +41,18 @@
</div> </div>
</div> </div>
<div class="col-md-2"> <div class="col-xs-4">
<div class="actions">
<%= f.submit class: 'btn btn-primary js-disable-confirm-unload', id: 'save_button' %> <!--
<div class="mod-fileuploader-box">
<div id="progress" class="progress" style="width: 100%">
<div class="progress-bar progress-bar-success"></div>
</div> </div>
<div id="files" class="files">Uploads file here...</div>
</div> </div>
-->
</div> </div>
</div><!-- /.row -->
<br> <br>
...@@ -68,10 +82,17 @@ ...@@ -68,10 +82,17 @@
<% end %> <% end %>
</div> </div>
<input id="fileupload" type="file" name="files[]" data-url="/apis/file_receiver" multiple style="display:none">
<% content_for :footer_js do %> <% content_for :footer_js do %>
<script type="text/javascript"> <script type="text/javascript">
$.setConfirmUnload(); $.setConfirmUnload();
$('#post-form').mod_mdEditor({end_point: '/apis/markdown_preview'}); $('#post-form').mod_mdEditor({end_point: '/apis/markdown_preview'});
$.mod_fileuploader({
$input: $('#fileupload'),
$textarea: $('.mod-mdEditor-body')
});
</script> </script>
<% end %> <% end %>
{
"Version": "2012-10-17",
"Id": "Rendezvous http referer policy",
"Statement": [
{
"Sid": "Allow get requests referred by rendezvous",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::rendezvous-uploads/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://localhost:3000/*",
"http://rendezvous.*"
]
}
}
},
{
"Sid": "Explicit deny to ensure requests are allowed only from specific referer.",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::rendezvous-uploads/*",
"Condition": {
"StringNotLike": {
"aws:Referer": [
"http://localhost:3000/*",
"http://rendezvous.*"
]
}
}
}
]
}
AWS.config(
access_key_id: Settings.s3.access_key_id,
secret_access_key: Settings.s3.secret_access_key,
s3_endpoint: "s3-ap-northeast-1.amazonaws.com"
)
Rendezvous::Application.routes.draw do Rendezvous::Application.routes.draw do
post 'apis/markdown_preview' post 'apis/markdown_preview'
post 'apis/file_receiver'
root 'home#top', as: 'root' root 'home#top', as: 'root'
......
...@@ -6,6 +6,7 @@ defaults: &defaults ...@@ -6,6 +6,7 @@ defaults: &defaults
google_api: google_api:
client_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com" client_id: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com"
secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
bucket_name: "xxxxxxxxxxxxxx"
development: development:
<<: *defaults <<: *defaults
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment