breezy_pdf 0.0.15 → 0.0.16

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
  SHA1:
3
- metadata.gz: 57bddc027c8cdfec7911f2cc59222a96c6122f87
4
- data.tar.gz: 98ab1ae786bfa5b1a9f402ff07d2d3bea9268a8d
3
+ metadata.gz: 762863805d9fbb8d35df18758beda176b0d50d4c
4
+ data.tar.gz: f674de70104e792945f1a9482331cf3154875473
5
5
  SHA512:
6
- metadata.gz: 4ac74f57b8b524fa6b2c30c940eef02a791a98602739b82133ab71bff13d3e9999743ad5f48c958b44f6d631e81028197944dec6827ecf03d136ba0df36cbc24
7
- data.tar.gz: 1b2a275727eeac5f202907d89689053762d1e97eea896cad4710ce782770ff291b0ba32c221c9c8123571dd8302339acb5cb51e19b977d7426dd4e3ae0a3d24d
6
+ metadata.gz: 39aff3f2f39f8e685abb5dae0f00dacac3f6bc580c1877e14574200b284636e2ea46f6693b2358540733b6cccf06109b78d91cc14b2c1e543ba0977c251c6b7f
7
+ data.tar.gz: 3cb320f2a666c40d9f526313e9682fcef067252a68c1030792b757cad41ea44109722d0e31c8499b57d8afded7feb9ff427be273283b7a802733f571bc3da142
@@ -7,6 +7,7 @@ module BreezyPDF::HTML
7
7
  @base_url = base_url
8
8
  @html_fragment = html_fragment
9
9
  @log_queue = []
10
+ @upload_ids = []
10
11
  end
11
12
 
12
13
  def public_fragment
@@ -15,6 +16,12 @@ module BreezyPDF::HTML
15
16
  end.to_html
16
17
  end
17
18
 
19
+ def upload_ids
20
+ public_fragment
21
+
22
+ @upload_ids
23
+ end
24
+
18
25
  private
19
26
 
20
27
  def publicize!
@@ -50,9 +57,12 @@ module BreezyPDF::HTML
50
57
  asset_element[attr] = BreezyPDF.asset_cache.fetch(asset_element[attr], expires_in: 601_200) do
51
58
  asset = BreezyPDF::Resources::Asset.new(@base_url, asset_element[attr])
52
59
 
53
- BreezyPDF::Uploads::Base.new(
60
+ upload = BreezyPDF::Uploads::Base.new(
54
61
  asset.filename, asset.content_type, asset.file_path
55
- ).public_url
62
+ )
63
+ @upload_ids.push(upload.id)
64
+
65
+ upload.public_url
56
66
  end
57
67
  end
58
68
  end
@@ -9,5 +9,41 @@ module BreezyPDF::Intercept
9
9
  @app = app
10
10
  @env = env
11
11
  end
12
+
13
+ private
14
+
15
+ def metadata
16
+ {
17
+ "requested_url" => requested_url, "rendered_url" => rendered_url
18
+ }
19
+ end
20
+
21
+ def rendered_url
22
+ "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}" \
23
+ "#{path}#{query_string}"
24
+ end
25
+
26
+ def requested_url
27
+ "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}" \
28
+ "#{env['PATH_INFO']}#{query_string}"
29
+ end
30
+
31
+ def base_url
32
+ "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}"
33
+ end
34
+
35
+ def port
36
+ ":#{env['SERVER_PORT']}" unless [80, 443].include?(env["SERVER_PORT"].to_i)
37
+ end
38
+
39
+ def path
40
+ env["PATH_INFO"].gsub(/\.pdf/, "")
41
+ end
42
+
43
+ def query_string
44
+ return "" if env["QUERY_STRING"].nil?
45
+
46
+ env["QUERY_STRING"] == "" ? "" : "?#{env['QUERY_STRING']}"
47
+ end
12
48
  end
13
49
  end
@@ -7,10 +7,10 @@ module BreezyPDF::Intercept
7
7
  raise BreezyPDF::Intercept::UnRenderable unless (200..299).cover?(status)
8
8
 
9
9
  BreezyPDF.logger.info(
10
- "[BreezyPDF] Requesting render of #{public_url} with metadata: #{html_private_asset.metadata}"
10
+ "[BreezyPDF] Requesting render of #{rendered_url} with metadata: #{metadata}"
11
11
  )
12
12
 
13
- render_request = BreezyPDF::RenderRequest.new(public_url, html_private_asset.metadata).submit
13
+ render_request = BreezyPDF::RenderRequest.new(public_url, metadata).submit
14
14
 
