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.
52 lines
1.1 KiB
52 lines
1.1 KiB
package PreviewController
|
|
|
|
import (
|
|
"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("/preview", preview)
|
|
return
|
|
}
|
|
|
|
// http://127.0.0.1:9000/support/preview/preview
|
|
func preview(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)
|
|
|
|
//判断是不是本地存在
|
|
isExist, err := CommonUtil.PathExists(fullPath)
|
|
if err != nil {
|
|
c.String(http.StatusOK, "发生严重错误:"+err.Error())
|
|
return
|
|
}
|
|
if !isExist {
|
|
c.String(http.StatusOK, "输入的文件无法找到!")
|
|
return
|
|
}
|
|
//将文件上传到华为云
|
|
key := "dsMinPreview/" + 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)
|
|
}
|