• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 9cd1579d-9684-4b66-ae83-9619a7d64644

pending completion
9cd1579d-9684-4b66-ae83-9619a7d64644

Pull #1094

circleci

GitHub
Merge branch 'main' into sidekiq-prod
Pull Request #1094: Adding redis and sidekiq

1628 of 2126 relevant lines covered (76.58%)

97.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.09
/app/models/s3_file.rb
1
# frozen_string_literal: true
2
class S3File
1✔
3
  include Rails.application.routes.url_helpers
1✔
4

5
  attr_accessor :safe_id, :filename, :last_modified, :size, :checksum, :url, :filename_display, :last_modified_display
1✔
6
  alias key filename
1✔
7
  alias id filename
1✔
8

9
  def initialize(filename:, last_modified:, size:, checksum:, work:)
1✔
10
    @safe_id = filename_as_id(filename)
53✔
11
    @filename = filename
53✔
12
    @filename_display = filename_short(work, filename)
53✔
13
    @last_modified = last_modified
53✔
14
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
53✔
15
    @size = size
53✔
16
    @checksum = checksum.delete('"')
53✔
17
    @url = work_download_path(work, filename: filename)
53✔
18
    @work = work
53✔
19
  end
20

21
  def created_at
1✔
22
    last_modified
13✔
23
  end
24

25
  def byte_size
1✔
26
    size
×
27
  end
28

29
  def globus_url
1✔
30
    encoded_filename = filename.split("/").map { |name| ERB::Util.url_encode(name) }.join("/")
45✔
31
    File.join(Rails.configuration.globus["post_curation_base_url"], encoded_filename)
9✔
32
  end
33

34
  def to_blob
1✔
35
    existing_blob = ActiveStorage::Blob.find_by(key: filename)
×
36

37
    if existing_blob.present?
×
38
      Rails.logger.warn("There is a blob existing for #{filename}, which we are not expecting!  It will be reattached #{existing_blob.inspect}")
×
39
      return existing_blob
×
40
    end
41

42
    params = { filename: filename, content_type: "", byte_size: size, checksum: checksum }
×
43
    blob = ActiveStorage::Blob.create_before_direct_upload!(**params)
×
44
    blob.key = filename
×
45
    blob
×
46
  end
47

48
  # Create a new snapshot of the current upload
49
  # @return [UploadSnapshot]
50
  def create_snapshot
1✔
51
    created = UploadSnapshot.create(uri: url, work: @work)
×
52
    created.upload = self
×
53
    created
×
54
  end
55

56
  private
1✔
57

58
    # Filename without the DOI/work-id/ in the path (but we preserve other path information if there is any)
59
    def filename_short(work, filename)
1✔
60
      prefix = "#{work.doi}/#{work.id}/"
53✔
61
      if filename.start_with?(prefix)
53✔
62
        filename[prefix.length..]
35✔
63
      else
64
        filename
18✔
65
      end
66
    end
67

68
    def filename_as_id(filename)
1✔
69
      # The full filename and path but only with alphanumeric characters
70
      # everything else becomes as dash.
71
      filename.gsub(/[^A-Za-z\d]/, "-")
53✔
72
    end
73
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc