🏡 index : github.com/captn3m0/outliner.git

author dhx <dh.tx.dev@dhx.at> 2024-02-22 18:20:20.0 +01:00:00
committer Nemo <me@captnemo.in> 2024-03-07 6:38:05.0 +00:00:00
commit
831e1731707d216d7e29fbf308f2f0e4165ce1d9 [patch]
tree
3934595273b916827ea4fcac0d0898124effc25b
parent
969f704f31bb8c61bf8e8b02356d13e89af580d7
download
831e1731707d216d7e29fbf308f2f0e4165ce1d9.tar.gz

Fixes the exportAll -> export_all outline API change

As until now the client implementation replaced single underscores with a dot
this was not compatible with underscores in the API URIs.
For this reason now double underscores in the method name are replaced with a
dot instead.

Diff

 exe/outliner-export    | 21 ++++++++++++++++++++-
 exe/outliner-import    |  6 +++---
 lib/outliner/client.rb |  7 ++++---
 3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/exe/outliner-export b/exe/outliner-export
index f12f103..20e261b 100755
--- a/exe/outliner-export
+++ a/exe/outliner-export
@@ -20,11 +20,28 @@
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

fop_redirect_response = CLIENT.fileOperations__redirect(id: file_operation_id)


# Extract it to a tempfle
file = Tempfile.new('download.zip')
File.open(file.path, 'w') { |f| f.write(response.body) }
File.open(file.path, 'w') { |f| f.write(fop_redirect_response) }

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

diff --git a/exe/outliner-import b/exe/outliner-import
index b2941a7..85a1b87 100755
--- a/exe/outliner-import
+++ a/exe/outliner-import
@@ -28,7 +28,7 @@
    }

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

@@ -42,7 +42,7 @@
      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
@@ -65,7 +65,7 @@
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
diff --git a/lib/outliner/client.rb b/lib/outliner/client.rb
index ea55969..0882855 100644
--- a/lib/outliner/client.rb
+++ a/lib/outliner/client.rb
@@ -11,17 +11,18 @@
    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('_', '.')
      method_name = '/' + method_name.to_s.sub('__', '.')
      puts method_name
      body = {token: @token}.merge(params).to_json
      options = {
        body: body,