15
15
  BreezyPDF.logger.info("[BreezyPDF] Redirect to pdf at #{render_request.download_url}")
16
16
  [
@@ -27,9 +27,23 @@ module BreezyPDF::Intercept
27
27
  private
28
28
 
29
29
  def public_url
30
- @public_url ||= BreezyPDF::Uploads::Base.new(
30
+ @public_url ||= upload.public_url
31
+ end
32
+
33
+ def metadata
34
+ super.merge(
35
+ "upload_ids" => upload_ids
36
+ ).merge(html_private_asset.metadata)
37
+ end
38
+
39
+ def upload_ids
40
+ [upload.id] + html_private_asset.upload_ids
41
+ end
42
+
43
+ def upload
44
+ @upload ||= BreezyPDF::Uploads::Base.new(
31
45
  html_private_asset.filename, html_private_asset.content_type, html_private_asset.file_path
32
- ).public_url
46
+ )
33
47
  end
34
48
 
35
49
  def html_private_asset
@@ -58,17 +72,5 @@ module BreezyPDF::Intercept
58
72
  hash["PATH_INFO"] = path
59
73
  end
60
74
  end
61
-
62
- def path
63
- env["PATH_INFO"].gsub(/\.pdf/, "")
64
- end
65
-
66
- def base_url
67
- "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}"
68
- end
69
-
70
- def port
71
- ":#{env['SERVER_PORT']}" unless [80, 443].include?(env["SERVER_PORT"].to_i)
72
- end
73
75
  end
74
76
  end
@@ -4,8 +4,8 @@ module BreezyPDF::Intercept
4
4
  # :nodoc
5
5
  class PublicUrl < Base
6
6
  def call
7
- BreezyPDF.logger.info("[BreezyPDF] Requesting render of #{public_url}")
8
- response = BreezyPDF::RenderRequest.new(public_url).submit
7
+ BreezyPDF.logger.info("[BreezyPDF] Requesting render of #{rendered_url}")
8
+ response = BreezyPDF::RenderRequest.new(rendered_url, metadata).submit
9
9
 
10
10
  [
11
11
  302,
@@ -13,26 +13,5 @@ module BreezyPDF::Intercept
13
13
  []
14
14
  ]
15
15
  end
16
-
17
- private
18
-
19
- def public_url
20
- "#{env['rack.url_scheme']}://#{env['SERVER_NAME']}#{port}" \
21
- "#{path}?#{env['QUERY_STRING']}"
22
- end
23
-
24
- def path
25
- path = env["PATH_INFO"]
26
-
27
- BreezyPDF.middleware_path_matchers.each do |regex|
28
- path = path.gsub(regex, "")
29
- end
30
-
31
- path
32
- end
33
-
34
- def port
35
- ":#{env['SERVER_PORT']}" unless [80, 443].include?(env["SERVER_PORT"].to_i)
36
- end
37
16
  end
38
17
  end
@@ -6,6 +6,7 @@ module BreezyPDF::Resources
6
6
  def initialize(base_url, html_fragment)
7
7
  @base_url = base_url
8
8
  @html_fragment = html_fragment
9
+ @upload_ids = []
9
10
  end
10
11
 
11
12
  def content_type
@@ -24,6 +25,12 @@ module BreezyPDF::Resources
24
25
  @metadata ||= BreezyPDF.extract_metadata ? Hash[*meta_tags] : {}
25
26
  end
26
27
 
28
+ def upload_ids
29
+ modified_html_fragment
30
+
31
+ @upload_ids
32
+ end
33
+
27
34
  private
28
35
 
29
36
  def file
@@ -45,9 +52,11 @@ module BreezyPDF::Resources
45
52
  end
46
53
 
47
54
  if BreezyPDF.upload_assets
48
- @html_fragment = BreezyPDF::HTML::Publicize.new(
55
+ publiciser = BreezyPDF::HTML::Publicize.new(
49
56
  @base_url, @html_fragment
50
- ).public_fragment
57
+ )
58
+ @upload_ids = publiciser.upload_ids
59
+ @html_fragment = publiciser.public_fragment
51
60
  end
52
61
 
53
62
  @html_fragment
@@ -18,6 +18,10 @@ module BreezyPDF::Uploads
18
18
  resource.presigned_url
19
19
  end
20
20
 
21
+ def id
22
+ resource.id
23
+ end
24
+
21
25
  private
22
26
 
23
27
  def client
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BreezyPDF
4
- VERSION = "0.0.15"
4
+ VERSION = "0.0.16"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breezy_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Westendorf
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-01 00:00:00.000000000 Z
11
+ date: 2018-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby