|
|
|
@ -3,10 +3,12 @@ package PreviewController
|
|
|
|
|
import (
|
|
|
|
|
"dsSupport/Utils/CommonUtil"
|
|
|
|
|
"dsSupport/Utils/ObsUtil"
|
|
|
|
|
"encoding/base64"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"path"
|
|
|
|
|
"strings"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//模块的路由配置
|
|
|
|
@ -17,19 +19,26 @@ func Routers(r *gin.RouterGroup) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// http://127.0.0.1:9000/surpport/preview/preview
|
|
|
|
|
// http://127.0.0.1:9000/support/preview/preview
|
|
|
|
|
func preview(c *gin.Context) {
|
|
|
|
|
//本地物理路径
|
|
|
|
|
p := c.Query("p")
|
|
|
|
|
filenameWithSuffix := path.Base(p) //获取文件名带后缀
|
|
|
|
|
fileSuffix := path.Ext(filenameWithSuffix) //获取文件后缀
|
|
|
|
|
filenameOnly := strings.TrimSuffix(filenameWithSuffix, fileSuffix) //获取文件名
|
|
|
|
|
if len(filenameOnly) != 36 {
|
|
|
|
|
c.String(http.StatusOK, "输入的文件名只支持GUID格式!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
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(p)
|
|
|
|
|
isExist, err := CommonUtil.PathExists(fullPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(http.StatusOK, "发生严重错误:"+err.Error())
|
|
|
|
|
return
|
|
|
|
@ -39,11 +48,10 @@ func preview(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//将文件上传到华为云
|
|
|
|
|
key := "dsMinPreview/" + filenameOnly
|
|
|
|
|
ObsUtil.UploadFileMultiPart(key, p)
|
|
|
|
|
key := "dsMinPreview/" + p
|
|
|
|
|
ObsUtil.UploadFileMultiPart(key, fullPath)
|
|
|
|
|
//返回地址
|
|
|
|
|
// http://ow365.cn/?i=14531&fname=6F8D046F-6D0E-CEE3-A2DE-661EA77DCABB&furl=http%3A%2F%2Fvideo.edusoa.com%2Fdown%2FMaterial%2F6F%2F6F8D046F-6D0E-CEE3-A2DE-661EA77DCABB.docx
|
|
|
|
|
url := "http://ow365.cn/?i=14531&fname=" + filenameOnly + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
|
|
|
|
|
url := "http://ow365.cn/?i=14531&fname=" + p + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
|
|
|
|
|
//输出预览地址
|
|
|
|
|
c.String(http.StatusOK, url)
|
|
|
|
|
}
|
|
|
|
|