diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index e0dd71467..6ef43c694 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -17,9 +17,11 @@ class AttachmentsController < ApplicationController redirect_to @file.cloud_url and return end - pdf_attachment = params[:disposition] || "attachment" - if pdf_attachment == "inline" + type_attachment = params[:disposition] || "attachment" + if type_attachment == "inline" send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf' + elsif type_attachment == "MP4" + send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true else send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream') end @@ -202,4 +204,31 @@ class AttachmentsController < ApplicationController end end + def send_file_with_range(path, options = {}) + logger.info("########request.headers: #{request.headers}") + logger.info("########request.headers: #{File.exist?(path)}") + + if File.exist?(path) + size = File.size(path) + logger.info("########request.headers: #{request.headers}") + if !request.headers["Range"] + status_code = 200 # 200 OK + offset = 0 + length = File.size(path) + else + status_code = 206 # 206 Partial Content + bytes = Rack::Utils.byte_ranges(request.headers, size)[0] + offset = bytes.begin + length = bytes.end - bytes.begin + end + response.header["Accept-Ranges"] = "bytes" + response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes + response.header["status"] = status_code + + send_data IO.binread(path, length, offset), options + else + raise ActionController::MissingFile, "Cannot read file #{path}." + end + end + end diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index 348303116..b038c836f 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -1,5 +1,5 @@ import React,{ Component } from "react"; -import { WordsBtn,ActionBtn,getmyUrl } from 'educoder'; +import { WordsBtn,ActionBtn,getmyUrl,getUrl } from 'educoder'; import {Tooltip,message,Input, Button} from 'antd'; import {Link} from 'react-router-dom'; import axios from 'axios' @@ -60,7 +60,8 @@ class Fileslistitem extends Component{ if(list.content_type==="video/mp4"){ this.setState({ videoModalObj:true, - file_url:getmyUrl(list.url+'?file_name='+list.title), + file_url:"https://"+document.domain+list.url+'?file_name='+list.title+"&disposition=MP4", + // file_url:getUrl()+list.url+'?file_name='+list.title+'&disposition=MP4', }) return }else{ @@ -92,7 +93,9 @@ class Fileslistitem extends Component{ if(list.content_type==="video/mp4"){ this.setState({ videoModalObj:true, - file_url:getmyUrl(list.url+'?file_name='+list.title), + file_url:"https://"+document.domain+list.url+'?file_name='+list.title+'&disposition=MP4', + // file_url:getUrl()+list.url+'?file_name='+list.title+'&disposition=MP4', + }) return }else{ @@ -127,9 +130,10 @@ class Fileslistitem extends Component{ Clicktobroadcastthevideo=(bool,url)=>{ this.setState({ - videoModalObj:bool, - file_url:getmyUrl(url), - }) + videoModalObj:bool, + file_url:"https://"+document.domain+url+'&disposition=MP4', + // file_url:getUrl()+url+'&disposition=MP4', + }) } @@ -215,8 +219,11 @@ class Fileslistitem extends Component{ const { checkBox, discussMessage,index } = this.props; - console.log("Fileslistitem"); - console.log(file_url); + // console.log("Fileslistitem"); + // console.log( document.domain); + // console.log(this.props.imhost); + // console.log( window.location.href); + return(
{ @@ -228,16 +235,16 @@ class Fileslistitem extends Component{ width={800 - 1} > - {/*
*/} - {/* */} - {/* this.copyurls()}>复制视频地址*/} - {/*
*/} +
+ + this.copyurls()}>复制视频地址 +
:"" @@ -256,7 +263,7 @@ class Fileslistitem extends Component{ {...this.props} visible={this.state.Showoldfiles} allfiles={this.state.allfiles} - Clicktobroadcastthevideo={(bool,urls)=>this.Clicktobroadcastthevideo(bool,urls)} + Clicktobroadcastthevideo={(bool,urls,index)=>this.Clicktobroadcastthevideo(bool,urls,index)} closaoldfilesprops={this.closaoldfilesprops} />