Merge branch 'dev_trustie' of http://git.trustie.net/jasder/forgeplus into dev_trustie

This commit is contained in:
Jasder 2020-10-04 10:57:05 +08:00
commit 7f9316075c
4 changed files with 15 additions and 4 deletions

View File

@ -2,7 +2,7 @@
#
# 文件上传
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 :attachment_candown, only: [:show]
skip_before_action :check_sign, only: [:show, :create]
@ -28,6 +28,15 @@ class AttachmentsController < ApplicationController
update_downloads(@file)
end
def get_file
normal_status(-1, "参数缺失") if params[:download_url].blank?
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
response = Faraday.get(url)
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
# 1. 本地存储
# 2. 上传到云

View File

@ -1,11 +1,11 @@
module RepositoriesHelper
def render_decode64_content(str)
return nil if str.blank?
Base64.decode64(str).force_encoding('UTF-8')
Base64.decode64(str).force_encoding("UTF-8")
end
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 vsdx)
default_type.include?(str&.downcase)
end

View File

@ -7,7 +7,7 @@ json.sha entry['sha']
json.path entry['path']
json.type entry['type']
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.download_url entry['download_url']
json.direct_download direct_download

View File

@ -8,8 +8,10 @@ Rails.application.routes.draw do
# Serve websocket cable requests in-process
mount ActionCable.server => '/cable'
get 'attachments/entries/get_file', to: 'attachments#get_file'
get 'attachments/download/:id', to: 'attachments#show'
get 'attachments/download/:id/:filename', to: 'attachments#show'
get 'auth/qq/callback', to: 'oauth/qq#create'
get 'auth/failure', to: 'oauth/base#auth_failure'
get 'auth/cas/callback', to: 'oauth/cas#create'