add instagram api and schema
This commit is contained in:
@@ -46,6 +46,24 @@ func GetFacebookPageIDs(c *context.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
//GetInstagramIDs -
|
||||
func GetInstagramIDs(c *context.Context) {
|
||||
igs, err := model.GetAllInstagram()
|
||||
if err != nil {
|
||||
c.ServerError(nil)
|
||||
return
|
||||
}
|
||||
|
||||
ids := make([]string, 0, len(igs))
|
||||
for _, v := range igs {
|
||||
ids = append(ids, v.ID)
|
||||
}
|
||||
|
||||
c.Success(map[string]interface{}{
|
||||
"list": ids,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateFacebookPagePost -
|
||||
func UpdateFacebookPagePost(c *context.Context) {
|
||||
var err error
|
||||
@@ -106,3 +124,63 @@ func UpdateFacebookPagePost(c *context.Context) {
|
||||
|
||||
c.Success(nil)
|
||||
}
|
||||
|
||||
// UpdateInstagramPost -
|
||||
func UpdateInstagramPost(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 {
|
||||
IGs []pageStruct `json:"igs"`
|
||||
}{}
|
||||
|
||||
err = c.BindData(&bodyArg)
|
||||
if err != nil {
|
||||
c.DataFormat(nil)
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range bodyArg.IGs {
|
||||
if len(v.ID) == 0 || len(v.PostID) == 0 || len(v.Link) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
ig, err := model.GetInstagram(v.ID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if ig.LastPost == v.PostID {
|
||||
continue
|
||||
}
|
||||
err = ig.UpdatePost(v.PostID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
err = ig.GetGroups()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, g := range ig.Groups {
|
||||
if g.Notify {
|
||||
tmpl := g.Tmpl
|
||||
if len(tmpl) > 0 {
|
||||
tmpl = strings.Replace(tmpl, "{link}", v.Link, -1)
|
||||
tmpl = strings.Replace(tmpl, "{txt}", v.Text, -1)
|
||||
} else {
|
||||
tmpl = fmt.Sprintf("%s\n%s", v.Text, v.Link)
|
||||
}
|
||||
|
||||
msg := line.TextMessage{Text: tmpl}
|
||||
line.PushMessage(g.ID, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.Success(nil)
|
||||
}
|
||||
|
||||
@@ -91,6 +91,8 @@ func SetRoutes(r *gin.Engine) {
|
||||
{
|
||||
privateAPIGroup.GET("/pages", context.PatchCtx(private.GetFacebookPageIDs))
|
||||
privateAPIGroup.POST("/pageposts", context.PatchCtx(private.UpdateFacebookPagePost))
|
||||
privateAPIGroup.GET("/ig", context.PatchCtx(private.GetInstagramIDs))
|
||||
privateAPIGroup.POST("/igposts", context.PatchCtx(private.UpdateInstagramPost))
|
||||
}
|
||||
|
||||
apiTwitchGroup := apiGroup.Group("/twitch", context.PatchCtx(api.CheckSession))
|
||||
|
||||
Reference in New Issue
Block a user