|
@@ -1,36 +1,20 @@
|
|
package api
|
|
package api
|
|
|
|
|
|
import (
|
|
import (
|
|
- "3dshow-supplier/conf"
|
|
|
|
|
|
+ "3dshow-supplier/bus"
|
|
"3dshow-supplier/db/model"
|
|
"3dshow-supplier/db/model"
|
|
"3dshow-supplier/db/repo"
|
|
"3dshow-supplier/db/repo"
|
|
- "3dshow-supplier/log"
|
|
|
|
- "bytes"
|
|
|
|
- "context"
|
|
|
|
- "crypto/tls"
|
|
|
|
- "errors"
|
|
|
|
- "fmt"
|
|
|
|
- "image"
|
|
|
|
- "io"
|
|
|
|
- "io/ioutil"
|
|
|
|
- "net/http"
|
|
|
|
- "os"
|
|
|
|
- "os/exec"
|
|
|
|
- "path"
|
|
|
|
- "strings"
|
|
|
|
|
|
+ "3dshow-supplier/funcgraph"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
_ "image/jpeg"
|
|
_ "image/jpeg"
|
|
_ "image/png"
|
|
_ "image/png"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
- "github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
)
|
|
|
|
|
|
-var ffmpegExe = ""
|
|
|
|
-
|
|
|
|
func regAssetApi(r *GinRouter) {
|
|
func regAssetApi(r *GinRouter) {
|
|
|
|
|
|
// 添加管理端接口
|
|
// 添加管理端接口
|
|
@@ -43,6 +27,15 @@ func regAssetApi(r *GinRouter) {
|
|
entity.SupplyId, _ = primitive.ObjectIDFromHex(apictx.User.Parent)
|
|
entity.SupplyId, _ = primitive.ObjectIDFromHex(apictx.User.Parent)
|
|
entity.CreateTime = time.Now()
|
|
entity.CreateTime = time.Now()
|
|
|
|
|
|
|
|
+ if entity.Groups != nil {
|
|
|
|
+ for _, g := range entity.Groups {
|
|
|
|
+ if len(g.ImagesPath) < 1 {
|
|
|
|
+ g.State = model.GROUPSTATE_UNSET
|
|
|
|
+ } else {
|
|
|
|
+ g.State = model.GROUPSTATE_ADDED
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return entity, nil
|
|
return entity, nil
|
|
},
|
|
},
|
|
|
|
|
|
@@ -58,419 +51,42 @@ func regAssetApi(r *GinRouter) {
|
|
},
|
|
},
|
|
JWT: true,
|
|
JWT: true,
|
|
SearchProject: []string{"name", "createTime", "type", "unit", "price", "cover", "status"},
|
|
SearchProject: []string{"name", "createTime", "type", "unit", "price", "cover", "status"},
|
|
- })
|
|
|
|
-
|
|
|
|
- r.POST("/assets/conv/:id/:groupId", AssetsConv)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func AssetsConv(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
|
-
|
|
|
|
- params := c.Params
|
|
|
|
- id, ok := params.Get("id")
|
|
|
|
- if !ok {
|
|
|
|
- return nil, errors.New("id不能为空")
|
|
|
|
- }
|
|
|
|
- groupId, ok := params.Get("groupId")
|
|
|
|
- if !ok {
|
|
|
|
- return nil, errors.New("groupId不能为空")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- startTime := time.Now()
|
|
|
|
- dir, _ := os.Getwd()
|
|
|
|
- ffmpegExe = fmt.Sprintf("%s/ffmpeg", dir)
|
|
|
|
- wPath := fmt.Sprintf("%s/%s/%s/spin_360", "assets", id, groupId)
|
|
|
|
- oPath := fmt.Sprintf("%s/%s/%s/spin_360", "images", id, groupId)
|
|
|
|
-
|
|
|
|
- // todo下载图片到oPth
|
|
|
|
- currAsset := &model.Asset360Fake3d{}
|
|
|
|
- ok, _ = repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
|
- CollectName: repo.CollectionAssets,
|
|
|
|
- Query: repo.Map{"_id": id},
|
|
|
|
- }, currAsset)
|
|
|
|
- if !ok {
|
|
|
|
- return nil, fmt.Errorf("当前资产不存在")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- groupPath := ""
|
|
|
|
- for _, item := range currAsset.Groups {
|
|
|
|
- if item.Id == groupId {
|
|
|
|
- groupPath = item.ImagesPath
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if len(groupPath) < 1 {
|
|
|
|
- return nil, fmt.Errorf("当前素材才尚未上传")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- _getImageIndex := func(i int) string {
|
|
|
|
- if i < 10 {
|
|
|
|
- return fmt.Sprintf("00_0%d.png", i)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return fmt.Sprintf("00_%d.png", i)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- index := 0
|
|
|
|
- for {
|
|
|
|
- name := _getImageIndex(index)
|
|
|
|
- remoteUrl := fmt.Sprintf("%s/%s", groupPath, name)
|
|
|
|
-
|
|
|
|
- //下载文件
|
|
|
|
- err := DownLoadFile(remoteUrl, fmt.Sprintf("%s/%s", oPath, name))
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, fmt.Errorf("文件下载失败!")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 获取图片
|
|
|
|
- files, _ := os.ReadDir(oPath)
|
|
|
|
- levels := map[int]int{4: 10, 2: 11, 1: 12}
|
|
|
|
-
|
|
|
|
- // 递归创建
|
|
|
|
- os.MkdirAll(wPath, os.ModePerm)
|
|
|
|
-
|
|
|
|
- for _, f := range files {
|
|
|
|
- fi, _ := os.Open(fmt.Sprintf("./%s/%s", oPath, f.Name()))
|
|
|
|
-
|
|
|
|
- imageInfo, _, _ := image.DecodeConfig(fi)
|
|
|
|
- defer fi.Close()
|
|
|
|
-
|
|
|
|
- filePrefix := getFilePrefix(f.Name())
|
|
|
|
- // 生成每个文件目录 00_00_files
|
|
|
|
- preFileDir := fmt.Sprintf("%s/%s%s", wPath, filePrefix, "_files")
|
|
|
|
- os.Mkdir(preFileDir, os.ModePerm)
|
|
|
|
-
|
|
|
|
- // 生成cover 384/512
|
|
|
|
- // asset/spin_360/00_00_cover.png
|
|
|
|
- orignFile := fmt.Sprintf("%s/%s", oPath, f.Name())
|
|
|
|
- coverFile := fmt.Sprintf("%s/%s_cover%s", wPath, filePrefix, path.Ext(f.Name()))
|
|
|
|
- scaleImage(384, 512, orignFile, coverFile)
|
|
|
|
-
|
|
|
|
- // 生成json文件 asset/spin_360/00_00.json
|
|
|
|
- jsonContent := fmt.Sprintf("{\"tileSource\": \"%s\",\"tileSize\": 510,\"width\": 1944,\"height\": 2592,\"sceneType\": \"spin\",\"scaleType\": \"inside\",\"minLevel\": 10,\"coverWidth\": 384,\"coverHeight\": 512,\"dziFile\": \"%s.dzi\",\"coverImage\":\"%s\"}", fmt.Sprintf("%s%s", filePrefix, "_files"), filePrefix, fmt.Sprintf("%s_cover%s", filePrefix, path.Ext(f.Name())))
|
|
|
|
- jsonFileName := fmt.Sprintf("%s/%s.json", wPath, filePrefix)
|
|
|
|
- setJsonFile(jsonFileName, jsonContent)
|
|
|
|
-
|
|
|
|
- // 文件目录下level目录 00_00_files/10 11 23
|
|
|
|
- for scale, level := range levels {
|
|
|
|
- preLevelDir := fmt.Sprintf("%s/%s%s/%d", wPath, filePrefix, "_files", level)
|
|
|
|
- os.Mkdir(preLevelDir, os.ModePerm)
|
|
|
|
-
|
|
|
|
- // 生成缩略图
|
|
|
|
- levelW := imageInfo.Width / scale
|
|
|
|
- levelH := imageInfo.Height / scale
|
|
|
|
-
|
|
|
|
- levelDest := fmt.Sprintf("%s/%s%s/%d", wPath, filePrefix, "_files", level)
|
|
|
|
- levelScaleImage := fmt.Sprintf("%s/%s_scale%s", levelDest, filePrefix, path.Ext(f.Name()))
|
|
|
|
- scaleImage(levelW, levelH, orignFile, levelScaleImage)
|
|
|
|
-
|
|
|
|
- // 裁剪缩略图
|
|
|
|
- createLevel(levelW, levelH, levelScaleImage, levelDest)
|
|
|
|
- os.Remove(levelScaleImage)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 删除图片文件
|
|
|
|
- // os.Remove(oPath)
|
|
|
|
- // os.Remove(wPath)
|
|
|
|
-
|
|
|
|
- fmt.Println(time.Since(startTime).Seconds())
|
|
|
|
-
|
|
|
|
- key := wPath
|
|
|
|
- _url, _ := serviceObsUploadPolicy(key, apictx.Svc.Conf)
|
|
|
|
-
|
|
|
|
- url := fmt.Sprintf("%s%s", "https://www.3dqueen.cloud/asset360/index.html?apath=", _url)
|
|
|
|
-
|
|
|
|
- result, err := repo.RepoDocArrayOneUpdate(apictx.CreateRepoCtx(), &repo.ArrayOneUpdateOption{
|
|
|
|
- CollectName: repo.CollectionAssets,
|
|
|
|
- Id: id,
|
|
|
|
- Query: repo.Map{"groups.id": groupId},
|
|
|
|
- Set: repo.Map{"groups.$.url": url},
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- return result, err
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func createLevel(w, h int, source, dest string) {
|
|
|
|
-
|
|
|
|
- xIndex := 0
|
|
|
|
- yIndex := 0
|
|
|
|
- step := 510
|
|
|
|
- for {
|
|
|
|
-
|
|
|
|
- offsetX := xIndex * step
|
|
|
|
- cropX := offsetX - 1
|
|
|
|
- cropW := 512
|
|
|
|
- if xIndex == 0 {
|
|
|
|
- cropW = 511
|
|
|
|
- cropX = 0
|
|
|
|
- }
|
|
|
|
- isOver := false
|
|
|
|
- if w < 511 {
|
|
|
|
- cropW = w
|
|
|
|
- isOver = true
|
|
|
|
- }
|
|
|
|
- if (offsetX - 1 + cropW) >= w {
|
|
|
|
- cropW = w - offsetX + 1
|
|
|
|
- isOver = true
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for {
|
|
|
|
-
|
|
|
|
- offsetY := yIndex * step
|
|
|
|
- cropY := offsetY - 1
|
|
|
|
- cropH := 512
|
|
|
|
- if yIndex == 0 {
|
|
|
|
- cropH = 511
|
|
|
|
- cropY = 0
|
|
|
|
|
|
+ OnUpdate: func(c *gin.Context, apictx *ApiSession, entity interface{}, id primitive.ObjectID) {
|
|
|
|
+ asset := entity.(*model.Asset360Fake3d)
|
|
|
|
+ if asset == nil {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- isYOver := false
|
|
|
|
- if (offsetY - 1 + cropH) >= h {
|
|
|
|
- cropH = h - offsetY + 1
|
|
|
|
- isYOver = true
|
|
|
|
|
|
+ natsUrl := ""
|
|
|
|
+ if asset.Groups == nil {
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
- //开始按参数裁剪
|
|
|
|
- cropImage(cropX, cropY, cropW, cropH, xIndex, yIndex, source, dest)
|
|
|
|
- fmt.Println("x:", cropX)
|
|
|
|
- fmt.Println("y:", cropY)
|
|
|
|
- fmt.Println("w:", cropW)
|
|
|
|
- fmt.Println("h:", cropH)
|
|
|
|
- fmt.Println("yIndex:", yIndex)
|
|
|
|
-
|
|
|
|
- yIndex = yIndex + 1
|
|
|
|
-
|
|
|
|
- if isYOver {
|
|
|
|
- break
|
|
|
|
|
|
+ for _, g := range asset.Groups {
|
|
|
|
+ if len(g.ImagesPath) < 1 {
|
|
|
|
+ g.State = model.GROUPSTATE_UNSET
|
|
|
|
+ } else {
|
|
|
|
+ if len(g.State) < 1 {
|
|
|
|
+ g.State = model.GROUPSTATE_ADDED
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if g.State == model.GROUPSTATE_ADDED && len(g.ImagesPath) > 1 {
|
|
|
|
+ if len(natsUrl) < 1 {
|
|
|
|
+ url, err := bus.NatsCenter.RequestConfig("bus-network")
|
|
|
|
+ if err != nil {
|
|
|
|
+ g.State = model.GROUPSTATE_FAIL
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ natsUrl = url
|
|
|
|
+ }
|
|
|
|
+ err := funcgraph.Tile360onvRequest(id.Hex(), g.Id, g.ImagesPath, natsUrl)
|
|
|
|
+ if err != nil {
|
|
|
|
+ g.State = model.GROUPSTATE_FAIL
|
|
|
|
+ } else {
|
|
|
|
+ g.State = model.GROUPSTATE_CROPING
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- yIndex = 0
|
|
|
|
- xIndex = xIndex + 1
|
|
|
|
- if isOver {
|
|
|
|
- break
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// asset/spin_360/00_00.json
|
|
|
|
-func setJsonFile(fileName string, content string) {
|
|
|
|
- f, err := os.Create(fileName)
|
|
|
|
- if err != nil {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- f.WriteString(content)
|
|
|
|
- defer f.Close()
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// 获取不带后缀文件名
|
|
|
|
-func getFilePrefix(fileName string) string {
|
|
|
|
- fileSilce := strings.Split(fileName, ".")
|
|
|
|
- return fileSilce[0]
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// asset/spin_360_scene/00_00_files/10/00_00_scale.png asset/spin_360_scene/00_00_files/10
|
|
|
|
-func cropImage(x, y, w, h int, xIndex, yIndex int, source, dest string) {
|
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), time.Duration(50000)*time.Millisecond)
|
|
|
|
- cmd := exec.CommandContext(ctx, ffmpegExe,
|
|
|
|
- "-i", source,
|
|
|
|
- "-vf", fmt.Sprintf("crop=%d:%d:%d:%d", w, h, x, y),
|
|
|
|
- fmt.Sprintf("%s/%d_%d%s", dest, xIndex, yIndex, path.Ext(source)),
|
|
|
|
- )
|
|
|
|
- defer cancel()
|
|
|
|
-
|
|
|
|
- err := cmd.Run()
|
|
|
|
- if err != nil {
|
|
|
|
- errImage := fmt.Sprintf("%s/%d_%d%s", dest, xIndex, yIndex, path.Ext(source))
|
|
|
|
- fmt.Println("err image:", errImage)
|
|
|
|
- fmt.Println("crop err", err)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func scaleImage(w, h int, source, dest string) {
|
|
|
|
- ctx, cancel := context.WithTimeout(context.Background(), time.Duration(50000)*time.Millisecond)
|
|
|
|
- // ffmpeg -i image_source -vf scale=width:height out_source
|
|
|
|
- cmd := exec.CommandContext(ctx, ffmpegExe,
|
|
|
|
- "-i", source,
|
|
|
|
- "-vf", fmt.Sprintf("scale=%d:%d", w, h),
|
|
|
|
- dest,
|
|
|
|
- )
|
|
|
|
- defer cancel()
|
|
|
|
-
|
|
|
|
- err := cmd.Run()
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("scale err", err)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func serviceObsUploadPolicy(key string, conf *conf.AppConf) (interface{}, error) {
|
|
|
|
-
|
|
|
|
- client, err := CreateObsClient()
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, NewError("创建ObsClient 失败!")
|
|
|
|
- }
|
|
|
|
- defer func() {
|
|
|
|
- client.Close()
|
|
|
|
- }()
|
|
|
|
- bucketName := conf.Obs.Bucket
|
|
|
|
- _, err = client.CreateBrowserBasedSignature(&obs.CreateBrowserBasedSignatureInput{
|
|
|
|
- Bucket: bucketName,
|
|
|
|
- Key: key,
|
|
|
|
- Expires: 600,
|
|
|
|
- FormParams: map[string]string{
|
|
|
|
- "x-obs-acl": "public-read",
|
|
|
|
},
|
|
},
|
|
})
|
|
})
|
|
-
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, NewLogWithError(err)
|
|
|
|
- }
|
|
|
|
- obsConf := conf.Obs
|
|
|
|
- // out := map[string]interface{}{
|
|
|
|
- // "accessKeyId": obsConf.AccessKeyId,
|
|
|
|
- // "originPolicy": result.OriginPolicy,
|
|
|
|
- // "policy": result.Policy,
|
|
|
|
- // "signature": result.Signature,
|
|
|
|
- // "host": fmt.Sprintf("https://%s.%s", bucketName, obsConf.Endpoint),
|
|
|
|
- // "key": key,
|
|
|
|
- // "saveType": conf.SaveType,
|
|
|
|
- // }
|
|
|
|
- url := fmt.Sprintf("%s/%s", fmt.Sprintf("https://%s.%s", bucketName, obsConf.Endpoint), key)
|
|
|
|
- return url, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func CreateObsClient() (*obs.ObsClient, error) {
|
|
|
|
- obsConf := conf.AppConfig.Obs
|
|
|
|
- return obs.New(obsConf.AccessKeyId, obsConf.SecrateKey, obsConf.Endpoint)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func uploadImage(fpath string, obsDir string) (string, error) {
|
|
|
|
- client, err := CreateObsClient()
|
|
|
|
- if err != nil {
|
|
|
|
- return "", err
|
|
|
|
- }
|
|
|
|
- obsConf := conf.AppConfig.Obs
|
|
|
|
-
|
|
|
|
- return UploadFile(client, obsConf.Bucket, fpath, obsDir)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func UploadFile(obsClient *obs.ObsClient, bucketName string, fpath string, obsDir string) (string, error) {
|
|
|
|
- _, obsname := path.Split(fpath)
|
|
|
|
- keyFormat := "%s/%s"
|
|
|
|
- if strings.HasSuffix(obsDir, "/") {
|
|
|
|
- keyFormat = "%s%s"
|
|
|
|
- }
|
|
|
|
- obsKey := fmt.Sprintf(keyFormat, obsDir, obsname)
|
|
|
|
-
|
|
|
|
- input := &obs.PutFileInput{}
|
|
|
|
- input.Bucket = bucketName
|
|
|
|
- input.Key = obsKey
|
|
|
|
- input.SourceFile = fpath
|
|
|
|
-
|
|
|
|
- fpathExt := path.Ext(fpath)
|
|
|
|
- isGzFile := fpathExt == ".gz"
|
|
|
|
- if isGzFile {
|
|
|
|
- input.ContentType = "text/plain"
|
|
|
|
- input.Metadata = map[string]string{"Content-Encoding": "gzip"}
|
|
|
|
- }
|
|
|
|
- result, err := obsClient.PutFile(input)
|
|
|
|
-
|
|
|
|
- isUploadOk := true
|
|
|
|
-
|
|
|
|
- if err != nil {
|
|
|
|
- log.Errorf("upload obs fail %s", fpath)
|
|
|
|
- log.Error(err)
|
|
|
|
- isUploadOk = false
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if result.StatusCode != 200 {
|
|
|
|
- isUploadOk = false
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if !isUploadOk {
|
|
|
|
- result, err = obsClient.PutFile(input)
|
|
|
|
-
|
|
|
|
- if err != nil {
|
|
|
|
- log.Errorf("upload obs fail2 %s", fpath)
|
|
|
|
- log.Error(err)
|
|
|
|
- return "", err
|
|
|
|
- }
|
|
|
|
- if result.StatusCode != 200 {
|
|
|
|
- return "", fmt.Errorf("上传失败!")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if isGzFile {
|
|
|
|
- metaRet, err := obsClient.SetObjectMetadata(&obs.SetObjectMetadataInput{
|
|
|
|
- Bucket: bucketName,
|
|
|
|
- Key: obsKey,
|
|
|
|
- ContentEncoding: "gzip",
|
|
|
|
- ContentType: "text/plain",
|
|
|
|
- })
|
|
|
|
- fmt.Println(metaRet, err)
|
|
|
|
-
|
|
|
|
- if err != nil {
|
|
|
|
- metaRet, err = obsClient.SetObjectMetadata(&obs.SetObjectMetadataInput{
|
|
|
|
- Bucket: bucketName,
|
|
|
|
- Key: obsKey,
|
|
|
|
- ContentEncoding: "gzip",
|
|
|
|
- ContentType: "text/plain",
|
|
|
|
- })
|
|
|
|
- fmt.Println(metaRet, err)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- obsConf := conf.AppConfig.Obs
|
|
|
|
-
|
|
|
|
- return fmt.Sprintf("//%s.%s/%s", bucketName, obsConf.Endpoint, obsKey), nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func DownLoadFile(src string, target string) error {
|
|
|
|
- out, err := os.Create(target)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if strings.HasPrefix(src, "//") {
|
|
|
|
- src = fmt.Sprintf("http:%s", src)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- timeout := time.Duration(180 * time.Second)
|
|
|
|
- client := &http.Client{
|
|
|
|
- Timeout: timeout,
|
|
|
|
- Transport: &http.Transport{
|
|
|
|
- TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- resp, err := client.Get(src)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- defer resp.Body.Close()
|
|
|
|
-
|
|
|
|
- pix, err := ioutil.ReadAll(resp.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- _, err = io.Copy(out, bytes.NewReader(pix))
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- out.Close()
|
|
|
|
-
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func isExist(path string) bool {
|
|
|
|
- _, err := os.Stat(path)
|
|
|
|
- if err != nil {
|
|
|
|
- if os.IsExist(err) {
|
|
|
|
- return true
|
|
|
|
- }
|
|
|
|
- if os.IsNotExist(err) {
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- fmt.Println(err)
|
|
|
|
- return false
|
|
|
|
- }
|
|
|
|
- return true
|
|
|
|
}
|
|
}
|