el_finder2 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +22 -0
  4. data/app/assets/javascripts/el_finder2/application.js +13 -0
  5. data/app/assets/stylesheets/el_finder2/application.css +15 -0
  6. data/app/controllers/el_finder2/application_controller.rb +4 -0
  7. data/app/controllers/el_finder2/el_finder_controller.rb +12 -0
  8. data/app/models/el_finder2/document.rb +9 -0
  9. data/app/models/el_finder2/file.rb +28 -0
  10. data/app/models/el_finder2/folder.rb +9 -0
  11. data/app/models/el_finder2/image.rb +16 -0
  12. data/app/serializers/el_finder2/document_serializer.rb +9 -0
  13. data/app/serializers/el_finder2/file_serializer.rb +41 -0
  14. data/app/serializers/el_finder2/folder_serializer.rb +30 -0
  15. data/app/serializers/el_finder2/image_serializer.rb +13 -0
  16. data/config/routes.rb +4 -0
  17. data/db/migrate/20151130180935_create_files.rb +14 -0
  18. data/db/migrate/20151130191903_create_el_finder2_file_hierarchies.rb +16 -0
  19. data/db/migrate.old/20151124151257_create_el_finder2_folders.rb +11 -0
  20. data/db/migrate.old/20151124160017_create_el_finder2_files.rb +13 -0
  21. data/db/migrate.old/20151124170526_create_el_finder2_folder_hierarchies.rb +16 -0
  22. data/lib/el_finder2/command/base.rb +22 -0
  23. data/lib/el_finder2/command/dim.rb +26 -0
  24. data/lib/el_finder2/command/duplicate.rb +26 -0
  25. data/lib/el_finder2/command/file.rb +61 -0
  26. data/lib/el_finder2/command/mkdir.rb +33 -0
  27. data/lib/el_finder2/command/open.rb +134 -0
  28. data/lib/el_finder2/command/parents.rb +31 -0
  29. data/lib/el_finder2/command/rename.rb +29 -0
  30. data/lib/el_finder2/command/resize.rb +36 -0
  31. data/lib/el_finder2/command/rm.rb +23 -0
  32. data/lib/el_finder2/command/size.rb +29 -0
  33. data/lib/el_finder2/command/tmb.rb +23 -0
  34. data/lib/el_finder2/command/tree.rb +25 -0
  35. data/lib/el_finder2/command/upload.rb +84 -0
  36. data/lib/el_finder2/command.rb +34 -0
  37. data/lib/el_finder2/engine.rb +23 -0
  38. data/lib/el_finder2/error.rb +9 -0
  39. data/lib/el_finder2/hash_utils.rb +22 -0
  40. data/lib/el_finder2/version.rb +3 -0
  41. data/lib/el_finder2.rb +10 -0
  42. data/lib/tasks/el_finder2_tasks.rake +4 -0
  43. metadata +267 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be7041364cc124624626d8d3b2ec4a498f509915
