mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 08:13:43 +08:00 
			
		
		
		
	opt: enable use cdn url for mj-plus
This commit is contained in:
		@@ -25,23 +25,16 @@ WeChatBot = false
 | 
				
			|||||||
  AppId = ""
 | 
					  AppId = ""
 | 
				
			||||||
  Token = ""
 | 
					  Token = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SmsConfig] # 阿里云短信服务配置
 | 
					 | 
				
			||||||
  AccessKey = ""
 | 
					 | 
				
			||||||
  AccessSecret = ""
 | 
					 | 
				
			||||||
  Product = "Dysmsapi"
 | 
					 | 
				
			||||||
  Domain = "dysmsapi.aliyuncs.com"
 | 
					 | 
				
			||||||
  Sign = ""
 | 
					 | 
				
			||||||
  CodeTempId = ""
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
[Sms] # Sms 配置,用于发送短信
 | 
					[SMS] # Sms 配置,用于发送短信
 | 
				
			||||||
   Active = "Ali" # 当前启用的短信服务,默认使用阿里云
 | 
					   Active = "Ali" # 当前启用的短信服务,默认使用阿里云
 | 
				
			||||||
   [Sms.SmsBao]
 | 
					   [SMS.Bao]
 | 
				
			||||||
      Username = ""
 | 
					      Username = ""
 | 
				
			||||||
      Password = ""
 | 
					      Password = ""
 | 
				
			||||||
      Domain = "api.smsbao.com"
 | 
					      Domain = "api.smsbao.com"
 | 
				
			||||||
      Sign = "【极客学长】"
 | 
					      Sign = "【极客学长】"
 | 
				
			||||||
      CodeTemplate = "您的验证码是{code}。5分钟有效,若非本人操作,请忽略本短信。"
 | 
					      CodeTemplate = "您的验证码是{code}。5分钟有效,若非本人操作,请忽略本短信。"
 | 
				
			||||||
   [Sms.Ali]
 | 
					   [SMS.Ali]
 | 
				
			||||||
      AccessKey = ""
 | 
					      AccessKey = ""
 | 
				
			||||||
      AccessSecret = ""
 | 
					      AccessSecret = ""
 | 
				
			||||||
      Product = "Dysmsapi"
 | 
					      Product = "Dysmsapi"
 | 
				
			||||||
@@ -82,6 +75,7 @@ WeChatBot = false
 | 
				
			|||||||
[[MjPlusConfigs]]
 | 
					[[MjPlusConfigs]]
 | 
				
			||||||
  Enabled = false
 | 
					  Enabled = false
 | 
				
			||||||
  ApiURL = "https://api.chatgpt-plus.net" # 目前暂时不支持更改
 | 
					  ApiURL = "https://api.chatgpt-plus.net" # 目前暂时不支持更改
 | 
				
			||||||
 | 
					  CdnURL = "" # CND 加速的 URL,如果有的话就设置
 | 
				
			||||||
  ApiKey = "sk-xxx"
 | 
					  ApiKey = "sk-xxx"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/mj/notify" # 这里需要改成你的域名
 | 
					  NotifyURL = "https://ai.r9it.com/api/mj/notify" # 这里需要改成你的域名
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -113,9 +107,9 @@ WeChatBot = false
 | 
				
			|||||||
[HuPiPayConfig]
 | 
					[HuPiPayConfig]
 | 
				
			||||||
  Enabled = false
 | 
					  Enabled = false
 | 
				
			||||||
  Name = "wechat"
 | 
					  Name = "wechat"
 | 
				
			||||||
  AppId = "201906161477"
 | 
					  AppId = ""
 | 
				
			||||||
  AppSecret = "7f403199d510fb2c6f0b9f2311800e7c"
 | 
					  AppSecret = ""
 | 
				
			||||||
  PayURL = "https://api.xunhupay.com/payment/do.html"
 | 
					  ApiURL = "https://api.xunhupay.com"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/payment/hupipay/notify"
 | 
					  NotifyURL = "https://ai.r9it.com/api/payment/hupipay/notify"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SmtpConfig] # 注意,阿里云服务器禁用了25号端口,所以如果需要使用邮件功能,请别用阿里云服务器
 | 
					[SmtpConfig] # 注意,阿里云服务器禁用了25号端口,所以如果需要使用邮件功能,请别用阿里云服务器
 | 
				
			||||||
@@ -130,5 +124,5 @@ WeChatBot = false
 | 
				
			|||||||
  Name = "wechat" # 请不要改动
 | 
					  Name = "wechat" # 请不要改动
 | 
				
			||||||
  AppId = "" # 商户 ID
 | 
					  AppId = "" # 商户 ID
 | 
				
			||||||
  PrivateKey = "" # 秘钥
 | 
					  PrivateKey = "" # 秘钥
 | 
				
			||||||
  ApiURL = "https://payjs.cn/api/native"
 | 
					  ApiURL = "https://payjs.cn"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/payment/payjs/notify" # 异步回调地址,域名改成你自己的
 | 
					  NotifyURL = "https://ai.r9it.com/api/payment/payjs/notify" # 异步回调地址,域名改成你自己的
 | 
				
			||||||
