You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package PreviewController
import (
"dsSupport/Const"
"dsSupport/Utils/CommonUtil"
"dsSupport/Utils/ObsUtil"
"encoding/base64"
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"path/filepath"
)
//模块的路由配置
func Routers ( r * gin . RouterGroup ) {
rr := r . Group ( "/preview" )
//配置接口
rr . GET ( "/previewOffice" , previewOffice )
return
}
// http://127.0.0.1:9000/support/preview/previewOffice
/**
功能: 提供Office系列文件的预览功能
作者:黄海
时间: 2020-07-15
*/
func previewOffice ( c * gin . Context ) {
//本地物理路径
uEnc := c . Query ( "p" )
uDec , err := base64 . URLEncoding . DecodeString ( uEnc )
if err != nil {
log . Fatalln ( err )
}
fullPath := string ( uDec )
fmt . Println ( fullPath )
_ , p := filepath . Split ( fullPath )
//TODO
//(1)保允许上传office系列的文件
//(2)在上传前判断文件是否已存在,存在了直接返回,不做重复工作,也可以支持强制刷新,需要添加参数
//(3)需要判断文件名是不是是标准的GUID形式, 不是的不让上传
//(4)对于异常的明显提示信息
//判断是不是本地存在
isExist , err := CommonUtil . PathExists ( fullPath )
if err != nil {
c . String ( http . StatusOK , "发生严重错误:" + err . Error ( ) )
return
}
if ! isExist {
c . String ( http . StatusOK , "输入的文件无法找到!" )
return
}
//将文件上传到华为云
key := Const . PreviewPrefix + p
ObsUtil . UploadFileMultiPart ( key , fullPath )
//返回地址
url := "http://ow365.cn/?i=14531&fname=" + p + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
//输出预览地址
c . String ( http . StatusOK , url )
}