Sha256: 17ef5a38670453688bbec2ec6203e0743a776454f17b3112346e293f60969855

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

module Rmega
  class FolderNode < Node
    def self.create session, parent_node, folder_name
      key = Crypto.random_key
      encrypted_attributes = Utils.a32_to_base64 Crypto.encrypt_attributes(key[0..3], {n: folder_name.strip})
      encrypted_key = Utils.a32_to_base64 Crypto.encrypt_key(session.master_key, key)
      n = [{h: 'xxxxxxxx', t: 1, a: encrypted_attributes, k: encrypted_key}]
      data = session.request a: 'p', t: parent_node.handle, n: n
      new session, data['f'][0]
    end

    def children
      storage.nodes.select { |node| node.parent_handle == handle }
    end

    def download path
      children.each do |node|
        if node.type == :file
          node.download path
        elsif node.type == :folder
          subfolder = File.expand_path File.join(path, node.name)
          Dir.mkdir(subfolder) unless Dir.exists?(subfolder)
          node.download subfolder
        end
      end
      nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rmega-0.0.6 lib/rmega/nodes/folder_node.rb
rmega-0.0.5 lib/rmega/nodes/folder_node.rb
rmega-0.0.4 lib/rmega/nodes/folder_node.rb