Add Download
This commit is contained in:
parent
1d72256098
commit
f5c7792717
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# 文件上传
|
# 文件上传
|
||||||
class AttachmentsController < ApplicationController
|
class AttachmentsController < ApplicationController
|
||||||
before_action :require_login, :check_auth, except: [:show, :preview_attachment]
|
before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file]
|
||||||
before_action :find_file, only: %i[show destroy]
|
before_action :find_file, only: %i[show destroy]
|
||||||
before_action :attachment_candown, only: [:show]
|
before_action :attachment_candown, only: [:show]
|
||||||
skip_before_action :check_sign, only: [:show, :create]
|
skip_before_action :check_sign, only: [:show, :create]
|
||||||
|
@ -28,6 +28,14 @@ class AttachmentsController < ApplicationController
|
||||||
update_downloads(@file)
|
update_downloads(@file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def get_file
|
||||||
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
|
response = Faraday.get(URI.parse(params[:download_url].to_s.gsub("http:", "https:")))
|
||||||
|
filename = params[:download_url].to_s.split("/").pop()
|
||||||
|
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
# 1. 本地存储
|
# 1. 本地存储
|
||||||
# 2. 上传到云
|
# 2. 上传到云
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
module RepositoriesHelper
|
module RepositoriesHelper
|
||||||
def render_decode64_content(str)
|
def render_decode64_content(str)
|
||||||
return nil if str.blank?
|
return nil if str.blank?
|
||||||
Base64.decode64(str).force_encoding('UTF-8')
|
Base64.decode64(str).force_encoding("UTF-8")
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_type(str)
|
def download_type(str)
|
||||||
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata)
|
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata doc docx mpp)
|
||||||
default_type.include?(str&.downcase)
|
default_type.include?(str&.downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ json.sha entry['sha']
|
||||||
json.path entry['path']
|
json.path entry['path']
|
||||||
json.type entry['type']
|
json.type entry['type']
|
||||||
json.size entry['size']
|
json.size entry['size']
|
||||||
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']).force_encoding('UTF-8') : ""
|
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']) : ""
|
||||||
json.target entry['target']
|
json.target entry['target']
|
||||||
json.download_url entry['download_url']
|
json.download_url entry['download_url']
|
||||||
json.direct_download direct_download
|
json.direct_download direct_download
|
||||||
|
|
|
@ -8,8 +8,10 @@ Rails.application.routes.draw do
|
||||||
# Serve websocket cable requests in-process
|
# Serve websocket cable requests in-process
|
||||||
mount ActionCable.server => '/cable'
|
mount ActionCable.server => '/cable'
|
||||||
|
|
||||||
|
get 'attachments/entries/get_file', to: 'attachments#get_file'
|
||||||
get 'attachments/download/:id', to: 'attachments#show'
|
get 'attachments/download/:id', to: 'attachments#show'
|
||||||
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
get 'attachments/download/:id/:filename', to: 'attachments#show'
|
||||||
|
|
||||||
get 'auth/qq/callback', to: 'oauth/qq#create'
|
get 'auth/qq/callback', to: 'oauth/qq#create'
|
||||||
get 'auth/failure', to: 'oauth/base#auth_failure'
|
get 'auth/failure', to: 'oauth/base#auth_failure'
|
||||||
get 'auth/cas/callback', to: 'oauth/cas#create'
|
get 'auth/cas/callback', to: 'oauth/cas#create'
|
||||||
|
|
Loading…
Reference in New Issue