lib/rmega/storage.rb in rmega-0.1.6 vs lib/rmega/storage.rb in rmega-0.1.7
- old
+ new
@@ -4,10 +4,12 @@
class Storage
include Loggable
attr_reader :session
+ delegate :master_key, :shared_keys, to: :session
+
def initialize(session)
@session = session
end
def used_space
@@ -21,13 +23,15 @@
def quota
session.request(a: 'uq', strg: 1)
end
def nodes
- results = session.request(a: 'f', c: 1)['f']
+ results = session.request(a: 'f', c: 1)
- results.map do |node_data|
+ store_shared_keys(results['ok'] || [])
+
+ (results['f'] || []).map do |node_data|
node = Nodes::Factory.build(session, node_data)
node.process_shared_key if node.shared_root?
node
end
end
@@ -48,8 +52,16 @@
@root ||= nodes.find { |n| n.type == :root }
end
def download(public_url, path)
Nodes::Factory.build_from_url(session, public_url).download(path)
+ end
+
+ private
+
+ def store_shared_keys(list)
+ list.each do |hash|
+ shared_keys[hash['h']] = Crypto.decrypt_key(master_key, Utils.base64_to_a32(hash['k']))
+ end
end
end
end