2 Star 0 Fork 0

huangjsshinedone / midjourney-apiserve

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
upscale.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
huangjs 提交于 2024-01-06 09:43 . first
package midjourney
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
)
type UpscaleRequest struct {
Index int32 `json:"index"`
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
MessageHash string `json:"message_hash"`
}
func (c *Client) Upscale(ctx context.Context, upscaleReq *UpscaleRequest) error {
flags := 0
interactionsReq := &InteractionsRequest{
Type: 3,
ApplicationID: ApplicationID,
GuildID: upscaleReq.GuildID,
ChannelID: upscaleReq.ChannelID,
MessageFlags: &flags,
MessageID: &upscaleReq.MessageID,
SessionID: SessionID,
Data: map[string]any{
"component_type": 2,
"custom_id": fmt.Sprintf("MJ::JOB::upsample::%d::%s", upscaleReq.Index, upscaleReq.MessageHash),
},
}
b, _ := json.Marshal(interactionsReq)
url := "https://discord.com/api/v9/interactions"
req, err := http.NewRequest("POST", url, bytes.NewReader(b))
if err != nil {
return fmt.Errorf("Call http.NewRequest failed, err: %w", err)
}
req.Header.Set("Authorization", c.Config.UserToken)
req.Header.Set("Content-Type", "application/json")
resp, err := c.Do(req)
if err != nil {
return fmt.Errorf("Call c.Do failed, err: %w", err)
}
defer resp.Body.Close()
if err := checkResponse(resp); err != nil {
return fmt.Errorf("Call checkResponse failed, err: %w", err)
}
return nil
}
func GetMessageHash(url string) string {
t := strings.Split(url, "_")
t = strings.Split(t[len(t)-1], ".")
return t[0]
}
1
https://gitee.com/huangjsshinedone/midjourney-apiserve.git
git@gitee.com:huangjsshinedone/midjourney-apiserve.git
huangjsshinedone
midjourney-apiserve
midjourney-apiserve
v0.0.8

搜索帮助