sunrise-file-upload 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -22,6 +22,7 @@ module Sunrise
|
|
22
22
|
def create(env)
|
23
23
|
request = Request.new(env)
|
24
24
|
params = request.params.symbolize_keys
|
25
|
+
headers = { 'Content-Type' => 'application/json' }
|
25
26
|
|
26
27
|
asset = find_or_build_asset(params)
|
27
28
|
asset.assetable_type = params[:assetable_type]
|
@@ -32,16 +33,14 @@ module Sunrise
|
|
32
33
|
_run_callbacks(:before_create, env, asset)
|
33
34
|
|
34
35
|
if asset.save
|
35
|
-
body = asset.to_json
|
36
|
-
status = 200
|
37
|
-
|
38
36
|
_run_callbacks(:after_create, env, asset)
|
37
|
+
|
38
|
+
body = asset.to_json
|
39
|
+
[200, headers.merge('Content-Length' => body.size.to_s), [body]]
|
39
40
|
else
|
40
41
|
body = asset.errors.to_json
|
41
|
-
|
42
|
+
[422, headers.merge('Content-Length' => body.size.to_s), [body]]
|
42
43
|
end
|
43
|
-
|
44
|
-
[status, {'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s}, body]
|
45
44
|
end
|
46
45
|
|
47
46
|
def find_or_build_asset(params)
|
@@ -15,7 +15,7 @@ module Sunrise
|
|
15
15
|
|
16
16
|
def body
|
17
17
|
if raw_post = @env['RAW_POST_DATA']
|
18
|
-
raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
|
18
|
+
raw_post = raw_post.force_encoding(Encoding::BINARY) if raw_post.respond_to?(:force_encoding)
|
19
19
|
StringIO.new(raw_post)
|
20
20
|
else
|
21
21
|
@env['rack.input']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunrise-file-upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2012-04-11 00:00:00 Z
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: Sunrise is a Aimbulance CMS
|