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
included, #logger
#inspect
Constructor Details
#initialize(session) ⇒ Storage
Returns a new instance of Storage.
14
15
16
|
# File 'lib/rmega/storage.rb', line 14
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/rmega/storage.rb', line 46
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
42
43
44
|
# File 'lib/rmega/storage.rb', line 42
def nodes=(list)
@nodes = list
end
|
#quota ⇒ Object
38
39
40
|
# File 'lib/rmega/storage.rb', line 38
def quota
session.request(a: 'uq', strg: 1)
end
|
#root ⇒ Object
70
71
72
|
# File 'lib/rmega/storage.rb', line 70
def root
@root ||= nodes.find { |n| n.type == :root }
end
|
#shared ⇒ Object
62
63
64
|
# File 'lib/rmega/storage.rb', line 62
def shared
nodes.select { |node| node.shared_root? }
end
|
#stats ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rmega/storage.rb', line 26
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
22
23
24
|
# File 'lib/rmega/storage.rb', line 22
def total_space
quota['mstrg']
end
|
#trash ⇒ Object
66
67
68
|
# File 'lib/rmega/storage.rb', line 66
def trash
@trash ||= nodes.find { |n| n.type == :trash }
end
|
#used_space ⇒ Object
18
19
20
|
# File 'lib/rmega/storage.rb', line 18
def used_space
quota['cstrg']
end
|