Class: RailsHttpLab::FoldersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_http_lab/folders_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
# File 'app/controllers/rails_http_lab/folders_controller.rb', line 5

def create
  path = params.require(:path).to_s
  RailsHttpLab::Storage::Filesystem.new.create_folder(path, display_name: params[:name])
  render json: { ok: true, path: path }
end

#destroyObject



28
29
30
31
32
# File 'app/controllers/rails_http_lab/folders_controller.rb', line 28

def destroy
  path = params.require(:path).to_s
  RailsHttpLab::Storage::Filesystem.new.delete(path)
  head :no_content
end

#renameObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/rails_http_lab/folders_controller.rb', line 11

def rename
  from     = params.require(:path).to_s
  new_name = params.require(:name).to_s.strip
  raise RailsHttpLab::Error, "name cannot be empty" if new_name.empty?
  raise RailsHttpLab::Error, "name cannot contain '/' or '\\'" if new_name.match?(%r{[/\\]})

  parent = File.dirname(from)
  parent = "" if parent == "."
  to = parent.empty? ? new_name : "#{parent}/#{new_name}"

  fs = RailsHttpLab::Storage::Filesystem.new
  fs.rename(from, to)
  update_folder_meta_name(fs, to, new_name)

  render json: { ok: true, path: to }
end