Class: Alchemy::Custom::Model::ElFinder::Volumes::Base

Inherits:
Object
  • Object
show all
Includes:
TranslationScope
Defined in:
lib/alchemy/custom/model/el_finder/volumes/base.rb

Direct Known Subclasses

AlchemyFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TranslationScope

#acm_t

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 10

def initialize(options)
  [:id, :name, :root, :url].each do |opt|
    raise(ArgumentError, "Missing required #{opt} option") unless options.key?(opt)
  end

  @id = options[:id]
  @name = options[:name]
  @root = options[:root]
  @url = options[:url]

  # @options = {
  #   upload_file_mode: 0644,
  #   original_filename_method: lambda {|file| file.original_filename.respond_to?(:force_encoding) ? file.original_filename.force_encoding('utf-8') : file.original_filename}
  # }
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 8

def name
  @name
end

#rootObject (readonly)

Returns the value of attribute root.



8
9
10
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 8

def root
  @root
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 8

def url
  @url
end

Instance Method Details

#contains?(hash) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 26

def contains?(hash)
  hash.start_with?("#{@id}_")
end

#cwd(target = '.') ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 30

def cwd(target = '.')
#       {
#     "name"   : "Images",             // (String) name of file/dir. Required
#     "hash"   : "l0_SW1hZ2Vz",        // (String) hash of current file/dir path, first symbol must be letter, symbols before _underline_ - volume id, Required.
#     "phash"  : "l0_Lw",              // (String) hash of parent directory. Required except roots dirs.
#     "mime"   : "directory",          // (String) mime type. Required.
#     "ts"     : 1334163643,           // (Number) file modification time in unix timestamp. Required.
#     "date"   : "30 Jan 2010 14:25",  // (String) last modification time (mime). Depricated but yet supported. Use ts instead.
#     "size"   : 12345,                // (Number) file size in bytes
#     "dirs"   : 1,                    // (Number) Only for directories. Marks if directory has child directories inside it. 0 (or not set) - no, 1 - yes. Do not need to calculate amount.
#     "read"   : 1,                    // (Number) is readable
#     "write"  : 1,                    // (Number) is writable
#     "locked" : 0,                    // (Number) is file locked. If locked that object cannot be deleted and renamed
#     "tmb"    : 'bac0d45b625f8d4633435ffbd52ca495.png' // (String) Only for images. Thumbnail file name, if file do not have thumbnail yet, but it can be generated than it must have value "1"
#     "alias"  : "files/images",       // (String) For symlinks only. Symlink target path.
#     "thash"  : "l1_c2NhbnMy",        // (String) For symlinks only. Symlink target hash.
#     "dim"    : "640x480"             // (String) For images - file dimensions. Optionally.
#     "volumeid" : "l1_"               // (String) Volume id. For root dir only.
# }
# {
#   name: @name,
#   hash: encode('.'),
#   mime: 'directory',
#   ts: File.mtime(@root).to_i,
#   size: 0,
#   dirs: 0,
#   read: 1,
#   write: 1,
#   locked: 0,
#   volumeid: "#{@id}_"
# }
  path_info(PathName.new(@root, target))
end

#decode(hash) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 102

def decode(hash)
  hash = hash.slice(("#{@id}_".length)..-1) if hash.start_with?("#{@id}_")
  hash = hash.tr('-_.', '+/=')
  # restore missing '='
  len = hash.length % 4
  hash += '==' if len == 1 or len == 2
  hash += '=' if len == 3
  path = Base64.strict_decode64(hash)

  if block_given?
    yield path
  else
    PathName.new(@root, path)
  end

end

#disabled_commandsObject

Elenco comandi disabilitati



142
143
144
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 142

def disabled_commands
  []
end

#encode(path) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 119

def encode(path)
  # creates hash for the path
  # path = ElFinder::Pathname.new(@root, path).path.to_s
  hash = Base64.strict_encode64(path)
  hash.tr!('+/=', '-_.')
  hash.gsub!(/\.+\Z/, '')
  "#{@id}_#{hash}"
end

#pathname(target) ⇒ Object

def files(target = '.')

target = ElFinder::Pathname.new(@root, target)
files = []
# files = target.children.map {|p| path_info(p)}
files << cwd(target)
files

end



136
137
138
# File 'lib/alchemy/custom/model/el_finder/volumes/base.rb', line 136

def pathname(target)
  raise "Absolute Path for file"
end