Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_winse
hjm 6 years ago
commit c171e9d61f

@ -15,8 +15,13 @@ class AttachmentsController < ApplicationController
update_downloads(@file)
redirect_to @file.cloud_url and return
end
send_file(absolute_path(local_path(@file)), filename: @file.filename, type: @file.content_type.presence || 'application/octet-stream')
pdf_attachment = params[:disposition] || "attachment"
if pdf_attachment == "inline"
send_file absolute_path(local_path(@file)),filename: @file.filename, disposition: 'inline',type: 'application/pdf'
else
send_file(absolute_path(local_path(@file)), filename: @file.filename,stream:false, type: @file.content_type.presence || 'application/octet-stream')
end
update_downloads(@file)
end

@ -1,5 +1,5 @@
class Users::VideoAuthsController < Users::BaseController
before_action :private_user_resources!, :require_auth_teacher!
before_action :private_user_resources!, :check_account, :require_auth_teacher!
def create
result = Videos::CreateAuthService.call(observed_user, create_params)

@ -1,5 +1,5 @@
class Users::VideosController < Users::BaseController
before_action :private_user_resources!, :require_auth_teacher!
before_action :private_user_resources!, :check_account, :require_auth_teacher!
helper_method :current_video

@ -52,7 +52,8 @@ module ApplicationHelper
shixun_id = shixun_id.blank? ? -1 : shixun_id.join(",")
Shixun.select([:id, :name, :user_id, :challenges_count, :myshixuns_count, :trainee, :identifier]).where("id
in(#{shixun_id}) or homepage_show =1").unhidden.order("myshixuns_count desc, homepage_show asc").limit(3)
in(#{shixun_id})").unhidden.order("homepage_show asc, myshixuns_count desc").limit(3)
end
# 相关推荐
@ -257,8 +258,8 @@ module ApplicationHelper
end
end
def download_url attachment
attachment_path(attachment)
def download_url attachment,options={}
attachment_path(attachment,options)
end
# 耗时:天、小时、分、秒

@ -6,6 +6,7 @@ json.publish_time attachment.publish_time
json.quotes attachment.quotes_count
json.downloads_count attachment.downloads_count
json.created_on attachment.created_on
json.url attachment_path(attachment, type: 'history').gsub("/api","")
# json.url attachment_path(attachment, type: 'history').gsub("/api","")
json.is_pdf attachment.is_history_pdf?
json.url attachment.is_history_pdf? ? attachment_path(attachment, type: 'history',disposition:"inline") : attachment_path(attachment, type: 'history')
json.attachment_id attachment.attachment_id

@ -11,6 +11,5 @@ json.quotes attachment.quotes_count
json.description attachment.description
json.downloads_count attachment.downloads_count
json.created_on attachment.created_on
json.url download_url(attachment)
# json.url download_url(attachment) unless attachment.locked?(@is_member)
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)

@ -2,5 +2,7 @@ json.id attachment.id
json.title attachment.title
json.filesize number_to_human_size attachment.filesize
json.description attachment.description
json.url download_url(attachment)
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
# json.url download_url(attachment)
json.set! :delete, delete.nil? ? true : delete if defined? delete

@ -1,6 +1,6 @@
json.id attachment.id
json.title attachment.title
json.filesize number_to_human_size(attachment.filesize)
json.url download_url(attachment)
json.is_pdf attachment.is_pdf?
json.url attachment.is_pdf? ? download_url(attachment,disposition:"inline") : download_url(attachment)
json.created_on attachment.created_on
json.is_pdf attachment.is_pdf?

@ -1,9 +1,3 @@
# json.partial! 'attachments/attachment_small', attachment: @file
json.id @file.id
json.title @file.title
json.filesize number_to_human_size(@file.filesize)
json.url download_url(@file).gsub("/api","")
json.created_on @file.created_on
json.is_pdf @file.is_pdf?
json.partial! 'attachments/attachment_small', attachment: @file
json.partial! "attachment_histories/list", attachment_histories: @attachment_histories

@ -38,30 +38,13 @@ class Fileslistitem extends Component{
}).then((result)=>{
if(result.data.attachment_histories.length===0){
if(result.data.is_pdf===true){
this.props.ShowOnlinePdf(result.data.url)
//预览pdf
// axios({
// method:'get',
// url:result.data.url,
// responseType: 'arraybuffer',
// }).then((result)=>{
// var binaryData = [];
// binaryData.push(result.data);
// this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
// window.open(this.url);
// })
}else{
let link = document.createElement('a');
document.body.appendChild(link);
link.href = "/api"+result.data.url;
link.download = result.data.title;
//兼容火狐浏览器
let evt = document.createEvent("MouseEvents");
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link);
}
// if(result.data.is_pdf===true){
// this.props.ShowOnlinePdf(result.data.url)
// //预览pdf
// }else{
//
// }
this.props.DownloadFileA(result.data.title,result.data.url)
}else{
this.setState({
Showoldfiles:true,
@ -147,8 +130,6 @@ class Fileslistitem extends Component{
discussMessage,
} = this.props;
return(
<div className="graduateTopicList boardsList">

@ -43,16 +43,6 @@ class Showoldfiles extends Component{
}
showfiless=(url)=>{
// axios({
// method:'get',
// url:url,
// responseType: 'arraybuffer',
// }).then((result)=>{
// var binaryData = [];
// binaryData.push(result.data);
// this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"}));
// window.open(this.url);
// })
this.props.ShowOnlinePdf(url)
}
render(){
@ -188,10 +178,11 @@ class Showoldfiles extends Component{
<div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={allfiles.id}>
<li className="fl fontlefts">
{allfiles.is_pdf===false?
<a className={"isabox"} href={"/api"+allfiles.url} >{allfiles.title}</a>:
<a className={"isabox"} onClick={()=>this.showfiless(allfiles.url)} >{allfiles.title}</a>
}
<a className={"isabox"} href={allfiles.url} >{allfiles.title}</a>
{/*{allfiles.is_pdf===false?*/}
{/*<a className={"isabox"} href={allfiles.url} >{allfiles.title}</a>:*/}
{/*<a className={"isabox"} onClick={()=>this.showfiless(allfiles.url)} >{allfiles.title}</a>*/}
{/*}*/}
<span className={"newcolor-orange fl"}>当前版本</span>
</li>
@ -207,11 +198,11 @@ class Showoldfiles extends Component{
<div className="clearfix edu-txt-center lineh-40 bor-bottom-greyE" id={item.id} key={key}>
<li className="fl fontlefts">
{item.is_pdf===false?
<a className={"isabox"} href={"/api"+item.url}>{item.title}</a>:
<a className={"isabox"} onClick={()=>this.showfiless(item.url)} >{item.title}</a>
}
<a className={"isabox"} href={item.url}>{item.title}</a>
{/*{item.is_pdf===false?*/}
{/*<a className={"isabox"} href={item.url}>{item.title}</a>:*/}
{/*<a className={"isabox"} onClick={()=>this.showfiless(item.url)} >{item.title}</a>*/}
{/*}*/}
</li>
<li className="fl filesves ">

@ -334,6 +334,17 @@ export function TPMIndexHOC(WrappedComponent) {
window.open(this.url);
})
}
DownloadFileA=(title,url)=>{
let link = document.createElement('a');
document.body.appendChild(link);
link.href =url;
link.download = title;
//兼容火狐浏览器
let evt = document.createEvent("MouseEvents");
evt.initEvent("click", false, false);
link.dispatchEvent(evt);
document.body.removeChild(link);
}
render() {
let{Headertop,Footerdown, isRender, AccountProfiletype}=this.state;
const common = {
@ -351,7 +362,8 @@ export function TPMIndexHOC(WrappedComponent) {
checkIfLogin: this.checkIfLogin,
showProfileCompleteDialog: this.showProfileCompleteDialog,
checkIfProfileCompleted: this.checkIfProfileCompleted,
ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url)
ShowOnlinePdf:(url)=>this.ShowOnlinePdf(url),
DownloadFileA:(title,url)=>this.DownloadFileA(title,url),
}
return (
<div>

Loading…
Cancel
Save