Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions exe/outliner-export
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,30 @@ 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")

raise 'Failed to trigger export_all action' if not response['success']

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

# Extract it to a tempfle
file = Tempfile.new('download.zip')
File.open(file.path, 'w') { |f| f.write(response.body) }
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

`unzip -o "#{file.path}" -d "#{local_directory}"`

# Delete tempfile
file.unlink
6 changes: 3 additions & 3 deletions exe/outliner-import
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id =
}

params[:parentDocumentId] = parent_document_id if parent_document_id
CLIENT.documents_create(params)
CLIENT.documents__create(params)
puts "[-] #{file}"
end

Expand All @@ -42,7 +42,7 @@ def create_documents_recursively(directory, collection_id, parent_document_id =
publish: true,
parentDocumentId: parent_document_id
}
response = CLIENT.documents_create(params)
response = CLIENT.documents__create(params)
create_documents_recursively(dir, collection_id, response['data']['id'])
end
Dir.chdir cwd
Expand All @@ -65,7 +65,7 @@ begin
rescue StandardError? => e
# If we fail, print an error, and delete the collection
puts "[E] Import failed with error: #{e.message}"
CLIENT.collections_delete(id: root_collection_id)
CLIENT.collections__delete(id: root_collection_id)
puts '[E] Deleted collection, please report the issue or retry'
exit 1
end
23 changes: 12 additions & 11 deletions lib/outliner/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@ def initialize(base_uri)
end

def find_or_create_collection(name)
collections = self.collections_list(limit: 100)['data']
collections = self.collections__list(limit: 100)['data']
collections.filter!{|c|c['name'] == name}
if collections.size >= 1
collections[0]['id']
else
self.collections_create(name: name, description: 'Imported Collection')['data']['id']
self.collections__create(name: name, description: 'Imported Collection')['data']['id']
end
end

def method_missing(method_name, params = {})
method_name = '/' + method_name.to_s.sub('_', '.')
body = {token: @token}.merge(params).to_json
def method_missing(method_name, params = {}, options = {})
method_name = "/#{method_name.to_s.sub('__', '.')}"

options = {
body: body,
body: params.to_json,
headers: {
'Accept'=>'application/json',
'Content-Type': 'application/json',
'User-Agent': "Outliner/#{Outliner::VERSION}"
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => "Outliner/#{Outliner::VERSION}",
'Authorization' => "Bearer #{@token}"
},
format: :json
}
format: :json,
}.merge!(options)

self.class.post(method_name, options)
end
Expand Down