exe/outliner-export in outliner-1.0.0 vs exe/outliner-export in outliner-1.0.2
- old
+ new
@@ -18,15 +18,32 @@
# Setup variables
local_directory = ARGV[0]
CLIENT = Outliner::Client.new ENV['OUTLINE_BASE_URI']
# Download the complete zip
-response = CLIENT.collections_exportAll(download: true)
+response = CLIENT.collections__export_all(format: "outline-markdown")
-# Extract it to a tempfle
-file = Tempfile.new('download.zip')
-File.open(file.path, 'w') { |f| f.write(response.body) }
+raise 'Failed to trigger export_all action' if not response['success']
-`unzip -o "#{file.path}" -d "#{local_directory}"`
+file_operation_id = response['data']['fileOperation']['id']
+fop_info_response = nil
+i = 0
+loop do
+ i += 1
+ raise 'Timed out waiting for the file export operation to complete' if i > 20
+ sleep(2*i)
+ fop_info_response = CLIENT.fileOperations__info(id: file_operation_id)
+ raise 'Failed to query export file operation info' if not fop_info_response['ok']
+ break if fop_info_response['data']['state'] == 'complete'
+end
-# Delete tempfile
-file.unlink
+begin
+ fop_redirect_response = CLIENT.fileOperations__redirect({id: file_operation_id}, {no_follow: true})
+rescue HTTParty::RedirectionTooDeep => e
+ response = HTTParty.get e.response.header['location']
+ file = Tempfile.new('download.zip')
+ File.open(file.path, 'w') { |f| f.write(response.body) }
+ `unzip -o "#{file.path}" -d "#{local_directory}"`
+ file.unlink
+end
+
+