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

benwbrum / fromthepage / 24053410501

06 Apr 2026 10:01PM UTC coverage: 71.804% (+0.01%) from 71.79%
24053410501

Pull #5410

github

web-flow
Merge c50e5ffe3 into 28756746f
Pull Request #5410: 5400 - Zero byte bulk export fix part 1

2480 of 3979 branches covered (62.33%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 2 files covered. (75.0%)

19 existing lines in 2 files now uncovered.

10220 of 13708 relevant lines covered (74.56%)

151.81 hits per line

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

95.05
/app/controllers/api/v1/bulk_export_controller.rb
1
module Api::V1
1✔
2
  class BulkExportController < ApplicationController
1✔
3
    before_action :set_api_user
1✔
4
    skip_before_action :verify_authenticity_token
1✔
5

6
    # list your bulk exports
7
    def index
1✔
8
      if @api_user
4✔
9
        collection_slug = params[:collection_slug]
3✔
10
        if collection_slug
3✔
11
          collection = Collection.where(slug: collection_slug).first
2✔
12
          if collection.nil?
2✔
13
            render status: 404, json: "No collection exists with the slug #{collection_slug}"
1✔
14
            return
1✔
15
          end
16
          exports = @api_user.bulk_exports.where(collection_id: collection.id)
1✔
17
        else
1✔
18
          exports = @api_user.bulk_exports
1✔
19
        end
20
        render json: exports.to_json(except: [:updated_at, :user_id, :collection_id], include: { collection: { only: [:title, :slug] } })
2✔
21
      else
1✔
22
        render status: 401, json: 'You must use an API token to access bulk exports'
1✔
23
      end
24
    end
25

26
    def start
1✔
27
      if @api_user
3✔
28
        collection_slug = params[:collection_slug]
2✔
29
        collection = Collection.where(slug: collection_slug).first
2✔
30
        if collection.nil?
2!
31
          render status: 404, json: "No collection exists with the slug #{collection_slug}"
×
32
          return
×
33
        end
34

35
        if collection.show_to?(@api_user)
2✔
36
          # try to parse the bulk_export
1✔
37
          bulk_export = BulkExport.new
1✔
38
          bulk_export.collection = collection
1✔
39
          bulk_export.user = @api_user
1✔
40
          bulk_export.status = :queued
1✔
41
          bulk_export.plaintext_verbatim_page = params[:plaintext_verbatim_page].present?
1✔
42
          bulk_export.plaintext_verbatim_work = params[:plaintext_verbatim_work].present?
1✔
43
          bulk_export.plaintext_emended_page = params[:plaintext_emended_page].present?
1✔
44
          bulk_export.plaintext_emended_work = params[:plaintext_emended_work].present?
1✔
45
          bulk_export.plaintext_searchable_page = params[:plaintext_searchable_page].present?
1✔
46
          bulk_export.plaintext_searchable_work = params[:plaintext_searchable_work].present?
1✔
47
          bulk_export.tei_work = params[:tei_work].present?
1✔
48
          bulk_export.html_page = params[:html_page].present?
1✔
49
          bulk_export.html_work = params[:html_work].present?
1✔
50
          bulk_export.subject_csv_collection = params[:subject_csv_collection].present?
1✔
51
          bulk_export.subject_details_csv_collection = params[:subject_details_csv_collection].present?
1✔
52
          bulk_export.table_csv_collection = params[:table_csv_collection].present?
1✔
53
          bulk_export.table_csv_work = params[:table_csv_work].present?
1✔
54
          bulk_export.notes_csv = params[:notes_csv].present?
1✔
55
          bulk_export.save
1✔
56
          BulkExport::ProcessJob.perform_later(user_id: bulk_export.user.id, bulk_export_id: bulk_export.id)
1✔
57

58
          response = {
59
            id: bulk_export.id,
1✔
60
            status: bulk_export.status,
61
            status_uri: api_v1_bulk_export_status_url(bulk_export.id),
62
            download_uri: api_v1_bulk_export_download_url(bulk_export.id)
63
          }
64

65
          render status: 202, json: response.to_json
1✔
66

67
        else
1✔
68
          render status: 403, json: "User #{@api_user} is not authorized to view #{collection.title}"
1✔
69
        end
70
      else
1✔
71
        render status: 401, json: 'You must use an API token to access bulk exports'
1✔
72
      end
73
    end
74

75
    def status
1✔
76
      if @api_user
3✔
77
        bulk_export_id = params[:bulk_export_id]
2✔
78
        bulk_export = @api_user.bulk_exports.find_by(id: bulk_export_id)
2✔
79

80
        if bulk_export
2✔
81
          response = {
82
            id: bulk_export.id,
1✔
83
            status: bulk_export.status,
84
            status_uri: api_v1_bulk_export_status_url(bulk_export.id),
85
            download_uri: api_v1_bulk_export_download_url(bulk_export.id)
86
          }
87
          render status: 200, json: response.to_json
1✔
88
        else
1✔
89
          render status: 403, json: "User #{@api_user} has no bulk export with ID #{bulk_export_id}"
1✔
90
        end
91
      else
1✔
92
        render status: 401, json: 'You must use an API token to access bulk exports'
1✔
93
      end
94
    end
95

96
    def download
1✔
97
      if @api_user
7✔
98
        bulk_export_id = params[:bulk_export_id]
6✔
99
        bulk_export = @api_user.bulk_exports.find_by(id: bulk_export_id)
6✔
100
        if bulk_export
6✔
101
          case bulk_export.status.to_sym
5✔
102
          when :finished
2✔
103
            if bulk_export.output.attached?
2!
UNCOV
104
              send_data(
×
105
                bulk_export.output.download,
106
                filename: bulk_export.output.filename.to_s,
107
                content_type: bulk_export.output.content_type || 'application/zip'
108
              )
2✔
109
            elsif File.exist?(bulk_export.zip_file_name)
2✔
110
              # TODO: Deprecate
111
              # Keep for now for backsupport
1✔
112
              send_file(
1✔
113
                bulk_export.zip_file_name,
114
                filename: 'fromthepage_export.zip',
115
                content_type: 'application/zip'
116
              )
117
            else
1✔
118
              render status: 410, json: "Bulk export #{bulk_export_id} file has been deleted. Please start a new export."
1✔
119
            end
120
          when :cleaned
1✔
121
            render status: 410, json: "Bulk export #{bulk_export_id} has been deleted.  Please start a new export."
1✔
122
          when :error
1✔
123
            render status: 410, json: "Bulk export #{bulk_export_id} failed with an error.  Please report this to support.  Re-running an export with different requested formats might succeed."
1✔
124
          else
1✔
125
            render status: 409, json: "Bulk export #{bulk_export_id} is not ready to download.  It is probably still running, but might have failed with an un-caught error."
1✔
126
          end
127
        else
1✔
128
          render status: 403, json: "User #{@api_user} has no bulk export with ID #{bulk_export_id}"
1✔
129
        end
130
      else
1✔
131
        render status: 401, json: 'You must use an API token to access bulk exports'
1✔
132
      end
133
    end
134
  end
135
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

© 2026 Coveralls, Inc