mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
opt: add default extension for mj image
This commit is contained in:
parent
94680c4411
commit
ed819e8c79
@ -180,7 +180,6 @@ func (s *Service) Notify(job model.MidJourneyJob) error {
|
|||||||
job.OrgURL = task.ImageUrl
|
job.OrgURL = task.ImageUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
job.UseProxy = true
|
|
||||||
job.MessageId = task.Id
|
job.MessageId = task.Id
|
||||||
tx := s.db.Updates(&job)
|
tx := s.db.Updates(&job)
|
||||||
if tx.Error != nil {
|
if tx.Error != nil {
|
||||||
|
@ -124,14 +124,12 @@ func (p *ServicePool) DownloadImages() {
|
|||||||
logger.Infof("try to download image: %s", v.OrgURL)
|
logger.Infof("try to download image: %s", v.OrgURL)
|
||||||
var imgURL string
|
var imgURL string
|
||||||
var err error
|
var err error
|
||||||
if v.UseProxy {
|
if servicePlus := p.getServicePlus(v.ChannelId); servicePlus != nil {
|
||||||
if servicePlus := p.getServicePlus(v.ChannelId); servicePlus != nil {
|
task, _ := servicePlus.Client.QueryTask(v.TaskId)
|
||||||
task, _ := servicePlus.Client.QueryTask(v.TaskId)
|
if len(task.Buttons) > 0 {
|
||||||
if len(task.Buttons) > 0 {
|
v.Hash = plus.GetImageHash(task.Buttons[0].CustomId)
|
||||||
v.Hash = plus.GetImageHash(task.Buttons[0].CustomId)
|
|
||||||
}
|
|
||||||
imgURL, err = p.uploaderManager.GetUploadHandler().PutImg(v.OrgURL, false)
|
|
||||||
}
|
}
|
||||||
|
imgURL, err = p.uploaderManager.GetUploadHandler().PutImg(v.OrgURL, false)
|
||||||
} else {
|
} else {
|
||||||
imgURL, err = p.uploaderManager.GetUploadHandler().PutImg(v.OrgURL, true)
|
imgURL, err = p.uploaderManager.GetUploadHandler().PutImg(v.OrgURL, true)
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,12 @@ import (
|
|||||||
"chatplus/core/types"
|
"chatplus/core/types"
|
||||||
"chatplus/utils"
|
"chatplus/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliYunOss struct {
|
type AliYunOss struct {
|
||||||
@ -88,7 +89,7 @@ func (s AliYunOss) PutImg(imageURL string, useProxy bool) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error with parse image URL: %v", err)
|
return "", fmt.Errorf("error with parse image URL: %v", err)
|
||||||
}
|
}
|
||||||
fileExt := filepath.Ext(parse.Path)
|
fileExt := utils.GetImgExt(parse.Path)
|
||||||
objectKey := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
objectKey := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
||||||
// 上传文件字节数据
|
// 上传文件字节数据
|
||||||
err = s.bucket.PutObject(objectKey, bytes.NewReader(imageData))
|
err = s.bucket.PutObject(objectKey, bytes.NewReader(imageData))
|
||||||
|
@ -4,11 +4,12 @@ import (
|
|||||||
"chatplus/core/types"
|
"chatplus/core/types"
|
||||||
"chatplus/utils"
|
"chatplus/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LocalStorage struct {
|
type LocalStorage struct {
|
||||||
@ -29,7 +30,7 @@ func (s LocalStorage) PutFile(ctx *gin.Context, name string) (File, error) {
|
|||||||
return File{}, fmt.Errorf("error with get form: %v", err)
|
return File{}, fmt.Errorf("error with get form: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := utils.GenUploadPath(s.config.BasePath, file.Filename)
|
path, err := utils.GenUploadPath(s.config.BasePath, file.Filename, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return File{}, fmt.Errorf("error with generate filename: %s", err.Error())
|
return File{}, fmt.Errorf("error with generate filename: %s", err.Error())
|
||||||
}
|
}
|
||||||
@ -54,7 +55,7 @@ func (s LocalStorage) PutImg(imageURL string, useProxy bool) (string, error) {
|
|||||||
return "", fmt.Errorf("error with parse image URL: %v", err)
|
return "", fmt.Errorf("error with parse image URL: %v", err)
|
||||||
}
|
}
|
||||||
filename := filepath.Base(parse.Path)
|
filename := filepath.Base(parse.Path)
|
||||||
filePath, err := utils.GenUploadPath(s.config.BasePath, filename)
|
filePath, err := utils.GenUploadPath(s.config.BasePath, filename, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error with generate image dir: %v", err)
|
return "", fmt.Errorf("error with generate image dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,14 @@ import (
|
|||||||
"chatplus/utils"
|
"chatplus/utils"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/minio/minio-go/v7"
|
|
||||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MiniOss struct {
|
type MiniOss struct {
|
||||||
@ -77,7 +78,7 @@ func (s MiniOss) PutFile(ctx *gin.Context, name string) (File, error) {
|
|||||||
}
|
}
|
||||||
defer fileReader.Close()
|
defer fileReader.Close()
|
||||||
|
|
||||||
fileExt := filepath.Ext(file.Filename)
|
fileExt := utils.GetImgExt(file.Filename)
|
||||||
filename := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
filename := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
||||||
info, err := s.client.PutObject(ctx, s.config.Bucket, filename, fileReader, file.Size, minio.PutObjectOptions{
|
info, err := s.client.PutObject(ctx, s.config.Bucket, filename, fileReader, file.Size, minio.PutObjectOptions{
|
||||||
ContentType: file.Header.Get("Content-Type"),
|
ContentType: file.Header.Get("Content-Type"),
|
||||||
|
@ -6,12 +6,13 @@ import (
|
|||||||
"chatplus/utils"
|
"chatplus/utils"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
|
||||||
"github.com/qiniu/go-sdk/v7/storage"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
||||||
|
"github.com/qiniu/go-sdk/v7/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type QinNiuOss struct {
|
type QinNiuOss struct {
|
||||||
@ -97,7 +98,7 @@ func (s QinNiuOss) PutImg(imageURL string, useProxy bool) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error with parse image URL: %v", err)
|
return "", fmt.Errorf("error with parse image URL: %v", err)
|
||||||
}
|
}
|
||||||
fileExt := filepath.Ext(parse.Path)
|
fileExt := utils.GetImgExt(parse.Path)
|
||||||
key := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
key := fmt.Sprintf("%s/%d%s", s.config.SubDir, time.Now().UnixMicro(), fileExt)
|
||||||
ret := storage.PutRet{}
|
ret := storage.PutRet{}
|
||||||
extra := storage.PutExtra{}
|
extra := storage.PutExtra{}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GenUploadPath 生成上传文件路径
|
// GenUploadPath 生成上传文件路径
|
||||||
func GenUploadPath(basePath, filename string) (string, error) {
|
func GenUploadPath(basePath, filename string, isImg bool) (string, error) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
dir := fmt.Sprintf("%s/%d/%d", basePath, now.Year(), now.Month())
|
dir := fmt.Sprintf("%s/%d/%d", basePath, now.Year(), now.Month())
|
||||||
_, err := os.Stat(dir)
|
_, err := os.Stat(dir)
|
||||||
@ -22,7 +22,12 @@ func GenUploadPath(basePath, filename string) (string, error) {
|
|||||||
return "", fmt.Errorf("error with create upload dir:%v", err)
|
return "", fmt.Errorf("error with create upload dir:%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileExt := filepath.Ext(filename)
|
var fileExt string
|
||||||
|
if isImg {
|
||||||
|
fileExt = GetImgExt(filename)
|
||||||
|
} else {
|
||||||
|
fileExt = filepath.Ext(filename)
|
||||||
|
}
|
||||||
return fmt.Sprintf("%s/%d%s", dir, now.UnixMicro(), fileExt), nil
|
return fmt.Sprintf("%s/%d%s", dir, now.UnixMicro(), fileExt), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,3 +71,11 @@ func DownloadFile(fileURL string, filepath string, proxy string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetImgExt(filename string) string {
|
||||||
|
ext := filepath.Ext(filename)
|
||||||
|
if ext == "" {
|
||||||
|
return ".png"
|
||||||
|
}
|
||||||
|
return ext
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user