active_storage-postgresql 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54615a42c7d40b923de16cd796ef44094dc02f97b85a0318fad194bc363737c8
|
4
|
+
data.tar.gz: 67382dfacc875240ce388c3a4ce32ef2863b26db95333e5a4ec490a5e287f5f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37b819a10d64ecdaac09ac73be1eb397b004d3bc327f2e07c9a27a7b688147517682bb1582701d77dfc28f6c5c135caebcd3a4001a9284ff0c6cf4d08e306b9a
|
7
|
+
data.tar.gz: f918504c8219915866da43b1ca40032133bd723085d5adb16c2e40e43c8ae2986fff687913d4434b481e53026b0e9b4b6ae46b80336e1a8cfde935a5f6a0f00f
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Serves files stored with the disk service in the same way that the cloud services do.
|
4
|
+
# This means using expiring, signed URLs that are meant for immediate access, not permanent linking.
|
5
|
+
# Always go through the BlobsController, or your own authenticated controller, rather than directly
|
6
|
+
# to the service url.
|
7
|
+
|
8
|
+
class ActiveStorage::PostgresqlController < ActiveStorage::BaseController
|
9
|
+
|
10
|
+
skip_forgery_protection
|
11
|
+
|
12
|
+
def show
|
13
|
+
if key = decode_verified_key
|
14
|
+
response.headers["Content-Type"] = params[:content_type] || DEFAULT_SEND_FILE_TYPE
|
15
|
+
response.headers["Content-Disposition"] = params[:disposition] || DEFAULT_SEND_FILE_DISPOSITION
|
16
|
+
size = ActiveStorage::PostgreSQL::File.open(key[:key], &:size)
|
17
|
+
|
18
|
+
ranges = Rack::Utils.get_byte_ranges(request.get_header('HTTP_RANGE'), size)
|
19
|
+
|
20
|
+
if ranges.nil? || ranges.length > 1
|
21
|
+
# # No ranges, or multiple ranges (which we don't support):
|
22
|
+
# # TODO: Support multiple byte-ranges
|
23
|
+
self.status = :ok
|
24
|
+
range = 0..size-1
|
25
|
+
|
26
|
+
elsif ranges.empty?
|
27
|
+
head 416, content_range: "bytes */#{size}"
|
28
|
+
return
|
29
|
+
else
|
30
|
+
range = ranges[0]
|
31
|
+
self.status = :partial_content
|
32
|
+
response.headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{size}"
|
33
|
+
end
|
34
|
+
self.response_body = postgresql_service.download_chunk(key[:key], range)
|
35
|
+
else
|
36
|
+
head :not_found
|
37
|
+
end
|
38
|
+
rescue ActiveRecord::RecordNotFound
|
39
|
+
head :not_found
|
40
|
+
end
|
41
|
+
|
42
|
+
def update
|
43
|
+
if token = decode_verified_token
|
44
|
+
if acceptable_content?(token)
|
45
|
+
postgresql_service.upload token[:key], request.body, checksum: token[:checksum]
|
46
|
+
head :no_content
|
47
|
+
else
|
48
|
+
head :unprocessable_entity
|
49
|
+
end
|
50
|
+
else
|
51
|
+
head :not_found
|
52
|
+
end
|
53
|
+
rescue ActiveStorage::IntegrityError
|
54
|
+
head :unprocessable_entity
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def postgresql_service
|
59
|
+
ActiveStorage::Blob.service
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def decode_verified_key
|
64
|
+
ActiveStorage.verifier.verified(params[:encoded_key], purpose: :blob_key)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def decode_verified_token
|
69
|
+
ActiveStorage.verifier.verified(params[:encoded_token], purpose: :blob_token)
|
70
|
+
end
|
71
|
+
|
72
|
+
def acceptable_content?(token)
|
73
|
+
token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length
|
74
|
+
end
|
75
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rails.application.routes.draw do
|
4
|
+
get "/rails/active_storage/postgresql/:encoded_key/*filename" => "active_storage/postgresql#show", as: :rails_postgresql_service
|
5
|
+
put "/rails/active_storage/postgresql/:encoded_token" => "active_storage/postgresql#update", as: :update_rails_postgresql_service
|
6
|
+
end
|
@@ -75,7 +75,7 @@ module ActiveStorage
|
|
75
75
|
purpose: :blob_key }
|
76
76
|
)
|
77
77
|
|
78
|
-
generated_url = url_helpers.
|
78
|
+
generated_url = url_helpers.rails_postgresql_service_url(verified_key_with_expiration,
|
79
79
|
host: current_host,
|
80
80
|
disposition: content_disposition,
|
81
81
|
content_type: content_type,
|
@@ -100,7 +100,7 @@ module ActiveStorage
|
|
100
100
|
purpose: :blob_token }
|
101
101
|
)
|
102
102
|
|
103
|
-
generated_url = url_helpers.
|
103
|
+
generated_url = url_helpers.update_rails_postgresql_service_url(verified_token_with_expiration, host: current_host)
|
104
104
|
|
105
105
|
payload[:url] = generated_url
|
106
106
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lachlan Sylvester
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -76,6 +76,8 @@ files:
|
|
76
76
|
- MIT-LICENSE
|
77
77
|
- README.md
|
78
78
|
- Rakefile
|
79
|
+
- app/controllers/active_storage/postgresql_controller.rb
|
80
|
+
- config/routes.rb
|
79
81
|
- db/migrate/20180530020601_create_active_storage_postgresql_tables.rb
|
80
82
|
- lib/active_storage/postgresql.rb
|
81
83
|
- lib/active_storage/postgresql/engine.rb
|
@@ -103,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
105
|
- !ruby/object:Gem::Version
|
104
106
|
version: '0'
|
105
107
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.7.6
|
108
|
+
rubygems_version: 3.0.1
|
108
109
|
signing_key:
|
109
110
|
specification_version: 4
|
110
111
|
summary: PostgreSQL Adapter for Active Storage
|