Class: Rmega::Storage
Instance Attribute Summary collapse
Instance Method Summary
collapse
#powm, #rsa_decrypt
#aes_ctr_cipher, #aes_ctr_decrypt, #aes_ctr_encrypt
#aes_ecb_cipher, #aes_ecb_decrypt, #aes_ecb_encrypt
#aes_cbc_cipher, #aes_cbc_decrypt, #aes_cbc_encrypt, #aes_cbc_mac
Methods included from Loggable
#logger
#inspect
Constructor Details
#initialize(session) ⇒ Storage
Returns a new instance of Storage.
11
12
13
|
# File 'lib/rmega/storage.rb', line 11
def initialize(session)
@session = session
end
|
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
7
8
9
|
# File 'lib/rmega/storage.rb', line 7
def session
@session
end
|
Instance Method Details
#nodes ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rmega/storage.rb', line 43
def nodes
return @nodes if @nodes
results = session.request(a: 'f', c: 1)
(results['ok'] || []).each do |hash|
shared_keys[hash['h']] ||= aes_ecb_decrypt(master_key, Utils.base64urldecode(hash['k']))
end
(results['f'] || []).map do |node_data|
node = Nodes::Factory.build(session, node_data)
node.process_shared_key if node.shared_root?
node
end
end
|
#nodes=(list) ⇒ Object
39
40
41
|
# File 'lib/rmega/storage.rb', line 39
def nodes=(list)
@nodes = list
end
|
#quota ⇒ Object
35
36
37
|
# File 'lib/rmega/storage.rb', line 35
def quota
session.request(a: 'uq', strg: 1)
end
|
#root ⇒ Object
67
68
69
|
# File 'lib/rmega/storage.rb', line 67
def root
@root ||= nodes.find { |n| n.type == :root }
end
|
#shared ⇒ Object
59
60
61
|
# File 'lib/rmega/storage.rb', line 59
def shared
nodes.select { |node| node.shared_root? }
end
|
#stats ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rmega/storage.rb', line 23
def stats
stats_hash = {files: 0, size: 0}
nodes.each do |n|
next unless n.type == :file
stats_hash[:files] += 1
stats_hash[:size] += n.filesize
end
return stats_hash
end
|
#total_space ⇒ Object
19
20
21
|
# File 'lib/rmega/storage.rb', line 19
def total_space
quota['mstrg']
end
|
#trash ⇒ Object
63
64
65
|
# File 'lib/rmega/storage.rb', line 63
def trash
@trash ||= nodes.find { |n| n.type == :trash }
end
|
#used_space ⇒ Object
15
16
17
|
# File 'lib/rmega/storage.rb', line 15
def used_space
quota['cstrg']
end
|