nohead 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c47346fafd2f22120096868642dbd192089c2719109ed1471d2995105693ab42
4
- data.tar.gz: f34bd6582faa6320d02a0795f6f69e4e87ccf845b6e40481a5cd74cf8cb38a6d
3
+ metadata.gz: 564e9f4b757eec6826687c29b021e9045b2198c15b1420fe17c027bbd3324bdb
4
+ data.tar.gz: 4be7b71c43ef14a94761b4ff9cf0f5479fbf7e03f67b629e76b091c7f3cec045
5
5
  SHA512:
6
- metadata.gz: 435292a1b8bf84c1cca84a5d405b47c2c2a6e959aa37b032e3736867836964a3c80b65528e9aadbc7df825b4384c4f8447232792130b04b5baa86d1a810408e9
7
- data.tar.gz: fb29f37f21e5772107f1799b02db6a1721b9e6b107b5281b237c853381c4185a97bab05c5b8cc5d805fcfcffd4ea3ca875a87afc5177e33116138a8dda0b6b09
6
+ metadata.gz: fa80370e240382cbc8c5dedd9ea5b52d34c2c59dd5291f3703059f5da2378aab2bdaafdca774a35dad4275facdb7127100a5b6bb94d6a7f973b4b62b0130a3b4
7
+ data.tar.gz: 413152171394e8faeda54da5f640dbee3cca5b1fe29733f37e0725762b67fb3132168c5b64135516e410a7b7b7431e9c708f959058b19ff24f2f8c2848953e08
data/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ Changes to the `nohead` gem that you can notice. Versions follow
5
5
  releases; a change that could break your code is a major one. Each release's
6
6
  section is its GitHub release's notes.
7
7
 
8
+ ## 0.19.0
9
+
10
+ - **Breaking:** `Nohead::Images.url` refuses a processing option image URLs
11
+ don't take, naming it, instead of building a URL that answers 404: imgproxy
12
+ Pro's options, such as `sa`, `mc` or `co`, and presets other than
13
+ `pr:preview`. The ones image URLs take are listed in the images guide.
14
+ - Uploads send a content type only when one is given; without it, the API
15
+ types the file by its filename, the same for every client and from a far
16
+ wider list than the SDKs knew (a `.mov` is `video/quicktime` and gets a
17
+ `media_url`). The SDKs' own extension table is gone.
18
+
8
19
  ## 0.18.0
9
20
 
10
21
  No changes in this SDK: the SDKs keep one version, and this release moves the
data/README.md CHANGED
@@ -243,7 +243,7 @@ asset = nohead.assets.upload("cover.jpg", alt: "The harbour at dawn") # alt: is
243
243
  nohead.records.update(id, data: { cover: asset.id })
244
244
  ```
245
245
 
246
- **Images.** Image URLs are open: an image's `image_url` serves the whole image, and any of [imgproxy's processing options](https://docs.imgproxy.net/usage/processing) written into it transform it. `Nohead::Images.url` builds them without a request:
246
+ **Images.** Image URLs are open: an image's `image_url` serves the whole image, and [imgproxy's processing options](https://docs.imgproxy.net/usage/processing) written into it transform it: the open-source ones, [listed in the docs](https://docs.nohead.io/guides/images#supported-options). Any other, such as imgproxy Pro's `sa` (saturation), would answer 404, so `Nohead::Images.url` refuses it, naming the option. It builds them without a request:
247
247
 
248
248
  ```ruby
249
249
  Nohead::Images.url(asset, width: 1200, height: 630, fit: "cover", gravity: "sm", format: "webp")
data/lib/nohead/images.rb CHANGED
@@ -2,14 +2,26 @@
2
2
 
3
3
  module Nohead
4
4
  # Image renditions without a request. Image URLs are open: an image asset's
5
- # `image_url` serves the whole image, and any of imgproxy's processing
6
- # options written into it transform it
7
- # (https://docs.imgproxy.net/usage/processing).
5
+ # `image_url` serves the whole image, and imgproxy's open-source processing
6
+ # options written into it transform it (listed at
7
+ # https://docs.nohead.io/guides/images#supported-options). Any other, such as
8
+ # imgproxy Pro's `sa`, `mc` or `co`, would answer 404, so `url` refuses it.
8
9
  #
9
10
  # Nohead::Images.url(asset, width: 800, height: 600, fit: "cover", format: "webp")
10
11
  module Images
11
12
  FITS = { "contain" => "fit", "cover" => "fill", "fill" => "force" }.freeze
12
13
 