4
+ data.tar.gz: 0af3537614b2d09ce8d2a0ce13718f4fbc1f22cd
5
+ SHA512:
6
+ metadata.gz: 66cd518df32c9bf78638d0b627becbe5c609faffce0eaf136265dfea1c9a8f75e27fefb2da52efb94aea4341c8b5885f3472116ada2a16134cdcf1dfa9487a0c
7
+ data.tar.gz: cd209452f8af4e8cfafe867e180a7d74c2ff332086d777d95446623262b324952e8eb23a35d65b7f2f5b37f2f84c8d2bfb1061092310063d1876b41f0929e77a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Keith Layne
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ElFinder2'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ElFinder2
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ require_dependency 'el_finder2/application_controller'
2
+
3
+ module ElFinder2
4
+ class ElFinderController < ApplicationController
5
+ def command
6
+ Command.dispatch(self, params.dup)
7
+ fail Exception.new('Command failed to render') unless performed?
8
+ rescue ElFinder2::Error => ex
9
+ render json: { error: ex.payload }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module ElFinder2
2
+ class Document < ElFinder2::File
3
+ has_attached_file :content
4
+
5
+ do_not_validate_attachment_file_type :content
6
+
7
+ delegate :content_type, :size, to: :content
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module ElFinder2
2
+ class File < ActiveRecord::Base
3
+ include ElFinder2::HashUtils
4
+ has_closure_tree
5
+
6
+ validates :name, uniqueness: { scope: :parent_id }
7
+
8
+ def self.find_by_path(path)
9
+ super(path.split('/'))
10
+ end
11
+
12
+ def self.path_exists?(path)
13
+ !!find_by_path(path.split('/'))
14
+ end
15
+
16
+ def self.upload_attributes(_)
17
+ {}
18
+ end
19
+
20
+ def path
21
+ ancestry_path.join('/')
22
+ end
23
+
24
+ def path_hash
25
+ "#{ElFinder2::VOLUME_ID}_#{to_base64url(path)}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module ElFinder2
2
+ class Folder < ElFinder2::File
3
+ ROOT = where(name: 'Root', parent_id: nil).first_or_create
4
+
5
+ def size
6
+ descendants.to_a.sum(&:size)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module ElFinder2
2
+ class Image < ElFinder2::File
3
+ has_attached_file :content, styles: { thumb: '100x100>' }
4
+
5
+ validates_attachment :content,
6
+ content_type: { content_type: ElFinder2::IMAGE_MIME_REGEX }
7
+
8
+ delegate :content_type, :size, :url, to: :content
9
+
10
+ def self.upload_attributes(upload)
11
+ geometry = Paperclip::Geometry.from_file(upload.path)
12
+
13
+ { dimensions: "#{geometry.width.to_i}x#{geometry.height.to_i}" }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module ElFinder2
2
+ class DocumentSerializer < FileSerializer
3
+ attributes :mime
4
+
5
+ def mime
6
+ object.content_type
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,41 @@
1
+ module ElFinder2
2
+ class FileSerializer < ActiveModel::Serializer
3
+ include ElFinder2::HashUtils
4
+
5
+ self.root = false
6
+
7
+ attributes :name, :hash, :phash, :ts, :size, :read, :write, :locked
8
+
9
+ def filter(keys)
10
+ if object.parent_id
11
+ keys
12
+ else
13
+ keys - [:phash]
14
+ end
15
+ end
16
+
17
+ def hash
18
+ object.path_hash
19
+ end
20
+
21
+ def locked
22
+ 0
23
+ end
24
+
25
+ def phash
26
+ object.parent.path_hash
27
+ end
28
+
29
+ def read
30
+ 1
31
+ end
32
+
33
+ def ts
34
+ object.updated_at.try(:tv_sec).to_i
35
+ end
36
+
37
+ def write
38
+ 1
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ module ElFinder2
2
+ class FolderSerializer < FileSerializer
3
+ attributes :mime, :volumeid, :dirs
4
+
5
+ # def initialize(object, options = {})
6
+ # super
7
+ # @tree = options.fetch(:tree)
8
+ # end
9
+
10
+ def filter(keys)
11
+ if object.parent_id
12
+ super
13
+ else
14
+ super + [:volumeid]
15
+ end
16
+ end
17
+
18
+ def dirs
19
+ object.children.where(type: 'ElFinder2::Folder').exists? ? 1 : 0
20
+ end
21
+
22
+ def mime
23
+ 'directory'
24
+ end
25
+
26
+ def volumeid
27
+ ElFinder2::VOLUME_ID + '_'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module ElFinder2
2
+ class ImageSerializer < DocumentSerializer
3
+ attributes :dim, :tmb
4
+
5
+ def dim
6
+ object.dimensions
7
+ end
8
+
9
+ def tmb
10
+ object.url(:thumb)
11
+ end
12
+ end
13
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ ElFinder2::Engine.routes.draw do
2
+ root 'el_finder#command'
3
+ match '/' => 'el_finder#command', via: [:get, :post]
4
+ end
@@ -0,0 +1,14 @@
1
+ class CreateFiles < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_finder2_files do |t|
4
+ t.integer :parent_id
5
+ t.string :type, null: false
6
+ t.string :name, null: false
7
+ t.attachment :content
8
+ t.string :content_fingerprint
9
+ t.string :dimensions
10
+ t.timestamps null: false
11
+ end
12
+ add_foreign_key :el_finder2_files, :el_finder2_files, column: :parent_id
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ class CreateElFinder2FileHierarchies < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_finder2_file_hierarchies, id: false do |t|
4
+ t.integer :ancestor_id, null: false
5
+ t.integer :descendant_id, null: false
6
+ t.integer :generations, null: false
7
+ end
8
+
9
+ add_index :el_finder2_file_hierarchies, [:ancestor_id, :descendant_id, :generations],
10
+ unique: true,
11
+ name: 'file_anc_desc_idx'
12
+
13
+ add_index :el_finder2_file_hierarchies, [:descendant_id],
14
+ name: 'file_desc_idx'
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ class CreateElFinder2Folders < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_finder2_folders do |t|
4
+ t.string :name, null: false
5
+ t.integer :parent_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ add_foreign_key :el_finder2_folders, :el_finder2_folders, column: :parent_id
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ class CreateElFinder2Files < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_finder2_files do |t|
4
+ t.integer :folder_id
5
+ t.attachment :content
6
+ t.string :content_fingerprint
7
+ t.string :name, null: false
8
+
9
+ t.timestamps null: false
10
+ end
11
+ add_foreign_key :el_finder2_files, :el_finder2_folders, column: :folder_id
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class CreateElFinder2FolderHierarchies < ActiveRecord::Migration
2
+ def change
3
+ create_table :el_finder2_folder_hierarchies, id: false do |t|
4
+ t.integer :ancestor_id, null: false
5
+ t.integer :descendant_id, null: false
6
+ t.integer :generations, null: false
7
+ end
8
+
9
+ add_index :el_finder2_folder_hierarchies, [:ancestor_id, :descendant_id, :generations],
10
+ unique: true,
11
+ name: 'folder_anc_desc_idx'
12
+
13
+ add_index :el_finder2_folder_hierarchies, [:descendant_id],
14
+ name: 'folder_desc_idx'
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module ElFinder2
2
+ module Command
3
+ class Base
4
+ extend Forwardable
5
+ include ElFinder2::HashUtils
6
+
7
+ def_delegators :@controller, :render, :response, :redirect_to, :send_data
8
+
9
+ def initialize(controller, params)
10
+ @controller = controller
11
+ parse_params!(params)
12
+ end
13
+
14
+ def execute
15
+ fail ElFinder2::Error.new('errCmdNoSupport')
16
+ end
17
+
18
+ private def parse_params!(params)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ module ElFinder2
2
+ module Command
3
+ class Dim < Base
4
+ def execute
5
+ images = @targets.inject({}) do |hash, image|
6
+ hash[image.path_hash] = image.url(:thumb)
7
+ end
8
+
9
+ render json: { images: images }
10
+ end
11
+
12
+ private def parse_params!(params)
13
+ target = params[:target]
14
+ fail ElFinder2::Error.new(%w(errCmdParams dim)) unless target
15
+
16
+ path = to_path(target)
17
+
18
+ @image = ElFinder2::Image.find_by_path(path)
19
+
20
+ fail ElFinder2::Error.new('errFileNotFound') unless @file
21
+
22
+ @download = params[:download] == '1'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module ElFinder2
2
+ module Command
3
+ class Duplicate < Base
4
+ def execute
5
+ duplicate = @target.copy_to(@current)
6
+
7
+ render json: {
8
+ added: ActiveModel::ArraySerializer.new([duplicate]).as_json
9
+ }
10
+ end
11
+
12
+ private def parse_params!(params)
13
+ current, target = params.values_at(:current, :target)
14
+ fail ElFinder2::Error.new(%w(errCmdParams duplicate)) unless current.present? && target.present?
15
+
16
+ current_path = to_path(current)
17
+ target_path = to_path(target)
18
+
19
+ @current = ElFinder2::Folder.find_by_path(current)
20
+ @target = ElFinder2::File.find_by_path(target)
21
+
22
+ fail ElFinder2::Error.new('errFileNotFound') unless @current && @target
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ module ElFinder2
2
+ module Command
3
+ class Resize < Base
4
+ def execute
5
+ source = Paperclip.io_adapters.for(@file.content)
6
+ dest = Paperclip::TempfileFactory.new.generate(source.path)
7
+
8
+ Paperclip::Processor.new(source.path).
9
+ convert(@convert_params, source: source.path, dest: dest.path)
10
+
11
+ geometry = Paperclip::Geometry.from_file(dest.path)
12
+
13
+ @file.content = dest
14
+ @file.dimensions = "#{geometry.width.to_i}x#{geometry.height.to_i}"
15
+ @file.save
16
+
17
+ render json: {
18
+ changed: ActiveModel::ArraySerializer.new([@file]).as_json
19
+ }
20
+ end
21
+
22
+ private def parse_params!(params)
23
+ target, mode = params.values_at(:target, :mode)
24
+ fail ElFinder2::Error.new(%w(errCmdParams resize)) unless target && mode
25
+
26
+ path = to_path(target)
27
+
28
+ @file = ElFinder2::Image.find_by_path(path)
29
+
30
+ fail ElFinder2::Error.new('errFileNotFound') unless @file
31
+
32
+ @convert_params =
33
+ case mode
34
+ when 'crop' then for_crop(params)
35
+ when 'resize' then for_resize(params)
36
+ when 'rotate' then for_rotate(params)
37
+ end
38
+
39
+ fail ElFinder2::Error.new(%w(errCmdParams resize)) unless @convert_params
40
+ end
41
+
42
+ private def for_crop(params)
43
+ width, height, x, y = params.values_at(:width, :height, :x, :y)
44
+
45
+ "-crop #{width}x#{height}+#{x}+#{y} :source :dest" if width && height && x && y
46
+ end
47
+
48
+ private def for_rotate(params)
49
+ degrees = params[:degree]
50
+
51
+ "-rotate #{degrees} :source :dest" if degrees
52
+ end
53
+
54
+ private def for_resize(params)
55
+ width, height = params.values_at(:width, :height)
56
+
57
+ "-resize #{width}x#{height}! :source :dest" if width && height
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,33 @@
1
+ module ElFinder2
2
+ module Command
3
+ class Mkdir < Base
4
+ # Response:
5
+ # added : (Array) Array with a single object - a new directory.
6
+ def execute
7
+ new_folder = @folder.children.create(name: @name, type: 'ElFinder2::Folder')
8
+
9
+ fail ElFinder2::Error.new(['errMkdir', @name]) unless new_folder.persisted?
10
+
11
+ render json: {
12
+ added: ActiveModel::ArraySerializer.new([new_folder]).as_json
13
+ }
14
+ end
15
+
16
+ # Arguments:
17
+ # target : hash of target directory,
18
+ # name : New directory name
19
+ private def parse_params!(params)
20
+ target = params[:target]
21
+ @name = params[:name]
22
+
23
+ fail ElFinder2::Error.new(%w(errCmdParams file)) unless target && @name
24
+
25
+ path = to_path(target)
26
+
27
+ @folder = ElFinder2::Folder.find_by_path(path)
28
+
29
+ fail ElFinder2::Error.new('errFolderNotFound') unless @folder
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,134 @@
1
+ module ElFinder2
2
+ module Command
3
+ # Returns information about requested directory and its content, optionally
4
+ # can return directory tree as files, and options for the current volume.
5
+ class Open < Base
6
+ # Response:
7
+ #
8
+ # api: (Number) The version number of the protocol, must be >= 2,
9
+ # ATTENTION - return api ONLY for init request!
10
+ # cwd: (Object) Current Working Directory - information about the
11
+ # current directory. Information about File/Directory
12
+ # files: (Array) array of objects - files and directories in current
13
+ # directory. If parameter tree == true, then added to the folder of the
14
+ # directory tree to a given depth. The order of files is not important.
15
+ # Note you must include the top-level volume objects here as well (i.e.
16
+ # cwd is repeated here, in addition to other volumes) Information about
17
+ # File/Directory
18
+ # netDrivers: (Array) Network protocols list which can be mounted on the
19
+ # fly (using netmount command). Now only ftp supported.
20
+ #
21
+ # Optional
22
+ #
23
+ # uplMaxSize: (String) Allowed upload max size. For example "32M"
24
+ #
25
+ # options: (Object) Further information about the folder and its volume
26
+ # {
27
+ # options: {
28
+ # // (String) Current folder path
29
+ # path: "files/folder42",
30
+ # // (String) Current folder URL
31
+ # url: "http://localhost/elfinder/files/folder42/",
32
+ # // (String) Thumbnails folder URL
33
+ # tmbURL: "http://localhost/elfinder/files/folder42/.tmb/",
34
+ # // (String) Разделитель пути для текущего тома
35
+ # separator: "/",
36
+ # // (Array) List of commands not allowed (disabled) on this volume
37
+ # disabled: [],
38
+ # // (Number) Whether or not to overwrite files with the same name on
39
+ # // the current volume
40
+ # copyOverwrite: 1,
41
+ # // (Object) Archive settings
42
+ # archivers: {
43
+ # // (Array) List of the mime type of archives which can be created
44
+ # create: [
45
+ # 0: "application/x-tar",
46
+ # 1: "application/x-gzip"
47
+ # ],
48
+ # // (Array) List of the mime types that can be extracted / unpacked
49
+ # extract: [
50
+ # 0: "application/x-tar",
51
+ # 1: "application/x-gzip"
52
+ # ]
53
+ # }
54
+ # }
55
+ # }
56
+ #
57
+ # debug: (Object) Debug information, if you specify the corresponding
58
+ # connector option.
59
+ # {
60
+ # debug: {
61
+ # // (String) Connector type
62
+ # connector: "php",
63
+ # // (String) php version
64
+ # phpver: "5.3.6",
65
+ # // (Number) Execution time
66
+ # time: 0.0749430656433,
67
+ # // (String) Used / Free / Available Memory
68
+ # memory: "3348Kb / 2507Kb / 128M",
69
+ # // (Array) Debugging by volume
70
+ # volumes: [
71
+ # {
72
+ # // (String) ID of the Volume
73
+ # id: "l1_",
74
+ # // (String) Driver type (class name)
75
+ # driver: "localfilesystem",
76
+ # // (String) Method for determining mime type
77
+ # mimeDetect: "internal",
78
+ # // (String) Library for working with images
79
+ # imgLib: "gd"
80
+ # }
81
+ # ],
82
+ # // (Array) List of errors for not mounted volumes
83
+ # mountErrors: [
84
+ # 0: "Root folder has not read and write permissions."
85
+ # ]
86
+ # }
87
+ # }
88
+ def execute
89
+ files = @folder.self_and_descendants
90
+ files = files.where('parent_id = :id OR id = :id', id: @folder.id) unless @tree
91
+
92
+ response = {
93
+ cwd: ElFinder2::FolderSerializer.new(@folder).as_json,
94
+ files: ActiveModel::ArraySerializer.new(files).as_json,
95
+ options: {}
96
+ }
97
+
98
+ response.merge!(
99
+ api: ElFinder2::API_VERSION
100
+ ) if @init
101
+
102
+ render json: response
103
+ end
104
+
105
+ # Arguments:
106
+
107
+ # init : (true|false|not set), optional parameter. If true indicates
108
+ # that this request is an initialization request and its response must
109
+ # include the value api (number or string >= 2) and should include the
110
+ # options object, but will still work without it. Also, this option
111
+ # affects the processing of parameter target hash value. If init == true
112
+ # and target is not set or that directory doesn't exist, then the data
113
+ # connector must return the root directory of the default volume.
114
+ # Otherwise it must return error "File not found".
115
+ # target : (string) Hash of directory to open. Required if init == false
116
+ # or init is not set
117
+ # tree : (true|false), optional. If true, response must contain
118
+ # subfolders trees of roots directories.
119
+ private def parse_params!(params)
120
+ @init = params[:init] == '1'
121
+ @tree = params[:tree] == '1'
122
+
123
+ fail ElFinder2::Error.new(%w(errCmdParams open)) unless @init || params.key?(:target)
124
+
125
+ path = to_path(params[:target])
126
+
127
+ @folder = ElFinder2::Folder.find_by_path(path) if path
128
+ @folder = ElFinder2::Folder.root if @init && !@folder
129
+
130
+ fail ElFinder2::Error.new('errFolderNotFound') unless @folder
131
+ end
132
+ end
133
+ end
134
+ end