fix change stoage file derictory
This commit is contained in:
parent
a93baa908f
commit
458fca9992
|
@ -28,8 +28,8 @@ class AttachmentsController < ApplicationController
|
||||||
update_downloads(@file)
|
update_downloads(@file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def get_file
|
def get_file
|
||||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
||||||
response = Faraday.get(url)
|
response = Faraday.get(url)
|
||||||
|
@ -45,7 +45,7 @@ class AttachmentsController < ApplicationController
|
||||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||||
raise "未上传文件" unless upload_file
|
raise "未上传文件" unless upload_file
|
||||||
|
|
||||||
folder = edu_setting('attachment_folder')
|
folder = file_storage_directory
|
||||||
raise "存储目录未定义" unless folder.present?
|
raise "存储目录未定义" unless folder.present?
|
||||||
|
|
||||||
month_folder = current_month_folder
|
month_folder = current_month_folder
|
||||||
|
@ -108,7 +108,7 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# 附件为视频时,点击播放
|
# 附件为视频时,点击播放
|
||||||
def preview_attachment
|
def preview_attachment
|
||||||
attachment = Attachment.find_by(id: params[:id])
|
attachment = Attachment.find_by(id: params[:id])
|
||||||
dir_path = "#{Rails.root}/public/preview"
|
dir_path = "#{Rails.root}/public/preview"
|
||||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||||
|
@ -118,10 +118,10 @@ class AttachmentsController < ApplicationController
|
||||||
else
|
else
|
||||||
normal_status(-1, "出现错误,请稍后重试")
|
normal_status(-1, "出现错误,请稍后重试")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
||||||
normal_status(1, "操作成功")
|
normal_status(1, "操作成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "出现错误,请稍后重试")
|
normal_status(-1, "出现错误,请稍后重试")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
include ApplicationHelper
|
||||||
include Ci::DbConnectable
|
include Ci::DbConnectable
|
||||||
|
|
||||||
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
|
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users]
|
||||||
|
@ -79,7 +80,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
def attachment_show
|
def attachment_show
|
||||||
file_name = params[:file_name]
|
file_name = params[:file_name]
|
||||||
path = params[:path] || edu_setting('attachment_folder')
|
path = params[:path] || file_storage_directory
|
||||||
send_file "#{path}/#{file_name}", :filename => "#{file_name}",
|
send_file "#{path}/#{file_name}", :filename => "#{file_name}",
|
||||||
:type => 'game',
|
:type => 'game',
|
||||||
:disposition => 'attachment' #inline can open in browser
|
:disposition => 'attachment' #inline can open in browser
|
||||||
|
|
|
@ -322,7 +322,15 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def absolute_path(file_path)
|
def absolute_path(file_path)
|
||||||
File.join(edu_setting('attachment_folder'), file_path)
|
file_root_directory + File.join(edu_setting('attachment_folder'), file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_root_directory
|
||||||
|
Rails.root.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def file_storage_directory
|
||||||
|
file_root_directory + edu_setting('attachment_folder')
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_path(file)
|
def local_path(file)
|
||||||
|
|
Loading…
Reference in New Issue