drive 0.30.0 → 0.31.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 +9 -0
- data/README.md +2 -1
- data/app/controllers/concerns/direct_files.rb +31 -0
- data/app/models/telex_file/sent.rb +39 -0
- data/lib/drive/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 91bbb721abecd32a5846ef916693c4d2205f79695776b559451149c24d8e0793
|
|
4
|
+
data.tar.gz: 4111f75e459236214c506c39c3fd926c0e493f58e8812134763eb31949b619f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01f7852de364895e170ae9f0b54c7d4944560e162328fd5600293ce444a4a7446824e628dec0279c54607a9e6f7f8bf3753d5d9bf323ff4ee13742c1c14bb780
|
|
7
|
+
data.tar.gz: f57e2cf187323107f402d9869ddf1f0345707da5c155340d0e4c0144caa60bf99415ae0a6b02101fb0b4352795d4f04d354783855dbba08b2195968a9460368f
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ For more information about changelogs, check [Keep a Changelog](http://keepachan
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## 0.31.0 - 2026-11-20
|
|
10
|
+
|
|
11
|
+
* [FEATURE] `DirectFiles`: a controller concern where a browser sends a file straight to storage
|
|
12
|
+
(easyfaa's `easy/direct`), recorded only for a kind `TelexFile` takes (or one the browser doesn't
|
|
13
|
+
name) up to `TelexFile::LARGEST`; an app taking other kinds names them in `direct_types`. Moved
|
|
14
|
+
from hangar's `Annual::DirectFilesController`
|
|
15
|
+
* [FEATURE] `TelexFile::Sent`: a file a browser sent, or one it sent straight to storage by its
|
|
16
|
+
signed id, kept as Telex reads it (`blob`), or refused saying why (`refusal`)
|
|
17
|
+
|
|
9
18
|
## 0.30.0 - 2026-11-20
|
|
10
19
|
|
|
11
20
|
* [FEATURE] `TelexReading`: what Telex read of a file an app sent it (`telex.readings`), included
|
data/README.md
CHANGED
|
@@ -17,7 +17,8 @@ gem's.
|
|
|
17
17
|
number, as every app reads them.
|
|
18
18
|
- **`TelexReading`**: what Telex read of a file the app sent it, included in the app's own
|
|
19
19
|
`Telex::Reading`, which sees its own requests' readings alone. **`TelexFile`**: a file kept as
|
|
20
|
-
Telex reads it, an iPhone's HEIC made an upright JPEG
|
|
20
|
+
Telex reads it, an iPhone's HEIC made an upright JPEG, sent through Rails or straight to storage
|
|
21
|
+
(**`DirectFiles`**, **`TelexFile::Sent`**).
|
|
21
22
|
|
|
22
23
|
## How to install
|
|
23
24
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Where a browser sends a file straight to storage, never through the web dyno (easyfaa's easy/direct): one Telex reads
|
|
2
|
+
# or a photo made one (TelexFile::TAKEN), or one of a kind the browser doesn't name, to be told by its bytes once it's
|
|
3
|
+
# kept (TelexFile::Sent); no larger than TelexFile::LARGEST. Rails only records it, and hands back where to send it; the
|
|
4
|
+
# app keeps it by its signed id. An app taking other kinds too (a ZIP) names them in `direct_types`.
|
|
5
|
+
module DirectFiles
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
include ActiveStorage::SetCurrent
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# The file's record and where to send it, or a refusal for one too large or of a kind not taken.
|
|
13
|
+
def create
|
|
14
|
+
args = params.expect(blob: %i[filename byte_size checksum content_type]).to_h.symbolize_keys
|
|
15
|
+
if args[:byte_size].to_i > TelexFile::LARGEST || direct_types.exclude?(args[:content_type].to_s)
|
|
16
|
+
head :unprocessable_content
|
|
17
|
+
else
|
|
18
|
+
render json: recorded(ActiveStorage::Blob.create_before_direct_upload!(**args))
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def recorded(blob)
|
|
25
|
+
upload = { url: blob.service_url_for_direct_upload, headers: blob.service_headers_for_direct_upload }
|
|
26
|
+
blob.as_json(root: false, methods: :signed_id).merge(direct_upload: upload)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# The kinds a browser may send straight: those TelexFile takes, and one it doesn't name ('').
|
|
30
|
+
def direct_types = TelexFile::TAKEN + ['']
|
|
31
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module TelexFile
|
|
2
|
+
# A file a browser sent, or one it sent straight to storage (DirectFiles) by its signed id, kept as Telex reads it
|
|
3
|
+
# (TelexFile): where it is already (a PDF or a PNG sent straight), or a new blob in its place, the one sent purged.
|
|
4
|
+
class Sent
|
|
5
|
+
# @param sent [ActionDispatch::Http::UploadedFile, String] the file, or the signed id of its blob.
|
|
6
|
+
def initialize(sent)
|
|
7
|
+
@blob = ActiveStorage::Blob.find_signed!(sent) if sent.is_a?(String)
|
|
8
|
+
@file = sent unless @blob
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Its name, as sent.
|
|
12
|
+
def name = @blob ? @blob.filename.to_s : @file.original_filename
|
|
13
|
+
|
|
14
|
+
# Why it's refused, or nil: too large, or neither a PDF nor a photo. One refused that was sent straight is purged.
|
|
15
|
+
def refusal
|
|
16
|
+
said = if size > TelexFile::LARGEST then "#{name} is over 20 MB"
|
|
17
|
+
elsif !TelexFile.type(bytes) then "#{name} isn’t a PDF or a photo"
|
|
18
|
+
end
|
|
19
|
+
@blob&.purge if said
|
|
20
|
+
said
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# The blob it's kept as.
|
|
24
|
+
def blob
|
|
25
|
+
data, content_type, filename = TelexFile.readable(bytes, name)
|
|
26
|
+
if @blob && data.equal?(bytes)
|
|
27
|
+
@blob
|
|
28
|
+
else
|
|
29
|
+
ActiveStorage::Blob.create_and_upload!(io: StringIO.new(data), filename:, content_type:).tap { @blob&.purge }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def size = @blob ? @blob.byte_size : @file.size
|
|
36
|
+
|
|
37
|
+
def bytes = @bytes ||= @blob ? @blob.download : @file.read
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/drive/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: drive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.31.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- claudiob
|
|
@@ -34,6 +34,7 @@ files:
|
|
|
34
34
|
- CHANGELOG.md
|
|
35
35
|
- MIT-LICENSE
|
|
36
36
|
- README.md
|
|
37
|
+
- app/controllers/concerns/direct_files.rb
|
|
37
38
|
- app/controllers/concerns/rate_limited.rb
|
|
38
39
|
- app/models/crawler.rb
|
|
39
40
|
- app/models/designation.rb
|
|
@@ -58,6 +59,7 @@ files:
|
|
|
58
59
|
- app/models/refined/sheet.rb
|
|
59
60
|
- app/models/serial.rb
|
|
60
61
|
- app/models/telex_file.rb
|
|
62
|
+
- app/models/telex_file/sent.rb
|
|
61
63
|
- app/models/telex_reading.rb
|
|
62
64
|
- config/inspection.yml
|
|
63
65
|
- lib/drive.rb
|