14
+ # The processing options image URLs take, by short and long name.
15
+ SUPPORTED = %w[
16
+ rs resize s size rt resizing_type w width h height mw min-width mh min-height
17
+ z zoom dpr el enlarge ex extend exar extend_aspect_ratio extend_ar g gravity c crop
18
+ t trim pd padding ar auto_rotate rot rotate fl flip bg background bl blur
19
+ sh sharpen pix pixelate q quality fq format_quality f format ext
20
+ kcr keep_copyright scp strip_color_profile ph preserve_hdr
21
+ eth enforce_thumbnail cb cachebuster exp expires fn filename
22
+ att return_attachment pr preset
23
+ ].to_set.freeze
24
+
13
25
  module_function
14
26
 
15
27
  # A rendition of an image (an asset, as an object or a Hash, or its `image_url`). fit: "contain"
@@ -23,6 +35,7 @@ module Nohead
23
35
  options = [*options].reject { |option| option.to_s.empty? }
24
36
  base = base_of(image)
25
37
  check_options([gravity, *options])
38
+ options.each { |option| check_supported(option.to_s) }
26
39
  at = base.index("/plain/")
27
40
  dpr = number(dpr)
28
41
  quality = number(quality)
@@ -68,6 +81,17 @@ module Nohead
68
81
  end
69
82
  private_class_method :check_options
70
83
 
84
+ # Refuses an option image URLs don't take, naming it. The only preset is preview_url's.
85
+ def check_supported(option)
86
+ name, args = option.split(":", 2)
87
+ preset = %w[pr preset].include?(name) && args != "preview"
88
+ return if SUPPORTED.include?(name) && !preset
89
+
90
+ raise ArgumentError, "#{preset ? option : name} isn't an option Nohead image URLs take (imgproxy Pro's, " \
91
+ "such as sa, mc or co, aren't available): https://docs.nohead.io/guides/images#supported-options"
92
+ end
93
+ private_class_method :check_supported
94
+
71
95
  # The source comes last; a format replaces any the URL already names.
72
96
  def source(source, format)
73
97
  format ? "#{source.sub(/@[a-z]+\z/, '')}@#{format}" : source
@@ -21,8 +21,8 @@ module Nohead
21
21
  source = UploadSource.new(file, filename: filename, content_type: content_type,
22
22
  byte_size: byte_size)
23
23
  begin
24
- created = create_upload(filename: source.filename, content_type: source.content_type,
25
- byte_size: source.byte_size, **{ alt: alt }.compact,
24
+ created = create_upload(filename: source.filename, byte_size: source.byte_size,
25
+ **{ content_type: source.content_type, alt: alt }.compact,
26
26
  idempotency_key: idempotency_key)
27
27
  # A replayed start returns the first run's asset, which may be done.
28
28
  if idempotency_key
@@ -6,15 +6,6 @@ module Nohead
6
6
  # Reading files for assets.upload: a path (String or Pathname) or an IO
7
7
  # opened in binary mode (File, StringIO).
8
8
  class UploadSource
9
- CONTENT_TYPES = {
10
- ".avif" => "image/avif", ".gif" => "image/gif", ".jpeg" => "image/jpeg",
11
- ".jpg" => "image/jpeg", ".png" => "image/png", ".svg" => "image/svg+xml",
12
- ".webp" => "image/webp", ".pdf" => "application/pdf", ".json" => "application/json",
13
- ".txt" => "text/plain", ".md" => "text/markdown", ".csv" => "text/csv",
14
- ".mp3" => "audio/mpeg", ".mp4" => "video/mp4", ".webm" => "video/webm",
15
- ".zip" => "application/zip"
16
- }.freeze
17
-
18
9
  attr_reader :filename, :content_type, :byte_size, :io
19
10
 
20
11
  def initialize(file, filename: nil, content_type: nil, byte_size: nil)
@@ -23,8 +14,8 @@ module Nohead
23
14
  @filename = present(filename) || present(name) || "upload"
24
15
  @byte_size = byte_size || size or
25
16
  raise UploadError, "Uploading a stream that cannot seek needs byte_size:"
26
- @content_type = present(content_type) ||
27
- CONTENT_TYPES.fetch(File.extname(@filename).downcase, "application/octet-stream")
17
+ # Without one, the API types the file by its filename, as for every client.
18
+ @content_type = present(content_type)
28
19
  @start = position(@io)
29
20
  end
30
21
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nohead
4
- VERSION = "0.18.0"
4
+ VERSION = "0.19.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nohead
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nohead