add tool to merge pdf files

This commit is contained in:
Alex Turchyn authored and Pete Matsyburka committed 2024-07-12 12:25:14 +03:00
1 parent 286b8d7067
commit ab49af9bcb
3 files changed
+36

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Api
class ToolsController < ApiBaseController
skip_authorization_check
def merge
files = params[:files] || []
return render json: { error: 'Files are required' }, status: :unprocessable_entity if files.blank?
return render json: { error: 'At least 2 files are required' }, status: :unprocessable_entity if files.size < 2
render json: {
data: Base64.encode64(PdfUtils.merge(files.map { |base64| StringIO.new(Base64.decode64(base64)) }).string)
}
end
end
end