mirror of
https://github.com/linux-do/new-api.git
synced 2025-11-11 00:23:42 +08:00
merge upstream
Signed-off-by: wozulong <>
This commit is contained in:
@@ -22,6 +22,7 @@ var StartTime = time.Now().Unix() // unit: second
|
|||||||
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
|
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
|
||||||
var SystemName = "New API"
|
var SystemName = "New API"
|
||||||
var ServerAddress = "http://localhost:3000"
|
var ServerAddress = "http://localhost:3000"
|
||||||
|
var OutProxyUrl = ""
|
||||||
var Footer = ""
|
var Footer = ""
|
||||||
var Logo = ""
|
var Logo = ""
|
||||||
var TopUpLink = ""
|
var TopUpLink = ""
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"golang.org/x/image/webp"
|
"golang.org/x/image/webp"
|
||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ func DecodeBase64ImageData(base64String string) (image.Config, string, string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsImageUrl(url string) (bool, error) {
|
func IsImageUrl(url string) (bool, error) {
|
||||||
resp, err := http.Head(url)
|
resp, err := ProxiedHttpHead(url, OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -48,7 +47,7 @@ func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
|||||||
if !isImage {
|
if !isImage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := http.Get(url)
|
resp, err := ProxiedHttpGet(url, OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,7 @@ func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DecodeUrlImageData(imageUrl string) (image.Config, string, error) {
|
func DecodeUrlImageData(imageUrl string) (image.Config, string, error) {
|
||||||
response, err := http.Get(imageUrl)
|
response, err := ProxiedHttpGet(imageUrl, OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SysLog(fmt.Sprintf("fail to get image from url: %s", err.Error()))
|
SysLog(fmt.Sprintf("fail to get image from url: %s", err.Error()))
|
||||||
return image.Config{}, "", err
|
return image.Config{}, "", err
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -267,3 +272,56 @@ func StrToMap(str string) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetProxiedHttpClient(proxyUrl string) (*http.Client, error) {
|
||||||
|
if "" == proxyUrl {
|
||||||
|
return &http.Client{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(proxyUrl, "http") {
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(u),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
} else if strings.HasPrefix(proxyUrl, "socks") {
|
||||||
|
dialer, err := proxy.FromURL(u, proxy.Direct)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
|
return dialer.(proxy.ContextDialer).DialContext(ctx, network, addr)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("unsupported proxy type")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProxiedHttpGet(url, proxyUrl string) (*http.Response, error) {
|
||||||
|
client, err := GetProxiedHttpClient(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Get(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProxiedHttpHead(url, proxyUrl string) (*http.Response, error) {
|
||||||
|
client, err := GetProxiedHttpClient(proxyUrl)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Head(url)
|
||||||
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ func InitOptionMap() {
|
|||||||
common.OptionMap["SystemName"] = common.SystemName
|
common.OptionMap["SystemName"] = common.SystemName
|
||||||
common.OptionMap["Logo"] = common.Logo
|
common.OptionMap["Logo"] = common.Logo
|
||||||
common.OptionMap["ServerAddress"] = ""
|
common.OptionMap["ServerAddress"] = ""
|
||||||
|
common.OptionMap["OutProxyUrl"] = ""
|
||||||
common.OptionMap["StripeApiSecret"] = common.StripeApiSecret
|
common.OptionMap["StripeApiSecret"] = common.StripeApiSecret
|
||||||
common.OptionMap["StripeWebhookSecret"] = common.StripeWebhookSecret
|
common.OptionMap["StripeWebhookSecret"] = common.StripeWebhookSecret
|
||||||
common.OptionMap["StripePriceId"] = common.StripePriceId
|
common.OptionMap["StripePriceId"] = common.StripePriceId
|
||||||
@@ -242,6 +243,8 @@ func updateOptionMap(key string, value string) (err error) {
|
|||||||
common.SMTPToken = value
|
common.SMTPToken = value
|
||||||
case "ServerAddress":
|
case "ServerAddress":
|
||||||
common.ServerAddress = value
|
common.ServerAddress = value
|
||||||
|
case "OutProxyUrl":
|
||||||
|
common.OutProxyUrl = value
|
||||||
case "StripeApiSecret":
|
case "StripeApiSecret":
|
||||||
common.StripeApiSecret = value
|
common.StripeApiSecret = value
|
||||||
case "StripeWebhookSecret":
|
case "StripeWebhookSecret":
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func RelayMidjourneyImage(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := http.Get(midjourneyTask.ImageUrl)
|
resp, err := common.ProxiedHttpGet(midjourneyTask.ImageUrl, common.OutProxyUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "http_get_image_failed",
|
"error": "http_get_image_failed",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const SystemSetting = () => {
|
|||||||
SMTPFrom: '',
|
SMTPFrom: '',
|
||||||
SMTPToken: '',
|
SMTPToken: '',
|
||||||
ServerAddress: '',
|
ServerAddress: '',
|
||||||
|
OutProxyUrl: '',
|
||||||
StripeApiSecret: '',
|
StripeApiSecret: '',
|
||||||
StripeWebhookSecret: '',
|
StripeWebhookSecret: '',
|
||||||
StripePriceId: '',
|
StripePriceId: '',
|
||||||
@@ -150,6 +151,7 @@ const SystemSetting = () => {
|
|||||||
name === 'Notice' ||
|
name === 'Notice' ||
|
||||||
(name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
|
(name.startsWith('SMTP') && name !== 'SMTPSSLEnabled') ||
|
||||||
name === 'ServerAddress' ||
|
name === 'ServerAddress' ||
|
||||||
|
name === 'OutProxyUrl' ||
|
||||||
name === 'StripeApiSecret' ||
|
name === 'StripeApiSecret' ||
|
||||||
name === 'StripeWebhookSecret' ||
|
name === 'StripeWebhookSecret' ||
|
||||||
name === 'StripePriceId' ||
|
name === 'StripePriceId' ||
|
||||||
@@ -181,6 +183,11 @@ const SystemSetting = () => {
|
|||||||
await updateOption('ServerAddress', ServerAddress);
|
await updateOption('ServerAddress', ServerAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitOutProxyUrl = async () => {
|
||||||
|
let OutProxyUrl = removeTrailingSlash(inputs.OutProxyUrl);
|
||||||
|
await updateOption('OutProxyUrl', OutProxyUrl);
|
||||||
|
};
|
||||||
|
|
||||||
const submitPaymentConfig = async () => {
|
const submitPaymentConfig = async () => {
|
||||||
if (inputs.ServerAddress === '') {
|
if (inputs.ServerAddress === '') {
|
||||||
showError('请先填写服务器地址');
|
showError('请先填写服务器地址');
|
||||||
@@ -368,6 +375,20 @@ const SystemSetting = () => {
|
|||||||
更新服务器地址
|
更新服务器地址
|
||||||
</Form.Button>
|
</Form.Button>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<Header as='h3' inverted={isDark}>
|
||||||
|
代理设置
|
||||||
|
</Header>
|
||||||
|
<Form.Group widths='equal'>
|
||||||
|
<Form.Input
|
||||||
|
label='出口代理地址'
|
||||||
|
placeholder='例如:http://1.2.3.4:8888'
|
||||||
|
value={inputs.OutProxyUrl}
|
||||||
|
name='OutProxyUrl'
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</Form.Group>
|
||||||
|
<Form.Button onClick={submitOutProxyUrl}>更新代理设置</Form.Button>
|
||||||
|
<Divider />
|
||||||
<Header as='h3' inverted={isDark}>
|
<Header as='h3' inverted={isDark}>
|
||||||
支付设置(当前仅支持Stripe Checkout)
|
支付设置(当前仅支持Stripe Checkout)
|
||||||
<Header.Subheader>
|
<Header.Subheader>
|
||||||
|
|||||||
Reference in New Issue
Block a user