add instagram api and schema

This commit is contained in:
Jay
2019-05-22 22:25:09 +08:00
parent d7d5ace2c0
commit 426bb0fea8
5 changed files with 173 additions and 0 deletions
+78
View File
@@ -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)
}