@@ -19,7 +19,6 @@ type AppConfig struct {
 | 
				
			|||||||
	OSS           OSSConfig               // OSS config
 | 
						OSS           OSSConfig               // OSS config
 | 
				
			||||||
	MjConfigs     []MidJourneyConfig      // mj AI draw service pool
 | 
						MjConfigs     []MidJourneyConfig      // mj AI draw service pool
 | 
				
			||||||
	MjPlusConfigs []MidJourneyPlusConfig  // MJ plus config
 | 
						MjPlusConfigs []MidJourneyPlusConfig  // MJ plus config
 | 
				
			||||||
	ImgCdnURL     string                  // 图片反代加速地址
 | 
					 | 
				
			||||||
	WeChatBot     bool                    // 是否启用微信机器人
 | 
						WeChatBot     bool                    // 是否启用微信机器人
 | 
				
			||||||
	SdConfigs     []StableDiffusionConfig // sd AI draw service pool
 | 
						SdConfigs     []StableDiffusionConfig // sd AI draw service pool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,6 +50,7 @@ type MidJourneyConfig struct {
 | 
				
			|||||||
	GuildId        string // Server ID
 | 
						GuildId        string // Server ID
 | 
				
			||||||
	ChanelId       string // Chanel ID
 | 
						ChanelId       string // Chanel ID
 | 
				
			||||||
	UseCDN         bool
 | 
						UseCDN         bool
 | 
				
			||||||
 | 
						ImgCdnURL      string // 图片反代加速地址
 | 
				
			||||||
	DiscordAPI     string
 | 
						DiscordAPI     string
 | 
				
			||||||
	DiscordGateway string
 | 
						DiscordGateway string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -63,8 +63,9 @@ type StableDiffusionConfig struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MidJourneyPlusConfig struct {
 | 
					type MidJourneyPlusConfig struct {
 | 
				
			||||||
	Enabled   bool // 如果启用了 MidJourney Plus,将会自动禁用原生的MidJourney服务
 | 
						Enabled   bool   // 如果启用了 MidJourney Plus,将会自动禁用原生的MidJourney服务
 | 
				
			||||||
	ApiURL    string
 | 
						ApiURL    string // api 地址
 | 
				
			||||||
 | 
						CdnURL    string // CDN 加速地址
 | 
				
			||||||
	ApiKey    string
 | 
						ApiKey    string
 | 
				
			||||||
	NotifyURL string // 任务进度更新回调地址
 | 
						NotifyURL string // 任务进度更新回调地址
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ const (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// MjTask MidJourney 任务
 | 
					// MjTask MidJourney 任务
 | 
				
			||||||
type MjTask struct {
 | 
					type MjTask struct {
 | 
				
			||||||
	Id          int      `json:"id"`
 | 
						Id          uint     `json:"id"`
 | 
				
			||||||
	TaskId      string   `json:"task_id"`
 | 
						TaskId      string   `json:"task_id"`
 | 
				
			||||||
	ImgArr      []string `json:"img_arr"`
 | 
						ImgArr      []string `json:"img_arr"`
 | 
				
			||||||
	ChannelId   string   `json:"channel_id"`
 | 
						ChannelId   string   `json:"channel_id"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -168,7 +168,7 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	h.pool.PushTask(types.MjTask{
 | 
						h.pool.PushTask(types.MjTask{
 | 
				
			||||||
		Id:        int(job.Id),
 | 
							Id:        job.Id,
 | 
				
			||||||
		TaskId:    taskId,
 | 
							TaskId:    taskId,
 | 
				
			||||||
		SessionId: data.SessionId,
 | 
							SessionId: data.SessionId,
 | 
				
			||||||
		Type:      types.TaskType(data.TaskType),
 | 
							Type:      types.TaskType(data.TaskType),
 | 
				
			||||||
@@ -178,7 +178,9 @@ func (h *MidJourneyHandler) Image(c *gin.Context) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client := h.pool.Clients.Get(uint(job.UserId))
 | 
						client := h.pool.Clients.Get(uint(job.UserId))
 | 
				
			||||||
	_ = client.Send([]byte("Task Updated"))
 | 
						if client != nil {
 | 
				
			||||||
 | 
							_ = client.Send([]byte("Task Updated"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// update user's img calls
 | 
						// update user's img calls
 | 
				
			||||||
	h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1))
 | 
						h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1))
 | 
				
			||||||
@@ -227,7 +229,7 @@ func (h *MidJourneyHandler) Upscale(c *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	h.pool.PushTask(types.MjTask{
 | 
						h.pool.PushTask(types.MjTask{
 | 
				
			||||||
		Id:          int(job.Id),
 | 
							Id:          job.Id,
 | 
				
			||||||
		SessionId:   data.SessionId,
 | 
							SessionId:   data.SessionId,
 | 
				
			||||||
		Type:        types.TaskUpscale,
 | 
							Type:        types.TaskUpscale,
 | 
				
			||||||
		Prompt:      data.Prompt,
 | 
							Prompt:      data.Prompt,
 | 
				
			||||||
@@ -239,7 +241,9 @@ func (h *MidJourneyHandler) Upscale(c *gin.Context) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client := h.pool.Clients.Get(uint(job.UserId))
 | 
						client := h.pool.Clients.Get(uint(job.UserId))
 | 
				
			||||||
	_ = client.Send([]byte("Task Updated"))
 | 
						if client != nil {
 | 
				
			||||||
 | 
							_ = client.Send([]byte("Task Updated"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	resp.SUCCESS(c)
 | 
						resp.SUCCESS(c)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -275,7 +279,7 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	h.pool.PushTask(types.MjTask{
 | 
						h.pool.PushTask(types.MjTask{
 | 
				
			||||||
		Id:          int(job.Id),
 | 
							Id:          job.Id,
 | 
				
			||||||
		SessionId:   data.SessionId,
 | 
							SessionId:   data.SessionId,
 | 
				
			||||||
		Type:        types.TaskVariation,
 | 
							Type:        types.TaskVariation,
 | 
				
			||||||
		Prompt:      data.Prompt,
 | 
							Prompt:      data.Prompt,
 | 
				
			||||||
@@ -287,7 +291,9 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client := h.pool.Clients.Get(uint(job.UserId))
 | 
						client := h.pool.Clients.Get(uint(job.UserId))
 | 
				
			||||||
	_ = client.Send([]byte("Task Updated"))
 | 
						if client != nil {
 | 
				
			||||||
 | 
							_ = client.Send([]byte("Task Updated"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// update user's img calls
 | 
						// update user's img calls
 | 
				
			||||||
	h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1))
 | 
						h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1))
 | 
				
			||||||
@@ -340,8 +346,8 @@ func (h *MidJourneyHandler) JobList(c *gin.Context) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if item.Progress < 100 && item.ImgURL == "" && item.OrgURL != "" {
 | 
							if item.Progress < 100 && item.ImgURL == "" && item.OrgURL != "" {
 | 
				
			||||||
			// 正在运行中任务使用代理访问图片
 | 
								// 正在运行中任务使用代理访问图片
 | 
				
			||||||
			if h.App.Config.ImgCdnURL != "" {
 | 
								if job.UseProxy {
 | 
				
			||||||
				job.ImgURL = strings.ReplaceAll(job.OrgURL, "https://cdn.discordapp.com", h.App.Config.ImgCdnURL)
 | 
									job.ImgURL = job.OrgURL
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				image, err := utils.DownloadImage(item.OrgURL, h.App.Config.ProxyURL)
 | 
									image, err := utils.DownloadImage(item.OrgURL, h.App.Config.ProxyURL)
 | 
				
			||||||
				if err == nil {
 | 
									if err == nil {
 | 
				
			||||||
@@ -381,7 +387,9 @@ func (h *MidJourneyHandler) Remove(c *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	client := h.pool.Clients.Get(data.UserId)
 | 
						client := h.pool.Clients.Get(data.UserId)
 | 
				
			||||||
	_ = client.Send([]byte("Task Updated"))
 | 
						if client != nil {
 | 
				
			||||||
 | 
							_ = client.Send([]byte("Task Updated"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	resp.SUCCESS(c)
 | 
						resp.SUCCESS(c)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,13 +12,12 @@ import (
 | 
				
			|||||||
// MidJourney client
 | 
					// MidJourney client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Client struct {
 | 
					type Client struct {
 | 
				
			||||||
	client    *req.Client
 | 
						client *req.Client
 | 
				
			||||||
	Config    types.MidJourneyConfig
 | 
						Config types.MidJourneyConfig
 | 
				
			||||||
	imgCdnURL string
 | 
						apiURL string
 | 
				
			||||||
	apiURL    string
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewClient(config types.MidJourneyConfig, proxy string, imgCdnURL string) *Client {
 | 
					func NewClient(config types.MidJourneyConfig, proxy string) *Client {
 | 
				
			||||||
	client := req.C().SetTimeout(10 * time.Second)
 | 
						client := req.C().SetTimeout(10 * time.Second)
 | 
				
			||||||
	var apiURL string
 | 
						var apiURL string
 | 
				
			||||||
	// set proxy URL
 | 
						// set proxy URL
 | 
				
			||||||
@@ -31,7 +30,7 @@ func NewClient(config types.MidJourneyConfig, proxy string, imgCdnURL string) *C
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &Client{client: client, Config: config, apiURL: apiURL, imgCdnURL: imgCdnURL}
 | 
						return &Client{client: client, Config: config, apiURL: apiURL}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Client) Imagine(task types.MjTask) error {
 | 
					func (c *Client) Imagine(task types.MjTask) error {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,10 @@ import (
 | 
				
			|||||||
	"encoding/base64"
 | 
						"encoding/base64"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/imroc/req/v3"
 | 
						"github.com/imroc/req/v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -18,10 +19,17 @@ var logger = logger2.GetLogger()
 | 
				
			|||||||
// Client MidJourney Plus Client
 | 
					// Client MidJourney Plus Client
 | 
				
			||||||
type Client struct {
 | 
					type Client struct {
 | 
				
			||||||
	Config types.MidJourneyPlusConfig
 | 
						Config types.MidJourneyPlusConfig
 | 
				
			||||||
 | 
						apiURL string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewClient(config types.MidJourneyPlusConfig) *Client {
 | 
					func NewClient(config types.MidJourneyPlusConfig) *Client {
 | 
				
			||||||
	return &Client{Config: config}
 | 
						var apiURL string
 | 
				
			||||||
 | 
						if config.CdnURL != "" {
 | 
				
			||||||
 | 
							apiURL = config.CdnURL
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							apiURL = config.ApiURL
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return &Client{Config: config, apiURL: apiURL}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ImageReq struct {
 | 
					type ImageReq struct {
 | 
				
			||||||
@@ -54,12 +62,12 @@ type ErrRes struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
 | 
					func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/imagine", c.Config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/imagine", c.apiURL)
 | 
				
			||||||
	body := ImageReq{
 | 
						body := ImageReq{
 | 
				
			||||||
		BotType:     "MID_JOURNEY",
 | 
							BotType:     "MID_JOURNEY",
 | 
				
			||||||
		Prompt:      task.Prompt,
 | 
							Prompt:      task.Prompt,
 | 
				
			||||||
		NotifyHook:  c.Config.NotifyURL,
 | 
							NotifyHook:  c.Config.NotifyURL,
 | 
				
			||||||
		Base64Array: make([]string, 1),
 | 
							Base64Array: make([]string, 0),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// 生成图片 Base64 编码
 | 
						// 生成图片 Base64 编码
 | 
				
			||||||
	if len(task.ImgArr) > 0 {
 | 
						if len(task.ImgArr) > 0 {
 | 
				
			||||||
@@ -67,7 +75,7 @@ func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logger.Error("error with download image: ", err)
 | 
								logger.Error("error with download image: ", err)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			body.Base64Array[0] = "data:image/png;base64," + base64.StdEncoding.EncodeToString(imageData)
 | 
								body.Base64Array = append(body.Base64Array, "data:image/png;base64,"+base64.StdEncoding.EncodeToString(imageData))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -80,12 +88,12 @@ func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
		SetErrorResult(&errRes).
 | 
							SetErrorResult(&errRes).
 | 
				
			||||||
		Post(apiURL)
 | 
							Post(apiURL)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		errStr, _ := io.ReadAll(r.Body)
 | 
							return ImageRes{}, fmt.Errorf("请求 API 出错:%v", err)
 | 
				
			||||||
		return ImageRes{}, fmt.Errorf("请求 API 出错:%v,%v", err, string(errStr))
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if r.IsErrorState() {
 | 
						if r.IsErrorState() {
 | 
				
			||||||
		return ImageRes{}, fmt.Errorf("API 返回错误:%s", errRes.Error.Message)
 | 
							errStr, _ := io.ReadAll(r.Body)
 | 
				
			||||||
 | 
							return ImageRes{}, fmt.Errorf("API 返回错误:%s,%v", errRes.Error.Message, string(errStr))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return res, nil
 | 
						return res, nil
 | 
				
			||||||
@@ -93,7 +101,7 @@ func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Blend 融图
 | 
					// Blend 融图
 | 
				
			||||||
func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
 | 
					func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/blend", c.Config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/blend", c.apiURL)
 | 
				
			||||||
	body := ImageReq{
 | 
						body := ImageReq{
 | 
				
			||||||
		BotType:     "MID_JOURNEY",
 | 
							BotType:     "MID_JOURNEY",
 | 
				
			||||||
		Dimensions:  "SQUARE",
 | 
							Dimensions:  "SQUARE",
 | 
				
			||||||
@@ -133,7 +141,7 @@ func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// SwapFace 换脸
 | 
					// SwapFace 换脸
 | 
				
			||||||
func (c *Client) SwapFace(task types.MjTask) (ImageRes, error) {
 | 
					func (c *Client) SwapFace(task types.MjTask) (ImageRes, error) {
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj-fast/mj/insight-face/swap", c.Config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/mj-fast/mj/insight-face/swap", c.apiURL)
 | 
				
			||||||
	// 生成图片 Base64 编码
 | 
						// 生成图片 Base64 编码
 | 
				
			||||||
	if len(task.ImgArr) != 2 {
 | 
						if len(task.ImgArr) != 2 {
 | 
				
			||||||
		return ImageRes{}, errors.New("参数错误,必须上传2张图片")
 | 
							return ImageRes{}, errors.New("参数错误,必须上传2张图片")
 | 
				
			||||||
@@ -189,7 +197,7 @@ func (c *Client) Upscale(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
		"taskId":     task.MessageId,
 | 
							"taskId":     task.MessageId,
 | 
				
			||||||
		"notifyHook": c.Config.NotifyURL,
 | 
							"notifyHook": c.Config.NotifyURL,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj/submit/action", c.Config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/mj/submit/action", c.apiURL)
 | 
				
			||||||
	var res ImageRes
 | 
						var res ImageRes
 | 
				
			||||||
	var errRes ErrRes
 | 
						var errRes ErrRes
 | 
				
			||||||
	r, err := req.C().R().
 | 
						r, err := req.C().R().
 | 
				
			||||||
@@ -216,7 +224,7 @@ func (c *Client) Variation(task types.MjTask) (ImageRes, error) {
 | 
				
			|||||||
		"taskId":     task.MessageId,
 | 
							"taskId":     task.MessageId,
 | 
				
			||||||
		"notifyHook": c.Config.NotifyURL,
 | 
							"notifyHook": c.Config.NotifyURL,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj/submit/action", c.Config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/mj/submit/action", c.apiURL)
 | 
				
			||||||
	var res ImageRes
 | 
						var res ImageRes
 | 
				
			||||||
	var errRes ErrRes
 | 
						var errRes ErrRes
 | 
				
			||||||
	r, err := req.C().R().
 | 
						r, err := req.C().R().
 | 
				
			||||||
@@ -262,7 +270,7 @@ type QueryRes struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *Client) QueryTask(taskId string) (QueryRes, error) {
 | 
					func (c *Client) QueryTask(taskId string) (QueryRes, error) {
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/mj/task/%s/fetch", c.Config.ApiURL, taskId)
 | 
						apiURL := fmt.Sprintf("%s/mj/task/%s/fetch", c.apiURL, taskId)
 | 
				
			||||||
	var res QueryRes
 | 
						var res QueryRes
 | 
				
			||||||
	r, err := req.C().R().SetHeader("Authorization", "Bearer "+c.Config.ApiKey).
 | 
						r, err := req.C().R().SetHeader("Authorization", "Bearer "+c.Config.ApiKey).
 | 
				
			||||||
		SetSuccessResult(&res).
 | 
							SetSuccessResult(&res).
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,10 +86,10 @@ func (s *Service) Run() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if err != nil || (res.Code != 1 && res.Code != 22) {
 | 
							if err != nil || (res.Code != 1 && res.Code != 22) {
 | 
				
			||||||
			errMsg := err.Error() + res.Description
 | 
								errMsg := fmt.Sprintf("%v,%s", err, res.Description)
 | 
				
			||||||
			logger.Error("绘画任务执行失败:", errMsg)
 | 
								logger.Error("绘画任务执行失败:", errMsg)
 | 
				
			||||||
			// update the task progress
 | 
								// update the task progress
 | 
				
			||||||
			s.db.Model(&model.MidJourneyJob{Id: uint(task.Id)}).UpdateColumns(map[string]interface{}{
 | 
								s.db.Model(&model.MidJourneyJob{Id: task.Id}).UpdateColumns(map[string]interface{}{
 | 
				
			||||||
				"progress": -1,
 | 
									"progress": -1,
 | 
				
			||||||
				"err_msg":  errMsg,
 | 
									"err_msg":  errMsg,
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
@@ -105,10 +105,10 @@ func (s *Service) Run() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		logger.Infof("任务提交成功:%+v", res)
 | 
							logger.Infof("任务提交成功:%+v", res)
 | 
				
			||||||
		// lock the task until the execute timeout
 | 
							// lock the task until the execute timeout
 | 
				
			||||||
		s.taskStartTimes[task.Id] = time.Now()
 | 
							s.taskStartTimes[int(task.Id)] = time.Now()
 | 
				
			||||||
		atomic.AddInt32(&s.HandledTaskNum, 1)
 | 
							atomic.AddInt32(&s.HandledTaskNum, 1)
 | 
				
			||||||
		// 更新任务 ID/频道
 | 
							// 更新任务 ID/频道
 | 
				
			||||||
		s.db.Model(&model.MidJourneyJob{}).Where("id = ?", task.Id).UpdateColumns(map[string]interface{}{
 | 
							s.db.Debug().Model(&model.MidJourneyJob{Id: task.Id}).UpdateColumns(map[string]interface{}{
 | 
				
			||||||
			"task_id":    res.Result,
 | 
								"task_id":    res.Result,
 | 
				
			||||||
			"channel_id": s.Name,
 | 
								"channel_id": s.Name,
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
@@ -152,26 +152,55 @@ type CBReq struct {
 | 
				
			|||||||
	} `json:"properties"`
 | 
						} `json:"properties"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Service) Notify(data CBReq, job model.MidJourneyJob) error {
 | 
					func (s *Service) Notify(job model.MidJourneyJob) error {
 | 
				
			||||||
 | 
						task, err := s.Client.QueryTask(job.TaskId)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	job.Progress = utils.IntValue(strings.Replace(data.Progress, "%", "", 1), 0)
 | 
						// 任务执行失败了
 | 
				
			||||||
	job.Prompt = data.Properties.FinalPrompt
 | 
						if task.FailReason != "" {
 | 
				
			||||||
	if data.ImageUrl != "" {
 | 
							s.db.Model(&model.MidJourneyJob{Id: job.Id}).UpdateColumns(map[string]interface{}{
 | 
				
			||||||
		job.OrgURL = data.ImageUrl
 | 
								"progress": -1,
 | 
				
			||||||
 | 
								"err_msg":  task.FailReason,
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
							return fmt.Errorf("task failed: %v", task.FailReason)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(task.Buttons) > 0 {
 | 
				
			||||||
 | 
							job.Hash = GetImageHash(task.Buttons[0].CustomId)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						oldProgress := job.Progress
 | 
				
			||||||
 | 
						job.Progress = utils.IntValue(strings.Replace(task.Progress, "%", "", 1), 0)
 | 
				
			||||||
 | 
						job.Prompt = task.PromptEn
 | 
				
			||||||
 | 
						if task.ImageUrl != "" {
 | 
				
			||||||
 | 
							if s.Client.Config.CdnURL != "" {
 | 
				
			||||||
 | 
								job.OrgURL = strings.Replace(task.ImageUrl, s.Client.Config.ApiURL, s.Client.Config.CdnURL, 1)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								job.OrgURL = task.ImageUrl
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	job.UseProxy = true
 | 
						job.UseProxy = true
 | 
				
			||||||
	job.MessageId = data.Id
 | 
						job.MessageId = task.Id
 | 
				
			||||||
	logger.Debugf("JOB: %+v", job)
 | 
						tx := s.db.Updates(&job)
 | 
				
			||||||
	res := s.db.Updates(&job)
 | 
						if tx.Error != nil {
 | 
				
			||||||
	if res.Error != nil {
 | 
							return fmt.Errorf("error with update database: %v", tx.Error)
 | 
				
			||||||
		return fmt.Errorf("error with update job: %v", res.Error)
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if task.Status == "SUCCESS" {
 | 
				
			||||||
	if data.Status == "SUCCESS" {
 | 
					 | 
				
			||||||
		// release lock task
 | 
							// release lock task
 | 
				
			||||||
		atomic.AddInt32(&s.HandledTaskNum, -1)
 | 
							atomic.AddInt32(&s.HandledTaskNum, -1)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// 通知前端更新任务进度
 | 
				
			||||||
	s.notifyQueue.RPush(job.UserId)
 | 
						if oldProgress != job.Progress {
 | 
				
			||||||
 | 
							s.notifyQueue.RPush(job.UserId)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetImageHash(action string) string {
 | 
				
			||||||
 | 
						split := strings.Split(action, "::")
 | 
				
			||||||
 | 
						if len(split) > 5 {
 | 
				
			||||||
 | 
							return split[4]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return split[len(split)-1]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,11 +6,9 @@ import (
 | 
				
			|||||||
	"chatplus/service/oss"
 | 
						"chatplus/service/oss"
 | 
				
			||||||
	"chatplus/store"
 | 
						"chatplus/store"
 | 
				
			||||||
	"chatplus/store/model"
 | 
						"chatplus/store/model"
 | 
				
			||||||
	"chatplus/utils"
 | 
					 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"github.com/go-redis/redis/v8"
 | 
						"github.com/go-redis/redis/v8"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync/atomic"
 | 
					 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
@@ -35,9 +33,8 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
 | 
				
			|||||||
		if config.Enabled == false {
 | 
							if config.Enabled == false {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if config.ApiURL != "https://gpt.bemore.lol" && config.ApiURL != "https://api.chat-plus.net" {
 | 
							// rewrite api key
 | 
				
			||||||
			config.ApiURL = "https://api.chat-plus.net"
 | 
							config.ApiURL = "https://api.chat-plus.net"
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		client := plus.NewClient(config)
 | 
							client := plus.NewClient(config)
 | 
				
			||||||
		name := fmt.Sprintf("mj-service-plus-%d", k)
 | 
							name := fmt.Sprintf("mj-service-plus-%d", k)
 | 
				
			||||||
		servicePlus := plus.NewService(name, taskQueue, notifyQueue, 10, 600, db, client)
 | 
							servicePlus := plus.NewService(name, taskQueue, notifyQueue, 10, 600, db, client)
 | 
				
			||||||
@@ -54,7 +51,7 @@ func NewServicePool(db *gorm.DB, redisCli *redis.Client, manager *oss.UploaderMa
 | 
				
			|||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			// create mj client
 | 
								// create mj client
 | 
				
			||||||
			client := NewClient(config, appConfig.ProxyURL, appConfig.ImgCdnURL)
 | 
								client := NewClient(config, appConfig.ProxyURL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			name := fmt.Sprintf("MjService-%d", k)
 | 
								name := fmt.Sprintf("MjService-%d", k)
 | 
				
			||||||
			// create mj service
 | 
								// create mj service
 | 
				
			||||||
@@ -98,6 +95,9 @@ func (p *ServicePool) CheckTaskNotify() {
 | 
				
			|||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			client := p.Clients.Get(userId)
 | 
								client := p.Clients.Get(userId)
 | 
				
			||||||
 | 
								if client == nil {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			err = client.Send([]byte("Task Updated"))
 | 
								err = client.Send([]byte("Task Updated"))
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
@@ -120,17 +120,17 @@ func (p *ServicePool) DownloadImages() {
 | 
				
			|||||||
				if v.OrgURL == "" {
 | 
									if v.OrgURL == "" {
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									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 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 task.ImageUrl != "" {
 | 
					 | 
				
			||||||
							imgURL, err = p.uploaderManager.GetUploadHandler().PutImg(task.ImageUrl, false)
 | 
					 | 
				
			||||||
						}
 | 
					 | 
				
			||||||
						if len(task.Buttons) > 0 {
 | 
											if len(task.Buttons) > 0 {
 | 
				
			||||||
							v.Hash = getImageHash(task.Buttons[0].CustomId)
 | 
												v.Hash = plus.GetImageHash(task.Buttons[0].CustomId)
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
 | 
											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)
 | 
				
			||||||
@@ -138,12 +138,17 @@ func (p *ServicePool) DownloadImages() {
 | 
				
			|||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					logger.Error("error with download image: ", err)
 | 
										logger.Error("error with download image: ", err)
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										logger.Info("download image %v successfully.", v.OrgURL)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				v.ImgURL = imgURL
 | 
									v.ImgURL = imgURL
 | 
				
			||||||
				p.db.Updates(&v)
 | 
									p.db.Updates(&v)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				client := p.Clients.Get(uint(v.UserId))
 | 
									client := p.Clients.Get(uint(v.UserId))
 | 
				
			||||||
 | 
									if client == nil {
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				err = client.Send([]byte("Task Updated"))
 | 
									err = client.Send([]byte("Task Updated"))
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
@@ -179,7 +184,7 @@ func (p *ServicePool) Notify(data plus.CBReq) error {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if servicePlus := p.getServicePlus(job.ChannelId); servicePlus != nil {
 | 
						if servicePlus := p.getServicePlus(job.ChannelId); servicePlus != nil {
 | 
				
			||||||
		return servicePlus.Notify(data, job)
 | 
							return servicePlus.Notify(job)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
@@ -211,40 +216,7 @@ func (p *ServicePool) SyncTaskProgress() {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if servicePlus := p.getServicePlus(v.ChannelId); servicePlus != nil {
 | 
									if servicePlus := p.getServicePlus(v.ChannelId); servicePlus != nil {
 | 
				
			||||||
					task, err := servicePlus.Client.QueryTask(v.TaskId)
 | 
										_ = servicePlus.Notify(v)
 | 
				
			||||||
					if err != nil {
 | 
					 | 
				
			||||||
						continue
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					// 任务失败了
 | 
					 | 
				
			||||||
					if task.FailReason != "" {
 | 
					 | 
				
			||||||
						p.db.Model(&model.MidJourneyJob{Id: v.Id}).UpdateColumns(map[string]interface{}{
 | 
					 | 
				
			||||||
							"progress": -1,
 | 
					 | 
				
			||||||
							"err_msg":  task.FailReason,
 | 
					 | 
				
			||||||
						})
 | 
					 | 
				
			||||||
						continue
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					if len(task.Buttons) > 0 {
 | 
					 | 
				
			||||||
						v.Hash = getImageHash(task.Buttons[0].CustomId)
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					oldProgress := v.Progress
 | 
					 | 
				
			||||||
					v.Progress = utils.IntValue(strings.Replace(task.Progress, "%", "", 1), 0)
 | 
					 | 
				
			||||||
					v.Prompt = task.PromptEn
 | 
					 | 
				
			||||||
					if task.ImageUrl != "" {
 | 
					 | 
				
			||||||
						v.OrgURL = task.ImageUrl
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					v.UseProxy = true
 | 
					 | 
				
			||||||
					v.MessageId = task.Id
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					p.db.Updates(&v)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
					if task.Status == "SUCCESS" {
 | 
					 | 
				
			||||||
						// release lock task
 | 
					 | 
				
			||||||
						atomic.AddInt32(&servicePlus.HandledTaskNum, -1)
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					// 通知前端更新任务进度
 | 
					 | 
				
			||||||
					if oldProgress != v.Progress {
 | 
					 | 
				
			||||||
						p.notifyQueue.RPush(v.UserId)
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -263,11 +235,3 @@ func (p *ServicePool) getServicePlus(name string) *plus.Service {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func getImageHash(action string) string {
 | 
					 | 
				
			||||||
	split := strings.Split(action, "::")
 | 
					 | 
				
			||||||
	if len(split) > 5 {
 | 
					 | 
				
			||||||
		return split[4]
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return split[len(split)-1]
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -97,7 +97,7 @@ func (s *Service) Run() {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// lock the task until the execute timeout
 | 
							// lock the task until the execute timeout
 | 
				
			||||||
		s.taskStartTimes[task.Id] = time.Now()
 | 
							s.taskStartTimes[int(task.Id)] = time.Now()
 | 
				
			||||||
		atomic.AddInt32(&s.handledTaskNum, 1)
 | 
							atomic.AddInt32(&s.handledTaskNum, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -152,7 +152,7 @@ func (s *Service) Notify(data CBReq) {
 | 
				
			|||||||
	job.OrgURL = data.Image.URL
 | 
						job.OrgURL = data.Image.URL
 | 
				
			||||||
	if s.client.Config.UseCDN {
 | 
						if s.client.Config.UseCDN {
 | 
				
			||||||
		job.UseProxy = true
 | 
							job.UseProxy = true
 | 
				
			||||||
		job.ImgURL = strings.ReplaceAll(data.Image.URL, "https://cdn.discordapp.com", s.client.imgCdnURL)
 | 
							job.ImgURL = strings.ReplaceAll(data.Image.URL, "https://cdn.discordapp.com", s.client.Config.ImgCdnURL)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res = s.db.Updates(&job)
 | 
						res = s.db.Updates(&job)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,7 +56,7 @@ func (js *PayJS) Pay(param JPayReq) JPayReps {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	p.Add("mchid", js.config.AppId)
 | 
						p.Add("mchid", js.config.AppId)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p.Add("Sign", js.sign(p))
 | 
						p.Add("sign", js.sign(p))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cli := http.Client{}
 | 
						cli := http.Client{}
 | 
				
			||||||
	apiURL := fmt.Sprintf("%s/api/native", js.config.ApiURL)
 | 
						apiURL := fmt.Sprintf("%s/api/native", js.config.ApiURL)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,11 +2,10 @@ package main
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strings"
 | 
						"net/url"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
	str := "7151109597841850368 一个漂亮的中国女孩,手上拿着一桶爆米花,脸上带着迷人的微笑,电影效果"
 | 
						u, err := url.Parse("https://api.chat-plus.net/mj/image/1706368258238514?aaa=bbb")
 | 
				
			||||||
	index := strings.Index(str, " ")
 | 
						fmt.Println(u.Path, u.RawQuery, err)
 | 
				
			||||||
	fmt.Println(str[index+1:])
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,23 +26,15 @@ WeChatBot = false
 | 
				
			|||||||
  AppId = ""
 | 
					  AppId = ""
 | 
				
			||||||
  Token = ""
 | 
					  Token = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SmsConfig] # 阿里云短信服务配置
 | 
					[SMS] # Sms 配置,用于发送短信
 | 
				
			||||||
  AccessKey = ""
 | 
					 | 
				
			||||||
  AccessSecret = ""
 | 
					 | 
				
			||||||
  Product = "Dysmsapi"
 | 
					 | 
				
			||||||
  Domain = "dysmsapi.aliyuncs.com"
 | 
					 | 
				
			||||||
  Sign = ""
 | 
					 | 
				
			||||||
  CodeTempId = ""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[Sms] # Sms 配置,用于发送短信
 | 
					 | 
				
			||||||
   Active = "Ali" # 当前启用的短信服务,默认使用阿里云
 | 
					   Active = "Ali" # 当前启用的短信服务,默认使用阿里云
 | 
				
			||||||
   [Sms.SmsBao]
 | 
					   [SMS.Bao]
 | 
				
			||||||
      Username = ""
 | 
					      Username = ""
 | 
				
			||||||
      Password = ""
 | 
					      Password = ""
 | 
				
			||||||
      Domain = "api.smsbao.com"
 | 
					      Domain = "api.smsbao.com"
 | 
				
			||||||
      Sign = "【极客学长】"
 | 
					      Sign = "【极客学长】"
 | 
				
			||||||
      CodeTemplate = "您的验证码是{code}。5分钟有效,若非本人操作,请忽略本短信。"
 | 
					      CodeTemplate = "您的验证码是{code}。5分钟有效,若非本人操作,请忽略本短信。"
 | 
				
			||||||
   [Sms.Ali]
 | 
					   [SMS.Ali]
 | 
				
			||||||
      AccessKey = ""
 | 
					      AccessKey = ""
 | 
				
			||||||
      AccessSecret = ""
 | 
					      AccessSecret = ""
 | 
				
			||||||
      Product = "Dysmsapi"
 | 
					      Product = "Dysmsapi"
 | 
				
			||||||
@@ -83,6 +75,7 @@ WeChatBot = false
 | 
				
			|||||||
[[MjPlusConfigs]]
 | 
					[[MjPlusConfigs]]
 | 
				
			||||||
  Enabled = false
 | 
					  Enabled = false
 | 
				
			||||||
  ApiURL = "https://api.chatgpt-plus.net" # 目前暂时不支持更改
 | 
					  ApiURL = "https://api.chatgpt-plus.net" # 目前暂时不支持更改
 | 
				
			||||||
 | 
					  CdnURL = "" # CND 加速的 URL,如果有的话就设置
 | 
				
			||||||
  ApiKey = "sk-xxx"
 | 
					  ApiKey = "sk-xxx"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/mj/notify" # 这里需要改成你的域名
 | 
					  NotifyURL = "https://ai.r9it.com/api/mj/notify" # 这里需要改成你的域名
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,9 +107,9 @@ WeChatBot = false
 | 
				
			|||||||
[HuPiPayConfig]
 | 
					[HuPiPayConfig]
 | 
				
			||||||
  Enabled = false
 | 
					  Enabled = false
 | 
				
			||||||
  Name = "wechat"
 | 
					  Name = "wechat"
 | 
				
			||||||
  AppId = "201906161477"
 | 
					  AppId = ""
 | 
				
			||||||
  AppSecret = "7f403199d510fb2c6f0b9f2311800e7c"
 | 
					  AppSecret = ""
 | 
				
			||||||
  PayURL = "https://api.xunhupay.com/payment/do.html"
 | 
					  ApiURL = "https://api.xunhupay.com"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/payment/hupipay/notify"
 | 
					  NotifyURL = "https://ai.r9it.com/api/payment/hupipay/notify"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[SmtpConfig] # 注意,阿里云服务器禁用了25号端口,所以如果需要使用邮件功能,请别用阿里云服务器
 | 
					[SmtpConfig] # 注意,阿里云服务器禁用了25号端口,所以如果需要使用邮件功能,请别用阿里云服务器
 | 
				
			||||||
@@ -131,5 +124,5 @@ WeChatBot = false
 | 
				
			|||||||
  Name = "wechat" # 请不要改动
 | 
					  Name = "wechat" # 请不要改动
 | 
				
			||||||
  AppId = "" # 商户 ID
 | 
					  AppId = "" # 商户 ID
 | 
				
			||||||
  PrivateKey = "" # 秘钥
 | 
					  PrivateKey = "" # 秘钥
 | 
				
			||||||
  ApiURL = "https://payjs.cn/api/native"
 | 
					  ApiURL = "https://payjs.cn"
 | 
				
			||||||
  NotifyURL = "https://ai.r9it.com/api/payment/payjs/notify" # 异步回调地址,域名改成你自己的
 | 
					  NotifyURL = "https://ai.r9it.com/api/payment/payjs/notify" # 异步回调地址,域名改成你自己的
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								web/public/images/mic.gif
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								web/public/images/mic.gif
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 38 KiB  | 
@@ -27,7 +27,11 @@
 | 
				
			|||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          .button-voice {
 | 
					          .button-voice {
 | 
				
			||||||
            padding 0 5px
 | 
					            padding 0 2px
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            .el-icon {
 | 
				
			||||||
 | 
					              font-size 24px
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            height 30px
 | 
					            height 30px
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -52,6 +56,16 @@
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.van-overlay {
 | 
				
			||||||
 | 
					  .mic-wrapper {
 | 
				
			||||||
 | 
					    display flex
 | 
				
			||||||
 | 
					    height 100vh
 | 
				
			||||||
 | 
					    justify-content center
 | 
				
			||||||
 | 
					    align-items center
 | 
				
			||||||
 | 
					    flex-flow column
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.van-theme-dark {
 | 
					.van-theme-dark {
 | 
				
			||||||
  .mobile-chat {
 | 
					  .mobile-chat {
 | 
				
			||||||
    .message-list-box {
 | 
					    .message-list-box {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ import {
 | 
				
			|||||||
    List,
 | 
					    List,
 | 
				
			||||||
    NavBar,
 | 
					    NavBar,
 | 
				
			||||||
    Notify,
 | 
					    Notify,
 | 
				
			||||||
 | 
					    Overlay,
 | 
				
			||||||
    Picker,
 | 
					    Picker,
 | 
				
			||||||
    Popup,
 | 
					    Popup,
 | 
				
			||||||
    Search,
 | 
					    Search,
 | 
				
			||||||
@@ -65,6 +66,7 @@ app.use(Switch);
 | 
				
			|||||||
app.use(Uploader);
 | 
					app.use(Uploader);
 | 
				
			||||||
app.use(Tag);
 | 
					app.use(Tag);
 | 
				
			||||||
app.use(V3waterfall)
 | 
					app.use(V3waterfall)
 | 
				
			||||||
 | 
					app.use(Overlay)
 | 
				
			||||||
app.use(router).use(ElementPlus).mount('#app')
 | 
					app.use(router).use(ElementPlus).mount('#app')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -716,10 +716,13 @@ const fetchFinishJobs = (userId) => {
 | 
				
			|||||||
        if (jobs[i].type === 'upscale' || jobs[i].type === 'swapFace') {
 | 
					        if (jobs[i].type === 'upscale' || jobs[i].type === 'swapFace') {
 | 
				
			||||||
          jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/600/q/75'
 | 
					          jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/600/q/75'
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          jobs[i]['can_opt'] = true
 | 
					 | 
				
			||||||
          jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/480/q/75'
 | 
					          jobs[i]['thumb_url'] = jobs[i]['img_url'] + '?imageView2/1/w/480/h/480/q/75'
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (jobs[i].type === 'image' || jobs[i].type === 'variation') {
 | 
				
			||||||
 | 
					        jobs[i]['can_opt'] = true
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    finishedJobs.value = jobs
 | 
					    finishedJobs.value = jobs
 | 
				
			||||||
  }).catch(e => {
 | 
					  }).catch(e => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -64,7 +64,9 @@
 | 
				
			|||||||
            >
 | 
					            >
 | 
				
			||||||
              <template #left-icon>
 | 
					              <template #left-icon>
 | 
				
			||||||
                <van-button round type="success" class="button-voice" @click="inputVoice">
 | 
					                <van-button round type="success" class="button-voice" @click="inputVoice">
 | 
				
			||||||
                  <van-icon name="volume-o"/>
 | 
					                  <el-icon>
 | 
				
			||||||
 | 
					                    <Microphone/>
 | 
				
			||||||
 | 
					                  </el-icon>
 | 
				
			||||||
                </van-button>
 | 
					                </van-button>
 | 
				
			||||||
              </template>
 | 
					              </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -84,6 +86,19 @@
 | 
				
			|||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <button id="copy-link-btn" style="display: none;" :data-clipboard-text="url">复制链接地址</button>
 | 
					    <button id="copy-link-btn" style="display: none;" :data-clipboard-text="url">复制链接地址</button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <van-overlay :show="showMic" z-index="100">
 | 
				
			||||||
 | 
					      <div class="mic-wrapper">
 | 
				
			||||||
 | 
					        <div class="image">
 | 
				
			||||||
 | 
					          <van-image
 | 
				
			||||||
 | 
					              width="100"
 | 
				
			||||||
 | 
					              height="100"
 | 
				
			||||||
 | 
					              src="/images/mic.gif"
 | 
				
			||||||
 | 
					          />
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <van-button type="success" @click="stopVoice">说完了</van-button>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </van-overlay>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -101,6 +116,7 @@ import ChatReply from "@/components/mobile/ChatReply.vue";
 | 
				
			|||||||
import {getSessionId, getUserToken} from "@/store/session";
 | 
					import {getSessionId, getUserToken} from "@/store/session";
 | 
				
			||||||
import {checkSession} from "@/action/session";
 | 
					import {checkSession} from "@/action/session";
 | 
				
			||||||
import Clipboard from "clipboard";
 | 
					import Clipboard from "clipboard";
 | 
				
			||||||
 | 
					import {Microphone} from "@element-plus/icons-vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const winHeight = ref(0)
 | 
					const winHeight = ref(0)
 | 
				
			||||||
const navBarRef = ref(null)
 | 
					const navBarRef = ref(null)
 | 
				
			||||||
@@ -114,6 +130,7 @@ const modelValue = chatConfig.modelValue
 | 
				
			|||||||
const title = chatConfig.title
 | 
					const title = chatConfig.title
 | 
				
			||||||
const chatId = chatConfig.chatId
 | 
					const chatId = chatConfig.chatId
 | 
				
			||||||
const loginUser = ref(null)
 | 
					const loginUser = ref(null)
 | 
				
			||||||
 | 
					const showMic = ref(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const url = location.protocol + '//' + location.host + '/mobile/chat/export?chat_id=' + chatId
 | 
					const url = location.protocol + '//' + location.host + '/mobile/chat/export?chat_id=' + chatId
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -421,25 +438,29 @@ const shareChat = (option) => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eslint-disable-next-line no-undef
 | 
				
			||||||
 | 
					const recognition = new webkitSpeechRecognition() || SpeechRecognition();
 | 
				
			||||||
 | 
					//recognition.lang = 'zh-CN' // 设置语音识别语言
 | 
				
			||||||
 | 
					recognition.onresult = function (event) {
 | 
				
			||||||
 | 
					  prompt.value = event.results[0][0].transcript
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					recognition.onerror = function (event) {
 | 
				
			||||||
 | 
					  showNotify({type: 'danger', message: '语音识别错误:' + event.error})
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					recognition.onend = function () {
 | 
				
			||||||
 | 
					  console.log('语音识别结束');
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
const inputVoice = () => {
 | 
					const inputVoice = () => {
 | 
				
			||||||
  const recognition = new webkitSpeechRecognition() || SpeechRecognition();
 | 
					  showMic.value = true
 | 
				
			||||||
  // recognition.lang = 'zh-CN' // 设置语音识别语言
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  recognition.onresult = function (event) {
 | 
					 | 
				
			||||||
    const result = event.results[0][0].transcript;
 | 
					 | 
				
			||||||
    showToast('你说了: ' + result)
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  recognition.onerror = function (event) {
 | 
					 | 
				
			||||||
    showNotify({type: 'danger', message: '语音识别错误:' + event.error})
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  recognition.onend = function () {
 | 
					 | 
				
			||||||
    console.log('语音识别结束');
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  recognition.start();
 | 
					  recognition.start();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const stopVoice = () => {
 | 
				
			||||||
 | 
					  showMic.value = false
 | 
				
			||||||
 | 
					  recognition.stop()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<style lang="stylus">
 | 
					<style lang="stylus">
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user