purl_fetcher-client 1.3.0 → 1.4.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: 8acef0951b0c30808be01de74a0be92e5926d8aa749844517cb559df253b9809
|
4
|
+
data.tar.gz: 7bc3b857be71f2ef660956e1b5db1bd9411fc391fefa8b7d52f128a8743a2b34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c87d8d90b38301ca7879cae8d95acf44ea0b4b54a1cf954040cc06f3dc8cc36420757a19f95d7a05b7e4acd77bd46f91e3469ec4aef04ba804833ede2006c2d7
|
7
|
+
data.tar.gz: bd9cadb99c2db016b91627d35b4928bc5e1fc1fecbb204ab82f217ee58a652baa0b593499f0358eaf46bb975fac093bcf745fddbb27b739a01bf522c00d281bb
|
data/Gemfile
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PurlFetcher
|
4
|
+
class Client
|
5
|
+
# Publish (metadata-only) to the purl cache
|
6
|
+
class Publish
|
7
|
+
def self.publish(...)
|
8
|
+
new(...).publish
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [Cocina::Models::DRO,Cocina::Models::Collection] cocina the Cocina data object
|
12
|
+
# @param [Hash<String,String>] file_uploads map of filenames to signed_ids
|
13
|
+
def initialize(cocina:, file_uploads:)
|
14
|
+
@cocina = cocina
|
15
|
+
@file_uploads = file_uploads
|
16
|
+
end
|
17
|
+
|
18
|
+
def publish
|
19
|
+
logger.debug("Starting a publish request for: #{druid}")
|
20
|
+
client.post(path:, body:)
|
21
|
+
logger.debug("Publish request complete")
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :cocina, :file_uploads
|
27
|
+
|
28
|
+
def druid
|
29
|
+
cocina.externalIdentifier
|
30
|
+
end
|
31
|
+
|
32
|
+
def body
|
33
|
+
{
|
34
|
+
object: cocina.to_h,
|
35
|
+
file_uploads: file_uploads
|
36
|
+
}.to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
def logger
|
40
|
+
Client.config.logger
|
41
|
+
end
|
42
|
+
|
43
|
+
def client
|
44
|
+
Client.instance
|
45
|
+
end
|
46
|
+
|
47
|
+
def path
|
48
|
+
"/v1/resources"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PurlFetcher
|
4
|
+
class Client
|
5
|
+
# High-level client for publishing and shelving.
|
6
|
+
class PublishShelve
|
7
|
+
def self.publish_and_shelve(...)
|
8
|
+
new(...).publish_and_shelve
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [Cocina::Models::DRO,Cocina::Models::Collection] cocina the Cocina data object
|
12
|
+
# @param [Hash<String,String>] filepath_map map of relative filepaths to absolute filepaths
|
13
|
+
def initialize(cocina:, filepath_map:)
|
14
|
+
@cocina = cocina
|
15
|
+
@filepath_map = filepath_map
|
16
|
+
end
|
17
|
+
|
18
|
+
def publish_and_shelve
|
19
|
+
logger.debug("Starting publish and shelve for: #{cocina.externalIdentifier}")
|
20
|
+
|
21
|
+
direct_upload_responses = PurlFetcher::Client::UploadFiles.upload(file_metadata: file_metadata, filepath_map: filepath_map)
|
22
|
+
file_uploads = direct_upload_responses.map { |response| [ response.filename, response.signed_id ] }.to_h
|
23
|
+
|
24
|
+
PurlFetcher::Client::Publish.publish(cocina: cocina, file_uploads: file_uploads)
|
25
|
+
logger.debug("Publish and shelve complete")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :cocina, :filepath_map
|
31
|
+
|
32
|
+
def file_metadata
|
33
|
+
cocina.structural.contains.flat_map do |fileset|
|
34
|
+
fileset.structural.contains.select { |file| filepath_map.include?(file.filename) }.map do |file|
|
35
|
+
direct_upload_request_for(file)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def direct_upload_request_for(cocina_file)
|
41
|
+
PurlFetcher::Client::DirectUploadRequest.from_file(
|
42
|
+
hexdigest: md5_for(cocina_file),
|
43
|
+
byte_size: size_for(cocina_file),
|
44
|
+
content_type: "application/octet-stream",
|
45
|
+
file_name: cocina_file.filename
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def md5_for(cocina_file)
|
50
|
+
cocina_file.hasMessageDigests.find { |digest| digest.type == "md5" }.digest
|
51
|
+
end
|
52
|
+
|
53
|
+
def size_for(cocina_file)
|
54
|
+
return cocina_file.size if cocina_file.size.present? && cocina_file.size.positive?
|
55
|
+
|
56
|
+
File.size(filepath_map[cocina_file.filename])
|
57
|
+
end
|
58
|
+
|
59
|
+
def logger
|
60
|
+
Client.config.logger
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -10,7 +10,7 @@ module PurlFetcher
|
|
10
10
|
new(file_metadata: file_metadata, filepath_map: filepath_map).upload
|
11
11
|
end
|
12
12
|
|
13
|
-
# @param [
|
13
|
+
# @param [Array<DirectUploadRequest>] file_metadata array of DirectUploadRequests for the files to be uploaded
|
14
14
|
# @param [Hash<String,String>] filepath_map map of relative filepaths to absolute filepaths
|
15
15
|
def initialize(file_metadata:, filepath_map:)
|
16
16
|
@file_metadata = file_metadata
|
@@ -19,10 +19,10 @@ module PurlFetcher
|
|
19
19
|
|
20
20
|
# @return [Array<DirectUploadResponse>] the responses from the server for the uploads
|
21
21
|
def upload
|
22
|
-
file_metadata.map do |
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
file_metadata.map do |metadata|
|
23
|
+
filepath = metadata.filename
|
24
|
+
# ActiveStorage modifies the filename provided in response, so setting here with the relative filename
|
25
|
+
direct_upload(metadata.to_json).with_filename(filepath).tap do |response|
|
26
26
|
upload_file(response)
|
27
27
|
logger.info("Upload of #{filepath} complete")
|
28
28
|
end
|
data/lib/purl_fetcher/client.rb
CHANGED
@@ -11,8 +11,10 @@ require "purl_fetcher/client/upload_files"
|
|
11
11
|
require "purl_fetcher/client/direct_upload_request"
|
12
12
|
require "purl_fetcher/client/direct_upload_response"
|
13
13
|
require "purl_fetcher/client/legacy_publish"
|
14
|
+
require "purl_fetcher/client/publish"
|
14
15
|
require "purl_fetcher/client/release_tags"
|
15
16
|
require "purl_fetcher/client/unpublish"
|
17
|
+
require "purl_fetcher/client/publish_shelve"
|
16
18
|
|
17
19
|
module PurlFetcher
|
18
20
|
class Client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purl_fetcher-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -130,6 +130,8 @@ files:
|
|
130
130
|
- lib/purl_fetcher/client/direct_upload_response.rb
|
131
131
|
- lib/purl_fetcher/client/legacy_publish.rb
|
132
132
|
- lib/purl_fetcher/client/mods.rb
|
133
|
+
- lib/purl_fetcher/client/publish.rb
|
134
|
+
- lib/purl_fetcher/client/publish_shelve.rb
|
133
135
|
- lib/purl_fetcher/client/reader.rb
|
134
136
|
- lib/purl_fetcher/client/release_tags.rb
|
135
137
|
- lib/purl_fetcher/client/unpublish.rb
|
@@ -154,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
156
|
- !ruby/object:Gem::Version
|
155
157
|
version: '0'
|
156
158
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
159
|
+
rubygems_version: 3.4.19
|
158
160
|
signing_key:
|
159
161
|
specification_version: 4
|
160
162
|
summary: Traject-compatible reader implementation for streaming data from purl-fetcher
|