mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
666 B
28 lines
666 B
# frozen_string_literal: true
|
|
|
|
class TemplatesDetectFieldsController < ApplicationController
|
|
include ActionController::Live
|
|
|
|
load_and_authorize_resource :template
|
|
|
|
def create
|
|
response.headers['Content-Type'] = 'text/event-stream'
|
|
|
|
sse = SSE.new(response.stream)
|
|
|
|
documents = @template.schema_documents.preload(:blob)
|
|
|
|
documents.each do |document|
|
|
io = StringIO.new(document.download)
|
|
|
|
Templates::DetectFields.call(io, attachment: document) do |(attachment_uuid, page, fields)|
|
|
sse.write({ attachment_uuid:, page:, fields: })
|
|
end
|
|
end
|
|
|
|
sse.write({ completed: true })
|
|
ensure
|
|
response.stream.close
|
|
end
|
|
end
|