Browse Source

get tokens for update and delete

this changes DoUpdate and DoDelete to load the user and set the access
token in the client when no edit token is provided.
pull/36/head
Rob Loranger 4 years ago
parent
commit
b60ae1edc0
No known key found for this signature in database GPG Key ID: D6F1633A4F0903B8
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      api/api.go

+ 18
- 0
api/api.go View File

@@ -225,6 +225,15 @@ func DoUpdate(c *cli.Context, post []byte, friendlyID, token, font string, code
return fmt.Errorf("%v", err)
}

if token == "" {
u, _ := config.LoadUser(c)
if u != nil {
cl.SetToken(u.AccessToken)
} else {
return fmt.Errorf("You must either provide and edit token or log in to delete a post.")
}
}

params := writeas.PostParams{}
params.Title, params.Content = posts.ExtractTitle(string(post))
if lang := config.Language(c, false); lang != "" {
@@ -251,6 +260,15 @@ func DoDelete(c *cli.Context, friendlyID, token string) error {
return fmt.Errorf("%v", err)
}

if token == "" {
u, _ := config.LoadUser(c)
if u != nil {
cl.SetToken(u.AccessToken)
} else {
return fmt.Errorf("You must either provide and edit token or log in to delete a post.")
}
}

err = cl.DeletePost(friendlyID, token)
if err != nil {
if config.Debug() {


Loading…
Cancel
Save