| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package osm
- import (
- ossDomain "ecos/application/domain/oss"
- "ecos/config"
- "ecos/utils"
- "git.sxidc.com/service-supports/fslog"
- "git.sxidc.com/service-supports/osm_sdk"
- "github.com/pkg/errors"
- "strings"
- )
- func ExistWithoutPrefix(obj string) (bool, error) {
- if utils.HasBlank(obj) {
- return false, nil
- }
- return osm_sdk.Exist(obj)
- }
- func UrlWithoutPrefix(obj string) (string, string, error) {
- if utils.HasBlank(obj) {
- fslog.Warn("oss获取Url发现违规参数")
- return "", "", nil
- }
- metaData, err := osm_sdk.GetUrlWithMetaData(obj)
- if err != nil {
- return "", "", err
- }
- println(metaData.Url, metaData.FileType, metaData.FileName, metaData.MetaData.FileName, metaData.MetaData.FileType)
- return metaData.Url, metaData.FileName, nil
- }
- func MultipleFileUrl(filePath string) ([]ossDomain.FileObject, error) {
- filePathArr := strings.Split(filePath, ",")
- picture := make([]ossDomain.FileObject, 0)
- for _, file := range filePathArr {
- exist, err := ExistWithoutPrefix(file)
- if err != nil {
- fslog.Error(err)
- picture = append(picture, ossDomain.FileObject{
- Url: file,
- Temp: "",
- })
- continue
- }
- if !exist {
- fslog.Error("文件【" + file + "】不存在")
- picture = append(picture, ossDomain.FileObject{
- Url: file,
- Temp: "",
- })
- continue
- }
- url, fileName, err := UrlWithoutPrefix(file)
- if err != nil {
- fslog.Error("文件【" + file + "】链接生成失败")
- picture = append(picture, ossDomain.FileObject{
- Url: file,
- Temp: "",
- })
- continue
- }
- picture = append(picture, ossDomain.FileObject{
- Url: file,
- Name: fileName,
- Temp: url,
- })
- }
- return picture, nil
- }
- func MultipleFileMv(filePath string) (string, error) {
- endPicture := make([]string, 0)
- files := strings.Split(filePath, ",")
- for _, file := range files {
- //文件名
- tmpFx := config.GetConfig().OsmConfig.TmpPrefix
- pfx := config.GetConfig().OsmConfig.Prefix
- if utils.HasText(file) && strings.Contains(file, "/temp/") {
- fileName, found := strings.CutPrefix(file, tmpFx)
- if !found {
- return "", errors.New("文件名处理失败")
- }
- err := MvWithoutPrefix(file, pfx+fileName)
- if err != nil {
- return "", errors.New("文件移动失败")
- }
- endPicture = append(endPicture, pfx+fileName)
- continue
- }
- endPicture = append(endPicture, file)
- }
- return strings.Join(endPicture, ","), nil
- }
- func MvWithoutPrefix(f, t string) error {
- if _, err := osm_sdk.Copy(f, t); err != nil {
- return err
- }
- return osm_sdk.DeleteMulti(f)
- }
|