chore: add bark custom server #83
This commit is contained in:
@@ -27,6 +27,7 @@ type Bark struct {
|
|||||||
URL string
|
URL string
|
||||||
Key string
|
Key string
|
||||||
IV string
|
IV string
|
||||||
|
Server string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bark) Request(title, content string) ([]byte, error) {
|
func (b *Bark) Request(title, content string) ([]byte, error) {
|
||||||
@@ -73,7 +74,11 @@ func (b *Bark) Request(title, content string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
// When using encryption, use the push endpoint if PushKey is just a key
|
// When using encryption, use the push endpoint if PushKey is just a key
|
||||||
if !strings.HasPrefix(b.PushKey, "http") {
|
if !strings.HasPrefix(b.PushKey, "http") {
|
||||||
url = "https://api.day.app/push"
|
server := b.Server
|
||||||
|
if server == "" {
|
||||||
|
server = "https://api.day.app"
|
||||||
|
}
|
||||||
|
url = strings.TrimSuffix(server, "/") + "/push"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Normal request
|
// Normal request
|
||||||
@@ -113,7 +118,12 @@ func (b *Bark) getURL() string {
|
|||||||
if strings.HasPrefix(pushKey, "http") {
|
if strings.HasPrefix(pushKey, "http") {
|
||||||
return pushKey
|
return pushKey
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("https://api.day.app/%s", pushKey)
|
server := b.Server
|
||||||
|
if server == "" {
|
||||||
|
server = "https://api.day.app"
|
||||||
|
}
|
||||||
|
server = strings.TrimSuffix(server, "/")
|
||||||
|
return fmt.Sprintf("%s/%s", server, pushKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bark) encryptPayload(payload string) (string, error) {
|
func (b *Bark) encryptPayload(payload string) (string, error) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func (c *BarkChannel) Send(config ChannelConfig, msg *Message) (*Result, error)
|
|||||||
URL: config.GetString("url"),
|
URL: config.GetString("url"),
|
||||||
Key: config.GetString("key"),
|
Key: config.GetString("key"),
|
||||||
IV: config.GetString("iv"),
|
IV: config.GetString("iv"),
|
||||||
|
Server: config.GetString("server"),
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := cli.Request(msg.Title, msg.Text)
|
res, err := cli.Request(msg.Title, msg.Text)
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ const channelConfigFields: Record<string, { key: string; label: string; required
|
|||||||
{ key: 'proxy_url', label: '代理地址', required: false, placeholder: 'http/https/socks5 代理' },
|
{ key: 'proxy_url', label: '代理地址', required: false, placeholder: 'http/https/socks5 代理' },
|
||||||
],
|
],
|
||||||
Bark: [
|
Bark: [
|
||||||
|
{ key: 'server', label: '服务地址', required: false, placeholder: '默认 https://api.day.app' },
|
||||||
{ key: 'push_key', label: 'Push Key', required: true, placeholder: 'Bark Push Key' },
|
{ key: 'push_key', label: 'Push Key', required: true, placeholder: 'Bark Push Key' },
|
||||||
{ key: 'sound', label: '推送声音', required: false, placeholder: '留空使用默认' },
|
{ key: 'sound', label: '推送声音', required: false, placeholder: '留空使用默认' },
|
||||||
{ key: 'group', label: '推送分组', required: false },
|
{ key: 'group', label: '推送分组', required: false },
|
||||||
|
|||||||
Reference in New Issue
Block a user