Class: AmcmsFilemanager::FilemanagerController

Inherits:
ApplicationController show all
Defined in:
app/controllers/amcms_filemanager/filemanager_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate

Instance Method Details

#change_directoryObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 21

def change_directory
  @files = AmcmsFilemanager::Filemanager.list(params[:cd], params[:type])

  render json: {
    files: @files,
    pwd: pwd,
    pwd_name: pwd.split('/').last,
    root_directory: AmcmsFilemanager.config.root_path,
    parent_directory: AmcmsFilemanager::Filemanager.parent_dir(params[:cd])
  }
end

#copyObject



33
34
35
36
37
38
39
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 33

def copy
  if AmcmsFilemanager::Filemanager.copy(params[:item_name])
    render json: { success: true }, status: 200
  else
    render json: { success: false }, status: 400
  end
end

#destroyObject



57
58
59
60
61
62
63
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 57

def destroy
  if AmcmsFilemanager::Filemanager.delete(params[:file])
    render json: { success: true }, status: 200
  else
    render json: { success: false }, status: 400
  end
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 7

def index
  @config = {
    routes: {
      cd_path: filemanager_change_directory_path,
      mkdir_path: filemanager_mkdir_path,
      rm_path: filemanager_destroy_path,
      rename_path: filemanager_rename_path,
      copy_path: filemanager_copy_path,
      image_info_path: imagemanager_path(':id'),
    },
    type: params.fetch(:type, 'all')
  }
end

#mkdirObject



41
42
43
44
45
46
47
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 41

def mkdir
  if AmcmsFilemanager::Filemanager.mkdir(params[:pwd], params[:item_name])
    render json: { success: true }, status: 200
  else
    render json: { success: false }, status: 400
  end
end

#renameObject



49
50
51
52
53
54
55
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 49

def rename
  if AmcmsFilemanager::Filemanager.rename(params[:pwd], params[:original_filename], params[:item_name])
    render json: { success: true }, status: 200
  else
    render json: { success: false }, status: 400
  end
end

#uploadObject



65
66
67
68
69
70
71
72
73
# File 'app/controllers/amcms_filemanager/filemanager_controller.rb', line 65

def upload
  if AmcmsFilemanager::Filemanager::upload(params[:dir], params[:file], params[:type])
    render json: { success: true }, status: 200
  else
    render json: { success: false }, status: 400
  end
rescue CarrierWave::IntegrityError => e
  render json: { error: e.message }, status: 400
end