dorisbot/route/private/private.go

67 lines
1.2 KiB
Go
Raw Normal View History

2019-09-16 09:16:58 +00:00
package private
import (
pubmodel "dorisbot/models/public"
"dorisbot/pkg/config"
"dorisbot/pkg/context"
"net/http"
"net/textproto"
)
// VerifyKey -
func VerifyKey(c *context.Context) {
conf := config.GetConfig()
key := c.GetHeader(textproto.CanonicalMIMEHeaderKey("x-mtfos-key"))
if len(key) == 0 || key != conf.SelfKey {
c.CustomRes(http.StatusForbidden, map[string]string{
"message": "key empty or not match",
})
return
}
c.Next()
}
// GetFacebookIDs -
func GetFacebookIDs(c *context.Context) {
pages, err := pubmodel.GetAllFacebookPage()
if err != nil {
c.ServerError()
return
}
ids := make([]string, 0, len(pages))
for _, v := range pages {
ids = append(ids, v.ID)
}
c.Success(map[string]interface{}{"list": ids})
}
2019-09-16 13:15:15 +00:00
// UpdateFacebookPost -
func UpdateFacebookPost(c *context.Context) {
var err error
type pageStruct struct {
ID string `json:"id"`
PostID string `json:"post_id"`
Link string `json:"link"`
Text string `json:"text"`
}
bodyArg := struct {
Pages []pageStruct `json:"pages"`
}{}
err = c.BindData(&bodyArg)
if err != nil {
c.DataFormat()
return
}
for _, v := range bodyArg.Pages {
if len(v.ID) == 0 || len(v.PostID) == 0 {
continue
}
}
}