|
|
|
@ -11,7 +11,6 @@ import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -41,16 +40,28 @@ func previewOffice(c *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fullPath := string(uDec)
|
|
|
|
|
//判断是不是华为云上存在,原则上存在就不需要再次上传了~
|
|
|
|
|
tempArray:=strings.Split(strings.Replace(strings.ToLower(fullPath),"\\","/",-1),"/")
|
|
|
|
|
fiName:=tempArray[len(tempArray)-1]
|
|
|
|
|
key := Const.PreviewPrefix + fiName
|
|
|
|
|
url := "http://ow365.cn/?i=14531&fname=" + fiName + "&furl=http%3A%2F%2Fvideo.edusoa.com%2F" + key
|
|
|
|
|
//如果存在,则直接返回
|
|
|
|
|
if ObsUtil.IsExist(fiName){
|
|
|
|
|
//输出预览地址
|
|
|
|
|
c.String(http.StatusOK, url)
|
|
|
|
|
//fmt.Println("文件已在云存储中存在,无需下载和上传!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//(1) 是否以http或https开头
|
|
|
|
|
if strings.HasPrefix(strings.ToLower(fullPath), "https://") || strings.HasPrefix(strings.ToLower(fullPath), "http://") {
|
|
|
|
|
//文件名称
|
|
|
|
|
arr := strings.Split(fullPath, "/")
|
|
|
|
|
fi := arr[len(arr)-1]
|
|
|
|
|
if !CommonUtil.IsContainString(allowExtension,"."+path.Ext(fi)){
|
|
|
|
|
c.String(http.StatusOK, "输入的预览文件,系统不支持!")
|
|
|
|
|
c.String(http.StatusOK, "输入的预览文件格式,系统不支持!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//下载
|
|
|
|
|
//准备下载
|
|
|
|
|
res, err := http.Get(fullPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(http.StatusOK, "输入的网络地址无法找到,不能进行预览!")
|
|
|
|
@ -68,8 +79,6 @@ func previewOffice(c *gin.Context) {
|
|
|
|
|
io.Copy(f, res.Body)
|
|
|
|
|
}
|
|
|
|
|
//(2) 是不是本地文件
|
|
|
|
|
_, p := filepath.Split(fullPath)
|
|
|
|
|
|
|
|
|
|
//判断是不是本地存在
|
|
|
|
|
isExist, err := CommonUtil.PathExists(fullPath)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -81,10 +90,7 @@ func previewOffice(c *gin.Context) {
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|