|
|
|
@ -10,6 +10,7 @@ import (
|
|
|
|
|
"io"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
@ -29,6 +30,9 @@ func Routers(r *gin.RouterGroup) {
|
|
|
|
|
时间:2020-07-15
|
|
|
|
|
*/
|
|
|
|
|
func previewOffice(c *gin.Context) {
|
|
|
|
|
// 允许预览的扩展名
|
|
|
|
|
allowExtension := []string{`doc`, `docx`, `rtf`, `xls`, `xlsx`, `ppt`, `pptx`,
|
|
|
|
|
`pdf`, `zip`, `rar`, `7z`, `png`, `jpg`, `jpeg`, `wps`, `txt`, `js`, `json`, `css`, `sql`, `xml`, `java`, `cs`}
|
|
|
|
|
//本地物理路径
|
|
|
|
|
uEnc := c.Query("p")
|
|
|
|
|
uDec, err := base64.URLEncoding.DecodeString(uEnc)
|
|
|
|
@ -39,15 +43,19 @@ func previewOffice(c *gin.Context) {
|
|
|
|
|
fullPath := string(uDec)
|
|
|
|
|
//(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, "输入的预览文件,系统不支持!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//下载
|
|
|
|
|
res, err := http.Get(fullPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.String(http.StatusOK, "输入的网络地址无法找到,不能进行预览!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//文件名称
|
|
|
|
|
arr := strings.Split(fullPath, "/")
|
|
|
|
|
fi := arr[len(arr)-1]
|
|
|
|
|
fullPath = CommonUtil.GetCurrentPath() + "/TempFiles/" + fi
|
|
|
|
|
if FileUtil.Exists(fullPath) {
|
|
|
|
|
os.Remove(fullPath)
|
|
|
|
@ -66,7 +74,6 @@ func previewOffice(c *gin.Context) {
|
|
|
|
|
//(1)只允许上传office系列的文件
|
|
|
|
|
//(2)在上传前判断文件是否已存在,存在了直接返回,不做重复工作,也可以支持强制刷新,需要添加参数
|
|
|
|
|
//(3)需要判断文件名是不是是标准的GUID形式,不是的不让上传
|
|
|
|
|
//(4)对于异常的明显提示信息
|
|
|
|
|
|
|
|
|
|
//判断是不是本地存在
|
|
|
|
|
isExist, err := CommonUtil.PathExists(fullPath)
|
|
|
|
|