Add download function at home controller
This commit is contained in:
parent
ab00afa513
commit
92a0d71bda
@ -1,19 +1,16 @@
|
|||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
config = get_conf
|
|
||||||
#@current_dir = config["project_path"]
|
|
||||||
@current_dir = "/mnt"
|
@current_dir = "/mnt"
|
||||||
file_directory(@current_dir)
|
file_directory(@current_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_download
|
def file_download
|
||||||
@file_name = params[:file_name]
|
@file_name = params[:file_name].gsub(" ", "/")
|
||||||
puts "file_name: " + @file_name
|
if !@file_name.nil?
|
||||||
if File.exist?(@file_name)
|
send_file @file_name
|
||||||
#File.delete(@file_name)
|
else
|
||||||
puts "file exist!!"
|
puts "file name is nil"
|
||||||
send_file(@file_name)
|
redirect_to '/home/index'
|
||||||
puts "send success"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -162,11 +162,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td>
|
<td>
|
||||||
<form class="form_file_download" data-parsley-validate>
|
<a href="/file_download?file_name=<%=(@current_dir+'/'+t['name']).gsub("/", "+")%>"><%=t['name']%></a>
|
||||||
<i class="fa fa-file-o"></i>
|
|
||||||
<input type="hidden", value="<%=@current_dir + '/' + t['name']%>">
|
|
||||||
<button type="submit" style="border: none; background: none;"><%=t["name"]%></button>
|
|
||||||
</form>
|
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%=t["auth"]%></td>
|
<td><%=t["auth"]%></td>
|
||||||
@ -279,11 +275,7 @@ function change_directory(directory){
|
|||||||
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
|
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
|
||||||
}else{
|
}else{
|
||||||
new_tr += "<td>";
|
new_tr += "<td>";
|
||||||
new_tr += "<form class='form_file_download' data-parsley-validate>";
|
new_tr += "<a href='/file_download?file_name="+ (cur + "/" + result.file[i].name).replace(/\//, "+") + "'>" + result.file[i].name + "</a>"
|
||||||
new_tr += "<i class='fa fa-file-o'></i>";
|
|
||||||
new_tr += "<input type='hidden', value='" + cur + "/" + result.file[i].name + "'>";
|
|
||||||
new_tr += "<button type='submit' style='border: none; background: none;'>" + result.file[i].name + "</button>";
|
|
||||||
new_tr += "</form>";
|
|
||||||
new_tr += "</td>";
|
new_tr += "</td>";
|
||||||
}
|
}
|
||||||
new_tr += "<td>"+result.file[i].auth+"</td>";
|
new_tr += "<td>"+result.file[i].auth+"</td>";
|
||||||
@ -296,45 +288,16 @@ function change_directory(directory){
|
|||||||
$("#table_div").append(new_table);
|
$("#table_div").append(new_table);
|
||||||
$('#datatable').dataTable();
|
$('#datatable').dataTable();
|
||||||
right_click();
|
right_click();
|
||||||
|
|
||||||
$(".form_file_download").submit(function(){
|
|
||||||
file_name = $(this).find("input").val();
|
|
||||||
$.ajax({
|
|
||||||
type: 'post',
|
|
||||||
url: '/file_download',
|
|
||||||
data: {file_name: file_name},
|
|
||||||
success: function(result){
|
|
||||||
console.log("post success");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
$("document").ready(function(){
|
$("document").ready(function(){
|
||||||
$(".form_file_download").submit(function(){
|
})
|
||||||
file_name = $(this).find("input").val();
|
|
||||||
$.ajax({
|
|
||||||
type: 'post',
|
|
||||||
url: '/file_download',
|
|
||||||
data: {file_name: file_name},
|
|
||||||
success: function(result){
|
|
||||||
console.log("post success");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<!--Test Page specific JS -->
|
<!--Test Page specific JS -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@ Rails.application.routes.draw do
|
|||||||
get 'index' => 'plainpage#index'
|
get 'index' => 'plainpage#index'
|
||||||
|
|
||||||
#Home
|
#Home
|
||||||
|
get 'file_download' => 'home#file_download'
|
||||||
get 'home/index' => 'home#index'
|
get 'home/index' => 'home#index'
|
||||||
post 'home/mkdir' => 'home#make_directory'
|
post 'home/mkdir' => 'home#make_directory'
|
||||||
post 'home/delete' => 'home#delete_file'
|
post 'home/delete' => 'home#delete_file'
|
||||||
post 'file_download' => 'home#file_download'
|
|
||||||
|
|
||||||
#Volume
|
#Volume
|
||||||
get 'volume/index' => 'volume#index'
|
get 'volume/index' => 'volume#index'
|
||||||
|
Loading…
Reference in New Issue
Block a user