Skip to content

Commit

Permalink
[support] Support #178.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Apr 22, 2023
1 parent 50b9220 commit cdbe362
Show file tree
Hide file tree
Showing 12 changed files with 633 additions and 19 deletions.
8 changes: 4 additions & 4 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func AdminRestAPI() {
v1.POST("/logout", token.DeleteAdminUser)

//
// Token
// BotToken
//
v1.POST("/token/generate", token.GenerateByAdmin)

v1.POST("/token", token.AddByAdmin)
// Token Delete
// BotToken Delete
v1.DELETE("/token", token.DeleteAllByAdmin)
v1.DELETE("/token/:id", token.DeleteByAdmin)
// Token Update
// BotToken Update
v1.PUT("/token/:id", token.UpdateByAdmin)
v1.GET("/token", token.GetAllByAdmin)
v1.GET("/token/:id", token.GetByAdmin)
Expand Down Expand Up @@ -323,7 +323,7 @@ func UserRestAPI() {

func cors(c *gin.Context) {

//c.Header("Access-Control-Allow-Headers", "Accept, Content-ID, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Access-Control-Request-Headers, Access-Control-Request-Method, Connection, Host, Origin, User-Agent, Referer, Cache-Control, X-header")
//c.Header("Access-Control-Allow-Headers", "Accept, Content-ID, Content-Length, Accept-Encoding, X-CSRF-BotToken, Authorization, Access-Control-Request-Headers, Access-Control-Request-Method, Connection, Host, Origin, User-Agent, Referer, Cache-Control, X-header")
c.Header("Access-Control-Allow-Origin", "*")
c.Header("Access-Control-Allow-Methods", "*")
c.Header("Access-Control-Allow-Headers", "*")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/core/group/service/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
Open = 3
SearchNewNumber = 4
GIDAndAddAllow = 5
ASN = 6
UpdateName = 100
UpdateDate = 102
UpdateRoute = 103
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/core/tool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ type Radius struct {
}

type Slack struct {
Token string `json:"token"`
AppToken string `json:"app_token"`
BotToken string `json:"bot_token"`
Channels SlackChannels `json:"channels"`
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/api/core/tool/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Notification NotifyStruct

func NewNotification() {
// slack
slackToken := config.Conf.Slack.Token
Notification.Slack = slack.New(slackToken)
slackToken := config.Conf.Slack.BotToken
appToken := slack.OptionAppLevelToken(config.Conf.Slack.AppToken)
Notification.Slack = slack.New(slackToken, appToken, slack.OptionDebug(config.IsDebug))
}
4 changes: 3 additions & 1 deletion pkg/api/core/tool/notification/slack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package notification

import (
"fmt"
"github.com/homenoc/dsbd-backend/pkg/api/core/tool/config"
"github.com/slack-go/slack"
"strings"
Expand Down Expand Up @@ -45,11 +46,12 @@ func NoticeLog(color string, baseKeyValue []string) {
slackAttachField = append(slackAttachField, slack.AttachmentField{Title: splitKeyValue[0], Value: keyValue[len(splitKeyValue[0])+1:]})
}

Notification.Slack.PostMessage(config.Conf.Slack.Channels.Log, slack.MsgOptionAttachments(
_, _, err := Notification.Slack.PostMessage(config.Conf.Slack.Channels.Log, slack.MsgOptionAttachments(
slack.Attachment{
Color: color,
Title: "System",
Fields: slackAttachField,
},
))
fmt.Println(err)
}
Loading

0 comments on commit cdbe362

Please sign in to comment.