nohead 0.18.0 → 0.20.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 +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/lib/nohead/images.rb +27 -3
- data/lib/nohead/resources/assets.rb +2 -2
- data/lib/nohead/uploads.rb +2 -11
- data/lib/nohead/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8bf6d26be7e17af4065b68ec627ad62ebb99635b62ab8b2fa2dcd66e69515c91
|
|
4
|
+
data.tar.gz: 35bb357014e3ae20c267cbf192961f332470624a7c3a39c5415566b50d8b20c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e93e7657f576da5b95f1c46d0c473aff95ee3af4a00b30bd4d6a355cc25e6f320aa2b826e5d80bb148a30accce61ea0fc854722314beffa04e62ebbc4fba4313
|
|
7
|
+
data.tar.gz: 8f52054438991236c977b7c817260fba7379cadff8b2e3ca0aaa904fa344c9eb356b74123400e2aa24737138448aba3dd305e94e7d83cae92317b7aedc1af61b
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ 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.20.0
|
|
9
|
+
|
|
10
|
+
- Nothing changed in the gem: the SDKs share one version, and this release
|
|
11
|
+
matches the TypeScript SDK's 0.20.0, whose reads changed.
|
|
12
|
+
|
|
13
|
+
## 0.19.0
|
|
14
|
+
|
|
15
|
+
- **Breaking:** `Nohead::Images.url` refuses a processing option image URLs
|
|
16
|
+
don't take, naming it, instead of building a URL that answers 404: imgproxy
|
|
17
|
+
Pro's options, such as `sa`, `mc` or `co`, and presets other than
|
|
18
|
+
`pr:preview`. The ones image URLs take are listed in the images guide.
|
|
19
|
+
- Uploads send a content type only when one is given; without it, the API
|
|
20
|
+
types the file by its filename, the same for every client and from a far
|
|
21
|
+
wider list than the SDKs knew (a `.mov` is `video/quicktime` and gets a
|
|
22
|
+
`media_url`). The SDKs' own extension table is gone.
|
|
23
|
+
|
|
8
24
|
## 0.18.0
|
|
9
25
|
|
|
10
26
|
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
|
|
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
|
|
6
|
-
# options written into it transform it
|
|
7
|
-
#
|
|
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,
|
|
25
|
-
|
|
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
|
data/lib/nohead/uploads.rb
CHANGED
|
@@ -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
|
-
|
|
27
|
-
|
|
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
|
|
data/lib/nohead/version.rb
CHANGED